Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 58 additions & 5 deletions src/CodiceFiscale/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Checker
{
// fiscal's code regex
const REGEX_CODICEFISCALE = '/^[a-z]{6}[0-9]{2}[a-z][0-9]{2}[a-z][0-9]{3}[a-z]$/i';
const REGEX_CODICEFISCALE = '/^[a-z]{6}[0-9lmnpqrstuvLMNPQRSTUV]{2}[a-z][0-9lmnpqrstuvLMNPQRSTUV]{2}[a-z][0-9lmnpqrstuvLMNPQRSTUV]{3}[a-z]$/i';

// women char
const CHR_WOMEN = 'F';
Expand All @@ -30,12 +30,24 @@ class Checker
*/
private $sex = null;

/**
* Real Country Birth
* @var integer
*/
private $realCountryBirth = null;

/**
* Country Birth
* @var integer
*/
private $countryBirth = null;

/**
* Day Birth
* @var integer
*/
private $realDayBirth = null;

/**
* Day Birth
* @var integer
Expand All @@ -48,6 +60,12 @@ class Checker
*/
private $monthBirth = null;

/**
* Year Birth
* @var integer
*/
private $realYearBirth = null;

/**
* Year Birth
* @var integer
Expand Down Expand Up @@ -143,6 +161,17 @@ public function getCountryBirth()
}



/**
* Getter CountryBirth
* @return integer
*/
public function getRealCountryBirth()
{
return $this->realCountryBirth;
}


/**
* Getter YearBirth
* @return integer
Expand All @@ -153,6 +182,18 @@ public function getYearBirth()
}



/**
* Getter YearBirth
* @return integer
*/
public function getRealYearBirth()
{
return $this->realYearBirth;
}



/**
* Getter MonthBirth
* @return integer
Expand All @@ -173,6 +214,16 @@ public function getDayBirth()
}


/**
* Getter DayBirth
* @return integer
*/
public function getRealDayBirth()
{
return $this->realDayBirth;
}


/**
* Check Codice Fiscale
* @param string $codiceFiscale
Expand Down Expand Up @@ -223,16 +274,18 @@ public function isFormallyCorrect($codiceFiscale)
if (!($this->listCtrlCode[($pari + $dispari) % 26] === $cFCharList[15])) {
$this->raiseException(4);
}

$tempCFCharList = $cFCharList;
// replace "omocodie"
for ($i = 0; $i < count($this->listSostOmocodia); $i++) {
if (!is_numeric($cFCharList[$this->listSostOmocodia[$i]])) {
$CFCharList[$this->listSostOmocodia[$i]] = $this->listDecOmocodia[$cFCharList[$this->listSostOmocodia[$i]]];
$cFCharList[$this->listSostOmocodia[$i]] = $this->listDecOmocodia[$cFCharList[$this->listSostOmocodia[$i]]];
}
}

$tempCodiceFiscaleAdattato = implode($tempCFCharList);
$codiceFiscaleAdattato = implode($cFCharList);

$this->realCountryBirth = substr($tempCodiceFiscaleAdattato, 11, 4);
$this->realYearBirth = substr($tempCodiceFiscaleAdattato, 6, 2);
$this->realDayBirth = substr($tempCodiceFiscaleAdattato, 9, 2);
// get fiscal code data
$this->sex = ((int)(substr($codiceFiscaleAdattato, 9, 2) > 40) ? self::CHR_WOMEN : self::CHR_MALE);
$this->countryBirth = substr($codiceFiscaleAdattato, 11, 4);
Expand Down