From 74cde415cfa48d318105b301df9c516da0857e9e Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 17 Jul 2020 15:54:59 +0400 Subject: Added program entity Signed-off-by: Valentin Popov --- src/Entities/ProgramEntity.php | 223 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 src/Entities/ProgramEntity.php (limited to 'src/Entities/ProgramEntity.php') diff --git a/src/Entities/ProgramEntity.php b/src/Entities/ProgramEntity.php new file mode 100644 index 0000000..a789de9 --- /dev/null +++ b/src/Entities/ProgramEntity.php @@ -0,0 +1,223 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities + */ +final class ProgramEntity { + /** + * @var string[] + */ + private array $categories; + + /** + * @var string + */ + private string $channel_id; + + /** + * @var string[] + */ + private array $countries; + + /** + * @var \EPGService\Entities\Program\CreditEntity[] + */ + private array $credits; + + /** + * @var \DateTime + */ + private DateTime $date; + + /** + * @var string + */ + private string $description; + + /** + * @var string[] + */ + private array $icons; + + /** + * @var string + */ + private string $parents_guide; + + /** + * @var string[] + */ + private array $productions; + + /** + * @var \DateTime + */ + private DateTime $start; + + /** + * @var \DateTime + */ + private DateTime $stop; + + /** + * @var string + */ + private string $sub_title; + + /** + * @var string + */ + private string $title; + + /** + * @var string + */ + private string $year; + + /** + * @param array $payload + */ + private function __construct(array $payload) { + $this->categories = $payload['categories']; + $this->channel_id = $payload['channel_id']; + $this->countries = $payload['countries']; + $this->credits = $payload['credits']; + $this->date = $payload['date']; + $this->description = $payload['description']; + $this->icons = $payload['icons']; + $this->parents_guide = $payload['parents_guide']; + $this->productions = $payload['productions']; + $this->start = $payload['start']; + $this->stop = $payload['stop']; + $this->sub_title = $payload['sub_title']; + $this->title = $payload['title']; + $this->year = $payload['year']; + } + + /** + * @param array $payload + * + * @return \EPGService\Entities\ProgramEntity + * + * @throws \RuntimeException + */ + public static function create(array $payload): ProgramEntity { + if (!is_array($payload['categories'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['channel_id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_array($payload['countries'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_array($payload['credits'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!$payload['date'] instanceof DateTime) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['description'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_array($payload['icons'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['parents_guide'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_array($payload['productions'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!$payload['start'] instanceof DateTime) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!$payload['stop'] instanceof DateTime) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['sub_title'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['title'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['year'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new ProgramEntity($payload); + } + + /** + * @param string $name + * + * @return mixed + */ + public function __get(string $name) { + return $this->$name; + } + + /** + * @param string $name + * @param mixed $value + * + * @throws \RuntimeException + */ + public function __set(string $name, $value) { + throw new RuntimeException('blah-blah-blah'); + } +} -- cgit v1.2.3 From 9d6e3525afeb1a396f78e05c8c8957860a9c4a41 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 18 Jul 2020 15:42:37 +0400 Subject: Updated program entity Signed-off-by: Valentin Popov --- src/Entities/ProgramEntity.php | 100 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) (limited to 'src/Entities/ProgramEntity.php') diff --git a/src/Entities/ProgramEntity.php b/src/Entities/ProgramEntity.php index a789de9..04017c6 100644 --- a/src/Entities/ProgramEntity.php +++ b/src/Entities/ProgramEntity.php @@ -25,20 +25,20 @@ use function is_array; use function is_string; /** - * @property-read \EPGService\Entities\Program\CreditEntity[] $credits - * @property-read \DateTime $date - * @property-read \DateTime $start - * @property-read \DateTime $stop - * @property-read string $channel_id - * @property-read string $description - * @property-read string $parents_guide - * @property-read string $sub_title - * @property-read string $title - * @property-read string $year - * @property-read string[] $categories - * @property-read string[] $countries - * @property-read string[] $icons - * @property-read string[] $productions + * @property-read \EPGService\Entities\Program\CreditEntity[]|null $credits + * @property-read \DateTime $date + * @property-read \DateTime $start + * @property-read \DateTime $stop + * @property-read string $channel_id + * @property-read string|null $description + * @property-read string|null $parents_guide + * @property-read string|null $sub_title + * @property-read string $title + * @property-read string|null $year + * @property-read string[]|null $categories + * @property-read string[]|null $countries + * @property-read string[]|null $icons + * @property-read string[]|null $productions * * @copyright Copyright © 2020 “Valentin Popov” * @license http://www.apache.org/licenses/LICENSE-2.0 @@ -46,9 +46,9 @@ use function is_string; */ final class ProgramEntity { /** - * @var string[] + * @var string[]|null */ - private array $categories; + private ?array $categories; /** * @var string @@ -56,14 +56,14 @@ final class ProgramEntity { private string $channel_id; /** - * @var string[] + * @var string[]|null */ - private array $countries; + private ?array $countries; /** - * @var \EPGService\Entities\Program\CreditEntity[] + * @var \EPGService\Entities\Program\CreditEntity[]|null */ - private array $credits; + private ?array $credits; /** * @var \DateTime @@ -71,24 +71,24 @@ final class ProgramEntity { private DateTime $date; /** - * @var string + * @var string|null */ - private string $description; + private ?string $description; /** - * @var string[] + * @var string[]|null */ - private array $icons; + private ?array $icons; /** - * @var string + * @var string|null */ - private string $parents_guide; + private ?string $parents_guide; /** - * @var string[] + * @var string[]|null */ - private array $productions; + private ?array $productions; /** * @var \DateTime @@ -101,9 +101,9 @@ final class ProgramEntity { private DateTime $stop; /** - * @var string + * @var string|null */ - private string $sub_title; + private ?string $sub_title; /** * @var string @@ -111,28 +111,28 @@ final class ProgramEntity { private string $title; /** - * @var string + * @var string|null */ - private string $year; + private ?string $year; /** * @param array $payload */ private function __construct(array $payload) { - $this->categories = $payload['categories']; + $this->categories = $payload['categories'] ?? null; $this->channel_id = $payload['channel_id']; - $this->countries = $payload['countries']; - $this->credits = $payload['credits']; + $this->countries = $payload['countries'] ?? null; + $this->credits = $payload['credits'] ?? null; $this->date = $payload['date']; - $this->description = $payload['description']; - $this->icons = $payload['icons']; - $this->parents_guide = $payload['parents_guide']; - $this->productions = $payload['productions']; + $this->description = $payload['description'] ?? null; + $this->icons = $payload['icons'] ?? null; + $this->parents_guide = $payload['parents_guide'] ?? null; + $this->productions = $payload['productions'] ?? null; $this->start = $payload['start']; $this->stop = $payload['stop']; - $this->sub_title = $payload['sub_title']; + $this->sub_title = $payload['sub_title'] ?? null; $this->title = $payload['title']; - $this->year = $payload['year']; + $this->year = $payload['year'] ?? null; } /** @@ -143,7 +143,7 @@ final class ProgramEntity { * @throws \RuntimeException */ public static function create(array $payload): ProgramEntity { - if (!is_array($payload['categories'])) { + if (isset($payload['categories']) && !is_array($payload['categories'])) { throw new RuntimeException('blah-blah-blah'); } @@ -151,11 +151,11 @@ final class ProgramEntity { throw new RuntimeException('blah-blah-blah'); } - if (!is_array($payload['countries'])) { + if (isset($payload['countries']) && !is_array($payload['countries'])) { throw new RuntimeException('blah-blah-blah'); } - if (!is_array($payload['credits'])) { + if (isset($payload['credits']) && !is_array($payload['credits'])) { throw new RuntimeException('blah-blah-blah'); } @@ -163,19 +163,19 @@ final class ProgramEntity { throw new RuntimeException('blah-blah-blah'); } - if (!is_string($payload['description'])) { + if (isset($payload['description']) && !is_string($payload['description'])) { throw new RuntimeException('blah-blah-blah'); } - if (!is_array($payload['icons'])) { + if (isset($payload['icons']) && !is_array($payload['icons'])) { throw new RuntimeException('blah-blah-blah'); } - if (!is_string($payload['parents_guide'])) { + if (isset($payload['parents_guide']) && !is_string($payload['parents_guide'])) { throw new RuntimeException('blah-blah-blah'); } - if (!is_array($payload['productions'])) { + if (isset($payload['productions']) && !is_array($payload['productions'])) { throw new RuntimeException('blah-blah-blah'); } @@ -187,7 +187,7 @@ final class ProgramEntity { throw new RuntimeException('blah-blah-blah'); } - if (!is_string($payload['sub_title'])) { + if (isset($payload['sub_title']) && !is_string($payload['sub_title'])) { throw new RuntimeException('blah-blah-blah'); } @@ -195,7 +195,7 @@ final class ProgramEntity { throw new RuntimeException('blah-blah-blah'); } - if (!is_string($payload['year'])) { + if (isset($payload['year']) && !is_string($payload['year'])) { throw new RuntimeException('blah-blah-blah'); } -- cgit v1.2.3