From 76e8ed954e2a1c70437fb34a927d1bb1d921d3ce Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 15 Jul 2020 13:54:01 +0400 Subject: Added category entity Signed-off-by: Valentin Popov --- src/Entities/CategoryEntity.php | 114 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/Entities/CategoryEntity.php (limited to 'src/Entities') diff --git a/src/Entities/CategoryEntity.php b/src/Entities/CategoryEntity.php new file mode 100644 index 0000000..ab1f431 --- /dev/null +++ b/src/Entities/CategoryEntity.php @@ -0,0 +1,114 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities + */ +class CategoryEntity { + /** + * @var int + */ + protected int $id; + + /** + * @var string + */ + protected string $lang; + + /** + * @var string + */ + protected string $name; + + /** + * @var string + */ + protected string $version; + + /** + * @param int $id + * @param string $lang + * @param string $name + * @param string $version + */ + protected function __construct(int $id, string $lang, string $name, string $version) { + $this->id = $id; + $this->lang = $lang; + $this->name = $name; + $this->version = $version; + } + + /** + * @param array $payload + * + * @return \EPGService\Entities\CategoryEntity + * @throws \RuntimeException + */ + public static function create(array $payload): CategoryEntity { + if (!is_int($payload['id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['lang'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['name'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['version'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new CategoryEntity($payload['id'], $payload['lang'], $payload['name'], $payload['version']); + } + + /** + * @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 6c52322a3cc5fe4036cc7689d60bd47eca402452 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 15 Jul 2020 19:20:43 +0400 Subject: Added genre entity Signed-off-by: Valentin Popov --- src/Entities/GenreEntity.php | 108 +++++++++++++++++++++++++++++++++++++ tests/Entities/GenreEntityTest.php | 47 ++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 src/Entities/GenreEntity.php create mode 100644 tests/Entities/GenreEntityTest.php (limited to 'src/Entities') diff --git a/src/Entities/GenreEntity.php b/src/Entities/GenreEntity.php new file mode 100644 index 0000000..78a9ac0 --- /dev/null +++ b/src/Entities/GenreEntity.php @@ -0,0 +1,108 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities + */ +class GenreEntity { + /** + * @var int + */ + protected int $id; + + /** + * @var string + */ + protected string $lang; + + /** + * @var string + */ + protected string $name; + + /** + * @var string + */ + protected string $version; + + /** + * @param int $id + * @param string $lang + * @param string $name + * @param string $version + */ + protected function __construct(int $id, string $lang, string $name, string $version) { + $this->id = $id; + $this->lang = $lang; + $this->name = $name; + $this->version = $version; + } + + public static function create(array $payload): GenreEntity { + if (!is_int($payload['id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['lang'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['name'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['version'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new GenreEntity($payload['id'], $payload['lang'], $payload['name'], $payload['version']); + } + + /** + * @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'); + } +} diff --git a/tests/Entities/GenreEntityTest.php b/tests/Entities/GenreEntityTest.php new file mode 100644 index 0000000..0b1b12c --- /dev/null +++ b/tests/Entities/GenreEntityTest.php @@ -0,0 +1,47 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities + */ +final class GenreEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Faker::create(); + + $id = $faker->numberBetween(1, 999); + $lang = $faker->languageCode; + $name = $faker->word; + $version = $faker->sha256; + + $entity = GenreEntity::create(compact('id', 'lang', 'name', 'version')); + + self::assertEquals($id, $entity->id); + self::assertEquals($lang, $entity->lang); + self::assertEquals($name, $entity->name); + self::assertEquals($version, $entity->version); + } +} -- cgit v1.2.3 From 42008dbe1bb64e901156560d066f47c2208d9d84 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 15 Jul 2020 22:06:33 +0400 Subject: Marked “final” entities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Popov --- src/Entities/CategoryEntity.php | 12 ++++++------ src/Entities/GenreEntity.php | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/CategoryEntity.php b/src/Entities/CategoryEntity.php index ab1f431..af44434 100644 --- a/src/Entities/CategoryEntity.php +++ b/src/Entities/CategoryEntity.php @@ -33,26 +33,26 @@ use function is_string; * @license http://www.apache.org/licenses/LICENSE-2.0 * @package EPGService\Entities */ -class CategoryEntity { +final class CategoryEntity { /** * @var int */ - protected int $id; + private int $id; /** * @var string */ - protected string $lang; + private string $lang; /** * @var string */ - protected string $name; + private string $name; /** * @var string */ - protected string $version; + private string $version; /** * @param int $id @@ -60,7 +60,7 @@ class CategoryEntity { * @param string $name * @param string $version */ - protected function __construct(int $id, string $lang, string $name, string $version) { + private function __construct(int $id, string $lang, string $name, string $version) { $this->id = $id; $this->lang = $lang; $this->name = $name; diff --git a/src/Entities/GenreEntity.php b/src/Entities/GenreEntity.php index 78a9ac0..61e11ba 100644 --- a/src/Entities/GenreEntity.php +++ b/src/Entities/GenreEntity.php @@ -33,26 +33,26 @@ use function is_string; * @license http://www.apache.org/licenses/LICENSE-2.0 * @package EPGService\Entities */ -class GenreEntity { +final class GenreEntity { /** * @var int */ - protected int $id; + private int $id; /** * @var string */ - protected string $lang; + private string $lang; /** * @var string */ - protected string $name; + private string $name; /** * @var string */ - protected string $version; + private string $version; /** * @param int $id @@ -60,7 +60,7 @@ class GenreEntity { * @param string $name * @param string $version */ - protected function __construct(int $id, string $lang, string $name, string $version) { + private function __construct(int $id, string $lang, string $name, string $version) { $this->id = $id; $this->lang = $lang; $this->name = $name; -- cgit v1.2.3 From 964ba206127de4eb904f271fd80db7941653adaa Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 17 Jul 2020 12:14:42 +0400 Subject: Added channel entity Signed-off-by: Valentin Popov --- src/Entities/ChannelEntity.php | 177 +++++++++++++++++++++++++++++++++++ tests/Entities/ChannelEntityTest.php | 70 ++++++++++++++ 2 files changed, 247 insertions(+) create mode 100644 src/Entities/ChannelEntity.php create mode 100644 tests/Entities/ChannelEntityTest.php (limited to 'src/Entities') diff --git a/src/Entities/ChannelEntity.php b/src/Entities/ChannelEntity.php new file mode 100644 index 0000000..59fc8ce --- /dev/null +++ b/src/Entities/ChannelEntity.php @@ -0,0 +1,177 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities + */ +final class ChannelEntity { + /** + * @var string + */ + private string $base_id; + + /** + * @var string + */ + private string $epg_id; + + /** + * @var string + */ + private string $geo_data; + + /** + * @var string + */ + private string $href; + + /** + * @var string + */ + private string $icon; + + /** + * @var string + */ + private string $id; + + /** + * @var string + */ + private string $lang; + + /** + * @var string + */ + private string $name; + + /** + * @var string + */ + private string $update_at; + + /** + * @var string + */ + private string $week; + + /** + * @param array $payload + */ + private function __construct(array $payload) { + $this->base_id = $payload['base_id']; + $this->epg_id = $payload['epg_id']; + $this->geo_data = $payload['geo_data']; + $this->href = $payload['href']; + $this->icon = $payload['icon']; + $this->id = $payload['id']; + $this->lang = $payload['lang']; + $this->name = $payload['name']; + $this->update_at = $payload['update_at']; + $this->week = $payload['week']; + } + + /** + * @param array $payload + * + * @return \EPGService\Entities\ChannelEntity + * + * @throws \RuntimeException + */ + public static function create(array $payload): ChannelEntity { + if (!is_string($payload['base_id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['epg_id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['geo_data'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['href'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['icon'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['lang'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['name'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['update_at'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['week'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new ChannelEntity($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'); + } +} diff --git a/tests/Entities/ChannelEntityTest.php b/tests/Entities/ChannelEntityTest.php new file mode 100644 index 0000000..e4f2456 --- /dev/null +++ b/tests/Entities/ChannelEntityTest.php @@ -0,0 +1,70 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities + */ +final class ChannelEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Factory::create(); + + $base_id = $faker->unique()->sha256; + $epg_id = $faker->unique()->sha256; + $geo_data = $faker->unique()->sha256; + $href = $faker->unique()->sha256; + $icon = $faker->unique()->sha256; + $id = $faker->unique()->sha256; + $lang = $faker->unique()->sha256; + $name = $faker->unique()->sha256; + $update_at = $faker->unique()->sha256; + $week = $faker->unique()->sha256; + + $entity = ChannelEntity::create(compact( + 'base_id', + 'epg_id', + 'geo_data', + 'href', + 'icon', + 'id', + 'lang', + 'name', + 'update_at', + 'week', + )); + + self::assertEquals($base_id, $entity->base_id); + self::assertEquals($epg_id, $entity->epg_id); + self::assertEquals($geo_data, $entity->geo_data); + self::assertEquals($href, $entity->href); + self::assertEquals($icon, $entity->icon); + self::assertEquals($id, $entity->id); + self::assertEquals($lang, $entity->lang); + self::assertEquals($name, $entity->name); + self::assertEquals($update_at, $entity->update_at); + self::assertEquals($week, $entity->week); + } +} -- cgit v1.2.3 From 46f834c9bf7ff890700cef3b05fd2d7ebefb21a0 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 17 Jul 2020 13:42:45 +0400 Subject: Updated channel entity Signed-off-by: Valentin Popov --- src/Entities/ChannelEntity.php | 11 +++++++++++ tests/Entities/ChannelEntityTest.php | 3 +++ 2 files changed, 14 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/ChannelEntity.php b/src/Entities/ChannelEntity.php index 59fc8ce..0d8d3fc 100644 --- a/src/Entities/ChannelEntity.php +++ b/src/Entities/ChannelEntity.php @@ -24,6 +24,7 @@ use function is_string; /** * @property-read string $base_id + * @property-read string $base_name * @property-read string $epg_id * @property-read string $geo_data * @property-read string $href @@ -44,6 +45,11 @@ final class ChannelEntity { */ private string $base_id; + /** + * @var string + */ + private string $base_name; + /** * @var string */ @@ -94,6 +100,7 @@ final class ChannelEntity { */ private function __construct(array $payload) { $this->base_id = $payload['base_id']; + $this->base_name = $payload['base_name']; $this->epg_id = $payload['epg_id']; $this->geo_data = $payload['geo_data']; $this->href = $payload['href']; @@ -117,6 +124,10 @@ final class ChannelEntity { throw new RuntimeException('blah-blah-blah'); } + if (!is_string($payload['base_name'])) { + throw new RuntimeException('blah-blah-blah'); + } + if (!is_string($payload['epg_id'])) { throw new RuntimeException('blah-blah-blah'); } diff --git a/tests/Entities/ChannelEntityTest.php b/tests/Entities/ChannelEntityTest.php index e4f2456..e3c2733 100644 --- a/tests/Entities/ChannelEntityTest.php +++ b/tests/Entities/ChannelEntityTest.php @@ -33,6 +33,7 @@ final class ChannelEntityTest extends TestCase { $faker = Factory::create(); $base_id = $faker->unique()->sha256; + $base_name = $faker->unique()->sha256; $epg_id = $faker->unique()->sha256; $geo_data = $faker->unique()->sha256; $href = $faker->unique()->sha256; @@ -45,6 +46,7 @@ final class ChannelEntityTest extends TestCase { $entity = ChannelEntity::create(compact( 'base_id', + 'base_name', 'epg_id', 'geo_data', 'href', @@ -57,6 +59,7 @@ final class ChannelEntityTest extends TestCase { )); self::assertEquals($base_id, $entity->base_id); + self::assertEquals($base_name, $entity->base_name); self::assertEquals($epg_id, $entity->epg_id); self::assertEquals($geo_data, $entity->geo_data); self::assertEquals($href, $entity->href); -- cgit v1.2.3 From 6d354e6a7791026b4a45e5e20963b10ed1a8bfbe Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 17 Jul 2020 15:32:14 +0400 Subject: Added credit entity Signed-off-by: Valentin Popov --- src/Entities/Program/CreditEntity.php | 89 +++++++++++++++++++++++++++++ tests/Entities/Program/CreditEntityTest.php | 43 ++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 src/Entities/Program/CreditEntity.php create mode 100644 tests/Entities/Program/CreditEntityTest.php (limited to 'src/Entities') diff --git a/src/Entities/Program/CreditEntity.php b/src/Entities/Program/CreditEntity.php new file mode 100644 index 0000000..f7088ea --- /dev/null +++ b/src/Entities/Program/CreditEntity.php @@ -0,0 +1,89 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities\Program + */ +final class CreditEntity { + /** + * @var string + */ + private string $name; + + /** + * @var string + */ + private string $type; + + /** + * @param array $payload + */ + private function __construct(array $payload) { + $this->name = $payload['name']; + $this->type = $payload['type']; + } + + /** + * @param array $payload + * + * @return \EPGService\Entities\Program\CreditEntity + * + * @throws \RuntimeException + */ + public static function create(array $payload): CreditEntity { + if (!is_string($payload['name'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['type'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new CreditEntity($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'); + } +} diff --git a/tests/Entities/Program/CreditEntityTest.php b/tests/Entities/Program/CreditEntityTest.php new file mode 100644 index 0000000..3c80300 --- /dev/null +++ b/tests/Entities/Program/CreditEntityTest.php @@ -0,0 +1,43 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities\Program + */ +final class CreditEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Faker::create(); + + $name = $faker->unique()->sha256; + $type = $faker->unique()->sha256; + + $entity = CreditEntity::create(compact('name', 'type')); + + self::assertEquals($name, $entity->name); + self::assertEquals($type, $entity->type); + } +} -- cgit v1.2.3 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 +++++++++++++++++++++++++++++++++++ tests/Entities/ProgramEntityTest.php | 83 +++++++++++++ 2 files changed, 306 insertions(+) create mode 100644 src/Entities/ProgramEntity.php create mode 100644 tests/Entities/ProgramEntityTest.php (limited to 'src/Entities') 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'); + } +} diff --git a/tests/Entities/ProgramEntityTest.php b/tests/Entities/ProgramEntityTest.php new file mode 100644 index 0000000..c36e283 --- /dev/null +++ b/tests/Entities/ProgramEntityTest.php @@ -0,0 +1,83 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities + */ +final class ProgramEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Faker::create(); + + $categories = [$faker->unique()->sha256]; + $channel_id = $faker->unique()->sha256; + $countries = [$faker->unique()->sha256]; + $credits = [GetCreditEntityUtility::get()]; + $date = $faker->unique()->dateTime; + $description = $faker->unique()->sha256; + $icons = [$faker->unique()->sha256]; + $parents_guide = $faker->unique()->sha256; + $productions = [$faker->unique()->sha256]; + $start = $faker->unique()->dateTime; + $stop = $faker->unique()->dateTime; + $sub_title = $faker->unique()->sha256; + $title = $faker->unique()->sha256; + $year = $faker->unique()->sha256; + + $entity = ProgramEntity::create(compact( + 'categories', + 'channel_id', + 'countries', + 'credits', + 'date', + 'description', + 'icons', + 'parents_guide', + 'productions', + 'start', + 'stop', + 'sub_title', + 'title', + 'year' + )); + + self::assertEquals($categories, $entity->categories); + self::assertEquals($channel_id, $entity->channel_id); + self::assertEquals($countries[0], $entity->countries[0]); + self::assertEquals($credits[0]->name, $entity->credits[0]->name); + self::assertEquals($date->getTimestamp(), $entity->date->getTimestamp()); + self::assertEquals($description, $entity->description); + self::assertEquals($icons[0], $entity->icons[0]); + self::assertEquals($parents_guide, $entity->parents_guide); + self::assertEquals($productions[0], $entity->productions[0]); + self::assertEquals($start->getTimestamp(), $entity->start->getTimestamp()); + self::assertEquals($stop->getTimestamp(), $entity->stop->getTimestamp()); + self::assertEquals($sub_title, $entity->sub_title); + self::assertEquals($title, $entity->title); + self::assertEquals($year, $entity->year); + } +} -- 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') 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 From a52e2e198708cf3e24eda73cbbc5906593cc730a Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 18 Jul 2020 15:49:06 +0400 Subject: Added DateTime of channel entity Signed-off-by: Valentin Popov --- src/Entities/ChannelEntity.php | 29 ++++++++++++++-------------- src/Repositories/ChannelRepository.php | 6 +++++- tests/Repositories/ChannelRepositoryTest.php | 3 ++- 3 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ChannelEntity.php b/src/Entities/ChannelEntity.php index 0d8d3fc..4881722 100644 --- a/src/Entities/ChannelEntity.php +++ b/src/Entities/ChannelEntity.php @@ -19,21 +19,22 @@ declare(strict_types = 1); namespace EPGService\Entities; +use DateTime; use RuntimeException; use function is_string; /** - * @property-read string $base_id - * @property-read string $base_name - * @property-read string $epg_id - * @property-read string $geo_data - * @property-read string $href - * @property-read string $icon - * @property-read string $id - * @property-read string $lang - * @property-read string $name - * @property-read string $update_at - * @property-read string $week + * @property-read string $base_id + * @property-read string $base_name + * @property-read string $epg_id + * @property-read string $geo_data + * @property-read string $href + * @property-read string $icon + * @property-read string $id + * @property-read string $lang + * @property-read string $name + * @property-read \DateTime $update_at + * @property-read string $week * * @copyright Copyright © 2020 “Valentin Popov” * @license http://www.apache.org/licenses/LICENSE-2.0 @@ -86,9 +87,9 @@ final class ChannelEntity { private string $name; /** - * @var string + * @var \DateTime */ - private string $update_at; + private DateTime $update_at; /** * @var string @@ -156,7 +157,7 @@ final class ChannelEntity { throw new RuntimeException('blah-blah-blah'); } - if (!is_string($payload['update_at'])) { + if (!$payload['update_at'] instanceof DateTime) { throw new RuntimeException('blah-blah-blah'); } diff --git a/src/Repositories/ChannelRepository.php b/src/Repositories/ChannelRepository.php index 44eac36..772e4f9 100644 --- a/src/Repositories/ChannelRepository.php +++ b/src/Repositories/ChannelRepository.php @@ -19,6 +19,7 @@ declare(strict_types = 1); namespace EPGService\Repositories; +use DateTime; use EPGService\Entities\ChannelEntity; use EPGService\Environments\ServiceEnvironment; use EPGService\Parsers\StringParser; @@ -66,6 +67,7 @@ final class ChannelRepository implements BaseRepository { * * @throws \GuzzleHttp\Exception\GuzzleException * @throws \RuntimeException + * @throws \Exception */ public function get(): array { $response = $this->client->get(self::METHOD); @@ -84,6 +86,8 @@ final class ChannelRepository implements BaseRepository { continue; } + $update = StringParser::get($element->update); + $result[] = ChannelEntity::create([ 'base_id' => StringParser::get($element->{'base-channel'}), 'base_name' => StringParser::get($element->{'base-channel'}['id']), @@ -94,7 +98,7 @@ final class ChannelRepository implements BaseRepository { 'id' => StringParser::get($element['id']), 'lang' => StringParser::get($element->{'display-name'}['lang']), 'name' => StringParser::get($element->{'base-channel'}), - 'update_at' => StringParser::get($element->update), + 'update_at' => new DateTime($update), 'week' => StringParser::get($element->week), ]); } diff --git a/tests/Repositories/ChannelRepositoryTest.php b/tests/Repositories/ChannelRepositoryTest.php index 2843a8b..eea6511 100644 --- a/tests/Repositories/ChannelRepositoryTest.php +++ b/tests/Repositories/ChannelRepositoryTest.php @@ -19,6 +19,7 @@ declare(strict_types = 1); namespace Tests\Repositories; +use DateTime; use EPGService\Repositories\ChannelRepository; use PHPUnit\Framework\TestCase; use Tests\Utilities\GetServiceEnvironment; @@ -44,8 +45,8 @@ final class ChannelRepositoryTest extends TestCase { self::assertIsString($channel->id); self::assertIsString($channel->lang); self::assertIsString($channel->name); - self::assertIsString($channel->update_at); self::assertIsString($channel->week); + self::isInstanceOf(DateTime::class, $channel->update_at); } } } -- cgit v1.2.3 From 5ba704abceb11f6e0bb3646492809a323a8fa19d Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 19 Jul 2020 19:16:47 +0400 Subject: Added country entity Signed-off-by: Valentin Popov --- src/Entities/CountryEntity.php | 123 +++++++++++++++++++++++++++++++++++ tests/Entities/CountryEntityTest.php | 49 ++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 src/Entities/CountryEntity.php create mode 100644 tests/Entities/CountryEntityTest.php (limited to 'src/Entities') diff --git a/src/Entities/CountryEntity.php b/src/Entities/CountryEntity.php new file mode 100644 index 0000000..fb559d8 --- /dev/null +++ b/src/Entities/CountryEntity.php @@ -0,0 +1,123 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities + */ +final class CountryEntity { + /** + * @var int + */ + private int $id; + + /** + * @var string + */ + private string $iso; + + /** + * @var string + */ + private string $lang; + + /** + * @var string + */ + private string $name; + + /** + * @var string + */ + private string $version; + + /** + * @param array $payload + */ + private function __construct(array $payload) { + $this->id = $payload['id']; + $this->iso = $payload['iso']; + $this->lang = $payload['lang']; + $this->name = $payload['name']; + $this->version = $payload['version']; + } + + /** + * @param array $payload + * + * @return \EPGService\Entities\CountryEntity + * + * @throws \RuntimeException + */ + public static function create(array $payload): CountryEntity { + if (!is_int($payload['id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['iso'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['lang'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['name'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['version'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new CountryEntity($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'); + } +} diff --git a/tests/Entities/CountryEntityTest.php b/tests/Entities/CountryEntityTest.php new file mode 100644 index 0000000..dd44075 --- /dev/null +++ b/tests/Entities/CountryEntityTest.php @@ -0,0 +1,49 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities + */ +final class CountryEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Faker::create(); + + $id = $faker->numberBetween(1, 100); + $iso = $faker->countryCode; + $lang = $faker->languageCode; + $name = $faker->unique()->sha256; + $version = $faker->unique()->sha256; + + $entity = CountryEntity::create(compact('id', 'iso', 'lang', 'name', 'version')); + + self::assertEquals($id, $entity->id); + self::assertEquals($iso, $entity->iso); + self::assertEquals($lang, $entity->lang); + self::assertEquals($name, $entity->name); + self::assertEquals($version, $entity->version); + } +} -- cgit v1.2.3 From 400862f5eea453730b556b34faf1bb45b03a6751 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 19 Jul 2020 19:48:41 +0400 Subject: Updated country entity Signed-off-by: Valentin Popov --- src/Entities/CountryEntity.php | 7 +++---- tests/Entities/CountryEntityTest.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/CountryEntity.php b/src/Entities/CountryEntity.php index fb559d8..37d4d6e 100644 --- a/src/Entities/CountryEntity.php +++ b/src/Entities/CountryEntity.php @@ -20,7 +20,6 @@ declare(strict_types = 1); namespace EPGService\Entities; use RuntimeException; -use function is_int; use function is_string; /** @@ -36,9 +35,9 @@ use function is_string; */ final class CountryEntity { /** - * @var int + * @var string */ - private int $id; + private string $id; /** * @var string @@ -79,7 +78,7 @@ final class CountryEntity { * @throws \RuntimeException */ public static function create(array $payload): CountryEntity { - if (!is_int($payload['id'])) { + if (!is_string($payload['id'])) { throw new RuntimeException('blah-blah-blah'); } diff --git a/tests/Entities/CountryEntityTest.php b/tests/Entities/CountryEntityTest.php index dd44075..ffff4fd 100644 --- a/tests/Entities/CountryEntityTest.php +++ b/tests/Entities/CountryEntityTest.php @@ -32,7 +32,7 @@ final class CountryEntityTest extends TestCase { public function testCreateEntity(): void { $faker = Faker::create(); - $id = $faker->numberBetween(1, 100); + $id = $faker->unique()->sha256; $iso = $faker->countryCode; $lang = $faker->languageCode; $name = $faker->unique()->sha256; -- cgit v1.2.3 From 7d078315d6f592de968fbaf9959a2dbc2f59ddfe Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 19 Jul 2020 20:14:20 +0400 Subject: Updated genre entity Signed-off-by: Valentin Popov --- src/Entities/GenreEntity.php | 26 +++++++++++--------------- tests/Entities/GenreEntityTest.php | 8 ++++---- 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/GenreEntity.php b/src/Entities/GenreEntity.php index 61e11ba..ee81041 100644 --- a/src/Entities/GenreEntity.php +++ b/src/Entities/GenreEntity.php @@ -20,11 +20,10 @@ declare(strict_types = 1); namespace EPGService\Entities; use RuntimeException; -use function is_int; use function is_string; /** - * @property-read int $id + * @property-read string $id * @property-read string $lang * @property-read string $name * @property-read string $version @@ -35,9 +34,9 @@ use function is_string; */ final class GenreEntity { /** - * @var int + * @var string */ - private int $id; + private string $id; /** * @var string @@ -55,20 +54,17 @@ final class GenreEntity { private string $version; /** - * @param int $id - * @param string $lang - * @param string $name - * @param string $version + * @param array $payload */ - private function __construct(int $id, string $lang, string $name, string $version) { - $this->id = $id; - $this->lang = $lang; - $this->name = $name; - $this->version = $version; + private function __construct(array $payload) { + $this->id = $payload['id']; + $this->lang = $payload['lang']; + $this->name = $payload['name']; + $this->version = $payload['version']; } public static function create(array $payload): GenreEntity { - if (!is_int($payload['id'])) { + if (!is_string($payload['id'])) { throw new RuntimeException('blah-blah-blah'); } @@ -84,7 +80,7 @@ final class GenreEntity { throw new RuntimeException('blah-blah-blah'); } - return new GenreEntity($payload['id'], $payload['lang'], $payload['name'], $payload['version']); + return new GenreEntity($payload); } /** diff --git a/tests/Entities/GenreEntityTest.php b/tests/Entities/GenreEntityTest.php index 0b1b12c..278fb68 100644 --- a/tests/Entities/GenreEntityTest.php +++ b/tests/Entities/GenreEntityTest.php @@ -32,10 +32,10 @@ final class GenreEntityTest extends TestCase { public function testCreateEntity(): void { $faker = Faker::create(); - $id = $faker->numberBetween(1, 999); - $lang = $faker->languageCode; - $name = $faker->word; - $version = $faker->sha256; + $id = $faker->unique()->sha256; + $lang = $faker->unique()->sha256; + $name = $faker->unique()->sha256; + $version = $faker->unique()->sha256; $entity = GenreEntity::create(compact('id', 'lang', 'name', 'version')); -- cgit v1.2.3 From a5a69a7732eaf278200ff2af53ed875de43714af Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 19 Jul 2020 20:15:07 +0400 Subject: Fixed PhpDoc Signed-off-by: Valentin Popov --- src/Entities/CountryEntity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/CountryEntity.php b/src/Entities/CountryEntity.php index 37d4d6e..bf8b6f7 100644 --- a/src/Entities/CountryEntity.php +++ b/src/Entities/CountryEntity.php @@ -23,7 +23,7 @@ use RuntimeException; use function is_string; /** - * @property-read int $id + * @property-read string $id * @property-read string $iso * @property-read string $lang * @property-read string $name -- cgit v1.2.3 From 506e16bdfcae6996adacdcb5ba23fdf45c98bafe Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 19 Jul 2020 20:18:09 +0400 Subject: Updated category entity Signed-off-by: Valentin Popov --- src/Entities/CategoryEntity.php | 26 +++++++++++--------------- tests/Entities/CategoryEntityTest.php | 8 ++++---- 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/CategoryEntity.php b/src/Entities/CategoryEntity.php index af44434..2d113a4 100644 --- a/src/Entities/CategoryEntity.php +++ b/src/Entities/CategoryEntity.php @@ -20,11 +20,10 @@ declare(strict_types = 1); namespace EPGService\Entities; use RuntimeException; -use function is_int; use function is_string; /** - * @property-read int $id + * @property-read string $id * @property-read string $lang * @property-read string $name * @property-read string $version @@ -35,9 +34,9 @@ use function is_string; */ final class CategoryEntity { /** - * @var int + * @var string */ - private int $id; + private string $id; /** * @var string @@ -55,16 +54,13 @@ final class CategoryEntity { private string $version; /** - * @param int $id - * @param string $lang - * @param string $name - * @param string $version + * @param array $payload */ - private function __construct(int $id, string $lang, string $name, string $version) { - $this->id = $id; - $this->lang = $lang; - $this->name = $name; - $this->version = $version; + private function __construct(array $payload) { + $this->id = $payload['id']; + $this->lang = $payload['lang']; + $this->name = $payload['name']; + $this->version = $payload['version']; } /** @@ -74,7 +70,7 @@ final class CategoryEntity { * @throws \RuntimeException */ public static function create(array $payload): CategoryEntity { - if (!is_int($payload['id'])) { + if (!is_string($payload['id'])) { throw new RuntimeException('blah-blah-blah'); } @@ -90,7 +86,7 @@ final class CategoryEntity { throw new RuntimeException('blah-blah-blah'); } - return new CategoryEntity($payload['id'], $payload['lang'], $payload['name'], $payload['version']); + return new CategoryEntity($payload); } /** diff --git a/tests/Entities/CategoryEntityTest.php b/tests/Entities/CategoryEntityTest.php index 6ad7bd3..35363fa 100644 --- a/tests/Entities/CategoryEntityTest.php +++ b/tests/Entities/CategoryEntityTest.php @@ -32,10 +32,10 @@ final class CategoryEntityTest extends TestCase { public function testCreateEntity(): void { $faker = Faker::create(); - $id = $faker->numberBetween(1, 999); - $lang = $faker->languageCode; - $name = $faker->word; - $version = $faker->sha256; + $id = $faker->unique()->sha256; + $lang = $faker->unique()->sha256; + $name = $faker->unique()->sha256; + $version = $faker->unique()->sha256; $entity = CategoryEntity::create(compact('id', 'lang', 'name', 'version')); -- cgit v1.2.3