Skip to content

Commit

Permalink
Remove age property to match updated v3 spec (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusbe authored Feb 20, 2020
1 parent 2d8ce95 commit 290471d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
9 changes: 1 addition & 8 deletions src/Personnummer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use DateTime;
use Exception;
use TypeError;

/**
* Class Personnummer
Expand All @@ -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
{
Expand Down Expand Up @@ -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(
Expand All @@ -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);
}

/**
Expand Down
7 changes: 2 additions & 5 deletions tests/PersonnummerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand All @@ -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()
Expand Down Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit 290471d

Please sign in to comment.