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 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/Entities/CountryEntity.php (limited to 'src/Entities/CountryEntity.php') 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'); + } +} -- 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/CountryEntity.php') 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 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/CountryEntity.php') 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