diff --git a/.styleci.yml b/.styleci.yml index ba68364..e2be4f1 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,3 +1,3 @@ -preset: psr2 +preset: psr12 risky: false diff --git a/composer.json b/composer.json index b4a4aba..7e39779 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ }, "require-dev": { "scrutinizer/ocular": "~1.1", - "phpunit/phpunit": "^7.5 || ^8.5" + "phpunit/phpunit": "^7.5 || ^8.5", + "squizlabs/php_codesniffer": "3.*" }, "license" : "GPL-2.0-or-later", "type" : "library", diff --git a/src/AbstractCalculator.php b/src/AbstractCalculator.php index d084487..6283ce4 100644 --- a/src/AbstractCalculator.php +++ b/src/AbstractCalculator.php @@ -10,13 +10,12 @@ */ abstract class AbstractCalculator { - // women char - const CHR_WOMEN = 'F'; - + protected const CHR_WOMEN = 'F'; + // male char - const CHR_MALE = 'M'; - + protected const CHR_MALE = 'M'; + /** * Array of all available months. */ @@ -34,7 +33,7 @@ abstract class AbstractCalculator '11' => 'S', '12' => 'T', ); - + /** * Array of all avaialable odd characters. */ @@ -118,7 +117,7 @@ abstract class AbstractCalculator 'Y' => 24, 'Z' => 25, ); - + /** * Array of all avaialable omocodia characters. diff --git a/src/Calculator.php b/src/Calculator.php index 0ac5b97..8743210 100644 --- a/src/Calculator.php +++ b/src/Calculator.php @@ -41,11 +41,11 @@ public function __construct(Subject $subject, $properties = array()) */ public function calculate() { - $temporaryCodiceFiscale = $this->calculateSurname().$this->calculateName(). - $this->calculateBirthDateAndGender().$this->calculateBelfioreCode(); + $temporaryCodiceFiscale = $this->calculateSurname() . $this->calculateName() . + $this->calculateBirthDateAndGender() . $this->calculateBelfioreCode(); $temporaryCodiceFiscale = $this->calculateOmocodia($temporaryCodiceFiscale); - return $temporaryCodiceFiscale.$this->calculateCheckDigit($temporaryCodiceFiscale); + return $temporaryCodiceFiscale . $this->calculateCheckDigit($temporaryCodiceFiscale); } /** @@ -92,7 +92,7 @@ private function calculateName() $name = $this->cleanString($this->subject->getName()); $consonants = str_replace($this->vowels, '', strtoupper($name)); if (strlen($consonants) > 3) { - $result = $consonants[0].$consonants[2].$consonants[3]; + $result = $consonants[0] . $consonants[2] . $consonants[3]; } elseif (strlen($consonants) == 3) { $result = $consonants; } else { @@ -113,7 +113,7 @@ private function calculateSmallString($consonants, $string) { $string = $this->cleanString($string); $vowels = str_replace(str_split($consonants), '', strtoupper($string)); - $result = substr($consonants.$vowels.'XXX', 0, 3); + $result = substr($consonants . $vowels . 'XXX', 0, 3); return $result; } @@ -132,7 +132,7 @@ private function calculateBirthDateAndGender() $day += 40; } - return $year.$month.$day; + return $year . $month . $day; } /** @@ -155,13 +155,55 @@ private function calculateOmocodia($temporaryCodiceFiscale) { if ($this->omocodiaLevel > 0) { if ($this->omocodiaLevel) { - $temporaryCodiceFiscale = $this->replaceOmocodiaSection(2, $temporaryCodiceFiscale, 1, 1, $this->omocodiaPositions[0]); - $temporaryCodiceFiscale = $this->replaceOmocodiaSection(4, $temporaryCodiceFiscale, 2, 3, $this->omocodiaPositions[1]); - $temporaryCodiceFiscale = $this->replaceOmocodiaSection(8, $temporaryCodiceFiscale, 4, 7, $this->omocodiaPositions[2]); - $temporaryCodiceFiscale = $this->replaceOmocodiaSection(16, $temporaryCodiceFiscale, 8, 15, $this->omocodiaPositions[3]); - $temporaryCodiceFiscale = $this->replaceOmocodiaSection(32, $temporaryCodiceFiscale, 16, 31, $this->omocodiaPositions[4]); - $temporaryCodiceFiscale = $this->replaceOmocodiaSection(64, $temporaryCodiceFiscale, 32, 63, $this->omocodiaPositions[5]); - $temporaryCodiceFiscale = $this->replaceOmocodiaSection(128, $temporaryCodiceFiscale, 64, 127, $this->omocodiaPositions[6]); + $temporaryCodiceFiscale = $this->replaceOmocodiaSection( + 2, + $temporaryCodiceFiscale, + 1, + 1, + $this->omocodiaPositions[0] + ); + $temporaryCodiceFiscale = $this->replaceOmocodiaSection( + 4, + $temporaryCodiceFiscale, + 2, + 3, + $this->omocodiaPositions[1] + ); + $temporaryCodiceFiscale = $this->replaceOmocodiaSection( + 8, + $temporaryCodiceFiscale, + 4, + 7, + $this->omocodiaPositions[2] + ); + $temporaryCodiceFiscale = $this->replaceOmocodiaSection( + 16, + $temporaryCodiceFiscale, + 8, + 15, + $this->omocodiaPositions[3] + ); + $temporaryCodiceFiscale = $this->replaceOmocodiaSection( + 32, + $temporaryCodiceFiscale, + 16, + 31, + $this->omocodiaPositions[4] + ); + $temporaryCodiceFiscale = $this->replaceOmocodiaSection( + 64, + $temporaryCodiceFiscale, + 32, + 63, + $this->omocodiaPositions[5] + ); + $temporaryCodiceFiscale = $this->replaceOmocodiaSection( + 128, + $temporaryCodiceFiscale, + 64, + 127, + $this->omocodiaPositions[6] + ); } } @@ -178,8 +220,13 @@ private function calculateOmocodia($temporaryCodiceFiscale) * @param $characterIndex int The index to use to make the substitutions on the $temporaryCodiceFiscale. * @return string The temporary codice fiscale with the substitutions made. */ - private function replaceOmocodiaSection($divider, $temporaryCodiceFiscale, $startingIndex, $endingIndex, $characterIndex) - { + private function replaceOmocodiaSection( + $divider, + $temporaryCodiceFiscale, + $startingIndex, + $endingIndex, + $characterIndex + ) { if ($this->omocodiaLevel % $divider >= $startingIndex && $this->omocodiaLevel % $divider <= $endingIndex) { $k = $temporaryCodiceFiscale[$characterIndex]; $newChar = $this->omocodiaCodes[$k]; diff --git a/src/Checker.php b/src/Checker.php index 887ef60..add5b01 100644 --- a/src/Checker.php +++ b/src/Checker.php @@ -16,7 +16,7 @@ class Checker /** * Constant to check for all the omocodia levels. */ - const ALL_OMOCODIA_LEVELS = -1; + public const ALL_OMOCODIA_LEVELS = -1; /** * Checker constructor. diff --git a/src/InverseCalculator.php b/src/InverseCalculator.php index 4af3af5..2438428 100644 --- a/src/InverseCalculator.php +++ b/src/InverseCalculator.php @@ -12,7 +12,7 @@ class InverseCalculator extends Validator { private $belfioreCode = null; - + /** * Create an InverseCalculator instance. * @@ -22,10 +22,10 @@ class InverseCalculator extends Validator public function __construct($codiceFiscale, $properties = []) { parent::__construct($codiceFiscale, $properties); - + if ($this->isFormallyValid()) { $codiceFiscaleWithoutOmocodia = $this->getCodiceFiscaleWithoutOmocodia(); - + // calculate belfiore code $this->belfioreCode = substr($codiceFiscaleWithoutOmocodia, 11, 4); } diff --git a/src/Validator.php b/src/Validator.php index 60caf16..4cf0a5f 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -143,16 +143,16 @@ class Validator extends AbstractCalculator 126 => '/^[a-z]{14}[0-9][a-z]$/i', //RSSMRAURTMLARS2W 127 => '/^[a-z]{16}$/i', //RSSMRAURTMLARSNL ); - + private $codiceFiscale; private $omocodiaAllowed = true; private $century = null; - + private $foundOmocodiaLevel = null; private $codiceFiscaleWithoutOmocodia = null; private $birthDate = null; private $gender = null; - + private $error = null; private $isValid = false; @@ -165,22 +165,22 @@ class Validator extends AbstractCalculator public function __construct($codiceFiscale, $properties = array()) { $this->codiceFiscale = strtoupper($codiceFiscale); - + if (array_key_exists('omocodiaAllowed', $properties)) { $this->omocodiaAllowed = $properties['omocodiaAllowed']; } - + if (array_key_exists('century', $properties)) { $this->century = $properties['century']; } - + try { $this->validateLength(); $this->validateFormat(); $this->validateCheckDigit(); - + $this->validateAndReplaceOmocodia(); $this->validateBirthDateAndGender(); @@ -240,7 +240,7 @@ private function validateFormat() throw new Exception('The codice fiscale to validate has an invalid format'); } } - + /** * Validates check digit * @@ -253,7 +253,7 @@ private function validateCheckDigit() throw new Exception('The codice fiscale to validate has an invalid control character'); } } - + /** * Validates omocodia and replace with matching chars * @@ -283,7 +283,10 @@ private function validateAndReplaceOmocodia() */ private function replaceOmocodiaSection($divider, $startingIndex, $endingIndex, $characterIndex) { - if ($this->foundOmocodiaLevel % $divider >= $startingIndex && $this->foundOmocodiaLevel % $divider <= $endingIndex) { + if ( + $this->foundOmocodiaLevel % $divider >= $startingIndex && + $this->foundOmocodiaLevel % $divider <= $endingIndex + ) { $charToCheck = $this->codiceFiscaleWithoutOmocodia[$characterIndex]; if (!in_array($charToCheck, $this->omocodiaCodes)) { throw new Exception('The codice fiscale to validate has an invalid character'); @@ -292,7 +295,7 @@ private function replaceOmocodiaSection($divider, $startingIndex, $endingIndex, $this->codiceFiscaleWithoutOmocodia[$characterIndex] = $newChar; } } - + /** * Validates birthdate and gender * @@ -318,19 +321,19 @@ private function validateBirthDateAndGender() if (!in_array($monthChar, $this->months)) { throw new Exception('The codice fiscale to validate has an invalid character for birth month'); } - + // calculate month, year and century $month = array_search($monthChar, $this->months); $year = substr($this->codiceFiscaleWithoutOmocodia, 6, 2); $century = $this->calculateCentury($year); // validate and calculate birth date - if (!checkdate($month, $day, $century.$year)) { + if (!checkdate($month, $day, $century . $year)) { throw new Exception('The codice fiscale to validate has an non existent birth date'); } - + $this->birthDate = new DateTime(); - $this->birthDate->setDate($century.$year, $month, $day)->setTime(0, 0, 0)->format('Y-m-d'); + $this->birthDate->setDate($century . $year, $month, $day)->setTime(0, 0, 0)->format('Y-m-d'); } /** @@ -349,7 +352,7 @@ private function calculateCentury($year) $currentCentury = substr($currentDate->format('Y'), 0, 2); $century = $year < $currentYear ? $currentCentury : $currentCentury - 1; } - + return $century; } diff --git a/test/CalculatorTest.php b/test/CalculatorTest.php index 97825bb..998dcf2 100644 --- a/test/CalculatorTest.php +++ b/test/CalculatorTest.php @@ -43,234 +43,234 @@ public function calculateProvider() return array( array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 0, 'RSSMRA85T10A562S', ), array( new Subject( - array( + array( 'name' => 'Roberto', 'surname' => 'Santini', 'birthDate' => '1963-05-08', 'gender' => 'M', 'belfioreCode' => 'H501', - ) + ) ), 0, 'SNTRRT63E08H501T', ), array( new Subject( - array( + array( 'name' => 'Davide', 'surname' => 'Rossi', 'birthDate' => '1989-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 0, 'RSSDVD89T10A562S', ), array( new Subject( - array( + array( 'name' => 'Maria', 'surname' => 'Montessori', 'birthDate' => '1870-08-31', 'gender' => 'F', 'belfioreCode' => 'C615', - ) + ) ), 0, 'MNTMRA70M71C615I', ), array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => new \DateTime('1985-12-10'), 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 0, 'RSSMRA85T10A562S', ), array( new Subject( - array( + array( 'name' => 'Gianfranco', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 0, 'RSSGFR85T10A562I', ), array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Fo', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 0, 'FOXMRA85T10A562G', ), array( new Subject( - array( + array( 'name' => '', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 0, 'RSSXXX85T10A562R', ), array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => '', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 0, 'XXXMRA85T10A562B', ), array( new Subject( - array( + array( 'name' => '', 'surname' => '', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 0, 'XXXXXX85T10A562A', ), array( new Subject( - array( + array( 'name' => 'Roberto', 'surname' => 'Santi', 'birthDate' => '1963-05-08', 'gender' => 'M', 'belfioreCode' => 'H501', - ) + ) ), 1, 'SNTRRT63E08H50ML', ), array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 1, 'RSSMRA85T10A56NH', ), array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 3, 'RSSMRA85T10A5SNT', ), array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'De Rossi', 'birthDate' => '1990-01-01', 'gender' => 'M', 'belfioreCode' => 'F839', - ) + ) ), -1, 'DRSMRA90A01F839W', ), array( new Subject( - array( + array( 'name' => 'Anna Paola', 'surname' => 'Rossi', 'birthDate' => '1990-01-01', 'gender' => 'F', 'belfioreCode' => 'F839', - ) + ) ), -1, 'RSSNPL90A41F839J', ), array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => "D'Ossi", 'birthDate' => '1990-01-01', 'gender' => 'M', 'belfioreCode' => 'F839', - ) + ) ), -1, 'DSSMRA90A01F839X', ), array( new Subject( - array( + array( 'name' => "Lu'ay", 'surname' => "D'ari", 'birthDate' => '1990-01-01', 'gender' => 'M', 'belfioreCode' => 'F839', - ) + ) ), -1, 'DRALYU90A01F839U', ), array( new Subject( - array( + array( 'name' => "Annalisa", 'surname' => "Lisà", 'birthDate' => '1980-04-04', 'gender' => 'F', 'belfioreCode' => 'H501', - ) + ) ), -1, 'LSINLS80D44H501F', @@ -286,13 +286,13 @@ public function calculateAllPossibilitiesProvider() return array( array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), array( 'RSSMRA85T10A562S', @@ -427,13 +427,13 @@ public function calculateAllPossibilitiesProvider() ), array( new Subject( - array( + array( 'name' => 'Roberto', 'surname' => 'Santi', 'birthDate' => '1963-05-08', 'gender' => 'M', 'belfioreCode' => 'H501', - ) + ) ), array( 'SNTRRT63E08H501T', diff --git a/test/CheckerTest.php b/test/CheckerTest.php index ff8a3c7..061be31 100644 --- a/test/CheckerTest.php +++ b/test/CheckerTest.php @@ -32,13 +32,13 @@ public function checkerProvider() return array( array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 'RSSMRA85T10A562S', 0, @@ -46,13 +46,13 @@ public function checkerProvider() ), array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 'RSSMRA85T10A562S', 2, @@ -60,13 +60,13 @@ public function checkerProvider() ), array( new Subject( - array( + array( 'name' => 'Roberto', 'surname' => 'Santi', 'birthDate' => '1963-05-08', 'gender' => 'M', 'belfioreCode' => 'H501', - ) + ) ), 'SNTRRT63E08H50ML', Checker::ALL_OMOCODIA_LEVELS, @@ -74,13 +74,13 @@ public function checkerProvider() ), array( new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), 'RSSMRAURTMLAR6NZ', Checker::ALL_OMOCODIA_LEVELS, @@ -88,13 +88,13 @@ public function checkerProvider() ), array( new Subject( - array( + array( 'name' => "Annalisa", 'surname' => "Lisà", 'birthDate' => '1980-04-04', 'gender' => 'F', 'belfioreCode' => 'H501', - ) + ) ), 'LSINLS80D44H501F', -1, diff --git a/test/InverseCalculatorTest.php b/test/InverseCalculatorTest.php index 3be249e..7904101 100644 --- a/test/InverseCalculatorTest.php +++ b/test/InverseCalculatorTest.php @@ -36,27 +36,27 @@ public function testInverseCalculate($codiceFiscale, $omocodiaAllowed, $century, public function calculateProvider() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); return array_merge( - array( + array( array( 'RSSMRA85T10A562S', true, null, new Subject( - array( + array( 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), ), array( @@ -64,11 +64,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1963-05-08', 'gender' => 'M', 'belfioreCode' => 'H501', - ) + ) ) ), array( @@ -76,11 +76,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1989-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ) ), array( @@ -88,11 +88,11 @@ public function calculateProvider() true, 18, new Subject( - array( + array( 'birthDate' => '1870-08-31', 'gender' => 'F', 'belfioreCode' => 'C615', - ) + ) ) ), array( @@ -100,11 +100,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), ), array( @@ -112,11 +112,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), ), array( @@ -124,11 +124,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), ), array( @@ -136,11 +136,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ) ), array( @@ -148,11 +148,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1963-05-08', 'gender' => 'M', 'belfioreCode' => 'H501', - ) + ) ) ), array( @@ -160,11 +160,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ) ), array( @@ -172,11 +172,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ), ), array( @@ -184,11 +184,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1990-01-01', 'gender' => 'M', 'belfioreCode' => 'F839', - ) + ) ) ), array( @@ -196,11 +196,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1990-01-01', 'gender' => 'F', 'belfioreCode' => 'F839', - ) + ) ) ), array( @@ -208,11 +208,11 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1990-01-01', 'gender' => 'M', 'belfioreCode' => 'F839', - ) + ) ), ), array( @@ -220,16 +220,16 @@ public function calculateProvider() true, null, new Subject( - array( + array( 'birthDate' => '1990-01-01', 'gender' => 'M', 'belfioreCode' => 'F839', - ) + ) ) ), - ), - // Handle all the different omocodia levels - $this->generateAllOmocodiaLevels($subject) + ), + // Handle all the different omocodia levels + $this->generateAllOmocodiaLevels($subject) ); } @@ -250,11 +250,11 @@ private function generateAllOmocodiaLevels($subject) true, null, new Subject( - array( + array( 'birthDate' => $subject->getBirthDate(), 'gender' => $subject->getGender(), 'belfioreCode' => $subject->getBelfioreCode(), - ) + ) ) ); } diff --git a/test/SubjectTest.php b/test/SubjectTest.php index b0af5a0..a59a7f0 100644 --- a/test/SubjectTest.php +++ b/test/SubjectTest.php @@ -15,13 +15,13 @@ class SubjectTest extends \PHPUnit\Framework\TestCase public function testGetName() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $actual = $subject->getName(); $expected = 'Mario'; @@ -34,13 +34,13 @@ public function testGetName() public function testSetName() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $subject->setName('Fabrizio'); $actual = $subject->getName(); @@ -54,13 +54,13 @@ public function testSetName() public function testGetSurname() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $actual = $subject->getSurname(); $expected = 'Rossi'; @@ -73,13 +73,13 @@ public function testGetSurname() public function testSetSurname() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $subject->setSurname('Russo'); $actual = $subject->getSurname(); @@ -93,13 +93,13 @@ public function testSetSurname() public function testGetBirthDate() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $actual = $subject->getBirthDate(); $expected = new \DateTime('1985-12-10'); @@ -112,13 +112,13 @@ public function testGetBirthDate() public function testSetBirthDate() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $subject->setBirthDate(new \DateTime('1944-01-10')); $actual = $subject->getBirthDate(); @@ -132,13 +132,13 @@ public function testSetBirthDate() public function testSetBirthDateImmutable() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $subject->setBirthDate(new \DateTimeImmutable('1944-01-10')); $actual = $subject->getBirthDate(); @@ -152,13 +152,13 @@ public function testSetBirthDateImmutable() public function testSetBirthDateFancyConversion() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $subject->setBirthDate('1944-01-10'); $actual = $subject->getBirthDate(); @@ -172,13 +172,13 @@ public function testSetBirthDateFancyConversion() public function testGetGender() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $actual = $subject->getGender(); $expected = 'M'; @@ -191,13 +191,13 @@ public function testGetGender() public function testSetGender() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $subject->setGender('F'); $actual = $subject->getGender(); @@ -211,13 +211,13 @@ public function testSetGender() public function testGetBelfioreCode() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $actual = $subject->getBelfioreCode(); $expected = 'A562'; @@ -230,13 +230,13 @@ public function testGetBelfioreCode() public function testSetBelfioreCode() { $subject = new Subject( - array( + array( 'name' => 'Mario', 'surname' => 'Rossi', 'birthDate' => '1985-12-10', 'gender' => 'M', 'belfioreCode' => 'A562', - ) + ) ); $subject->setBelfioreCode('H501'); $actual = $subject->getBelfioreCode(); diff --git a/test/ValidatorTest.php b/test/ValidatorTest.php index a22159d..b5353cc 100644 --- a/test/ValidatorTest.php +++ b/test/ValidatorTest.php @@ -14,18 +14,24 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase * * @dataProvider validatorProvider */ - public function testValidationTrue($codiceFiscaleToValidate, $omocodiaAllowed, $secular, $isFormallyValid, $isOmocodia = false) - { - $validator = new Validator($codiceFiscaleToValidate, + public function testValidationTrue( + $codiceFiscaleToValidate, + $omocodiaAllowed, + $secular, + $isFormallyValid, + $isOmocodia = false + ) { + $validator = new Validator( + $codiceFiscaleToValidate, array('omocodiaAllowed' => $omocodiaAllowed, 'secular' => $secular) - ); - + ); + $actual = $validator->isFormallyValid(); $this->assertEquals($isFormallyValid, $actual); - + $this->{$isFormallyValid ? "assertEquals" : "assertNotEquals"}(null, $validator->getError()); - + if ($isFormallyValid && $isOmocodia) { $this->assertEquals($isOmocodia, $validator->isOmocodia()); }