Exemplo n.º 1
0
 /**
  * Set id
  *
  * Format is YYYYMMDD(+-)NNNC or YYMMDD(+-)NNNC where parenthesis represents
  * an optional one char delimiter, N represents the individual number and C
  * the check digit. If year is set using two digits century is calculated
  * based on delimiter (+ signals more than a hundred years old). If year is
  * set using four digits delimiter is calculated based on century.
  *
  * @param  string $number
  * @throws Exception\InvalidDateStructureException If date is not logically valid
  */
 public function __construct($number)
 {
     list(, $century, $this->serialPre, $delimiter, $this->serialPost, $this->checkDigit) = PersonalId::parseStructure($number);
     $this->delimiter = $delimiter ?: '-';
     if ($century) {
         // Set delimiter based on date (+ if date is more then a hundred years old)
         $this->date = DateTimeCreator::createFromFormat('Ymd', $century . $this->serialPre);
         $hundredYearsAgo = new \DateTime();
         $hundredYearsAgo->modify('-100 year');
         $this->delimiter = $this->getDate() < $hundredYearsAgo ? '+' : '-';
     } else {
         // No century defined
         $this->date = DateTimeCreator::createFromFormat('ymd', $this->serialPre);
         // If in the future century is wrong
         if ($this->date > new \DateTime()) {
             $this->date->modify('-100 year');
         }
         // Date is over a hundred years ago if delimiter is +
         if ($this->getDelimiter() == '+') {
             $this->date->modify('-100 year');
         }
     }
     // Validate that date is logically valid
     if ($this->date->format('ymd') != $this->serialPre) {
         throw new Exception\InvalidDateStructureException("Invalid date in <{$this->getId()}>");
     }
     $this->validateCheckDigit();
 }
Exemplo n.º 2
0
 public function testGetLegalForm()
 {
     $personalId = new PersonalId('770314-0348');
     $this->assertEquals(Id::LEGAL_FORM_UNDEFINED, $personalId->getLegalForm());
     $this->assertTrue($personalId->isLegalFormUndefined());
     $this->assertFalse($personalId->isStateOrParish());
     $this->assertFalse($personalId->isIncorporated());
     $this->assertFalse($personalId->isPartnership());
     $this->assertFalse($personalId->isAssociation());
     $this->assertFalse($personalId->isNonProfit());
     $this->assertFalse($personalId->isTradingCompany());
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  *
  * @return string
  */
 public function getSerialPreDelimiter()
 {
     return (string) intval(parent::getSerialPreDelimiter()) + 60;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  *
  * @return string One of the sex identifier constants
  */
 public function getSex()
 {
     return is_numeric($this->getSerialPostDelimiter()[2]) ? parent::getSex() : self::SEX_UNDEFINED;
 }