From 290471d7ff440a6ced9b45b7aeab000147331df7 Mon Sep 17 00:00:00 2001 From: Rasmus <2124386+rasmusbe@users.noreply.github.com> Date: Thu, 20 Feb 2020 12:18:31 +0100 Subject: [PATCH] Remove age property to match updated v3 spec (#27) --- README.md | 1 - src/Personnummer.php | 9 +-------- tests/PersonnummerTest.php | 7 ++----- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 366b65b..33c2d4a 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ composer require personnummer/personnummer | Property | Type | Description | | ---------|:-------|----------------------------:| -| age | int | Current age | | century | string | Century, two digits | | year | string | Year, two digits | | fullYear | string | Year, four digits | diff --git a/src/Personnummer.php b/src/Personnummer.php index f5ee87a..8aadc5a 100644 --- a/src/Personnummer.php +++ b/src/Personnummer.php @@ -4,7 +4,6 @@ use DateTime; use Exception; -use TypeError; /** * Class Personnummer @@ -19,8 +18,6 @@ * @property-read string $sep * @property-read string $num * @property-read string $check - * - * @property-read int $age */ final class Personnummer implements PersonnummerInterface { @@ -227,10 +224,6 @@ public function __get(string $name) return $this->parts[$name]; } - if ($name === 'age') { - return $this->getAge(); - } - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); trigger_error( sprintf( @@ -247,7 +240,7 @@ public function __get(string $name) public function __isset(string $name): bool { - return array_key_exists($name, $this->parts) || in_array($name, ['age']); + return array_key_exists($name, $this->parts); } /** diff --git a/tests/PersonnummerTest.php b/tests/PersonnummerTest.php index 4ffa8c5..d804751 100644 --- a/tests/PersonnummerTest.php +++ b/tests/PersonnummerTest.php @@ -161,8 +161,7 @@ public function testAge() continue; } - $this->assertSame($expected, Personnummer::parse($testdata[$format])->age); - $this->assertSame($expected, Personnummer::parse($testdata[$format])->__get('age')); + $this->assertSame($expected, Personnummer::parse($testdata[$format])->getAge()); } } } @@ -181,7 +180,7 @@ public function testAgeOnBirthday() $method->setAccessible(true); $ssn .= $method->invoke(null, substr($ssn, 2)); - $this->assertSame($expected, Personnummer::parse($ssn)->age); + $this->assertSame($expected, Personnummer::parse($ssn)->getAge()); } public function testSex() @@ -217,8 +216,6 @@ public function testProperties() $this->assertSame($expected, Personnummer::parse($testdata['separated_format'])->__get($partName)); $this->assertTrue(isset(Personnummer::parse($testdata['separated_format'])->$partName)); } - - $this->assertTrue(isset(Personnummer::parse($testdata['separated_format'])->age)); } } }