Skip to content

Commit

Permalink
Another PSR-2 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidePastore committed Nov 22, 2015
1 parent 5b0fa8b commit e976949
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/DavidePastore/CodiceFiscale/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ private function calculateSurname()
if (strlen($consonants) > 2) {
$result = substr($consonants, 0, 3);
} else {
$vowels = str_replace(str_split($consonants), '', strtoupper($this->subject->getSurname()));
$result = substr($consonants.$vowels.'XXX', 0, 3);
$result = $this->calculateSmallString($consonants, $this->subject->getSurname());
}

return $result;
Expand All @@ -211,12 +210,24 @@ private function calculateName()
} elseif (strlen($consonants) == 3) {
$result = implode($consonants);
} else {
$vowels = str_replace(str_split($consonants), '', strtoupper($this->subject->getName()));
$result = substr($consonants.$vowels.'XXX', 0, 3);
$result = $this->calculateSmallString($consonants, $this->subject->getName());
}

return $result;
}

/**
* Calculate small string for the given parameters (used by name and surname).
* @param $consonants A consonants string.
* @param $string The small string.
* @returns Returns the calculated result for the small string.
*/
private function calculateSmallString($consonants, $string)
{
$vowels = str_replace(str_split($consonants), '', strtoupper($string));
$result = substr($consonants.$vowels.'XXX', 0, 3);
return $result;
}

/**
* Calculate the birth date and the gender.
Expand Down

0 comments on commit e976949

Please sign in to comment.