@@ -39,92 +39,92 @@ discard block |
||
| 39 | 39 | * Array of all avaialable odd characters. |
| 40 | 40 | */ |
| 41 | 41 | private $odd = array( |
| 42 | - '0' => 1, |
|
| 43 | - '1' => 0, |
|
| 44 | - '2' => 5, |
|
| 45 | - '3' => 7, |
|
| 46 | - '4' => 9, |
|
| 47 | - '5' => 13, |
|
| 48 | - '6' => 15, |
|
| 49 | - '7' => 17, |
|
| 50 | - '8' => 19, |
|
| 51 | - '9' => 21, |
|
| 52 | - 'A' => 1, |
|
| 53 | - 'B' => 0, |
|
| 54 | - 'C' => 5, |
|
| 55 | - 'D' => 7, |
|
| 56 | - 'E' => 9, |
|
| 57 | - 'F' => 13, |
|
| 58 | - 'G' => 15, |
|
| 59 | - 'H' => 17, |
|
| 60 | - 'I' => 19, |
|
| 61 | - 'J' => 21, |
|
| 62 | - 'K' => 2, |
|
| 63 | - 'L' => 4, |
|
| 64 | - 'M' => 18, |
|
| 65 | - 'N' => 20, |
|
| 66 | - 'O' => 11, |
|
| 67 | - 'P' => 3, |
|
| 68 | - 'Q' => 6, |
|
| 69 | - 'R' => 8, |
|
| 70 | - 'S' => 12, |
|
| 71 | - 'T' => 14, |
|
| 72 | - 'U' => 16, |
|
| 73 | - 'V' => 10, |
|
| 74 | - 'W' => 22, |
|
| 75 | - 'X' => 25, |
|
| 76 | - 'Y' => 24, |
|
| 77 | - 'Z' => 23 |
|
| 78 | - ); |
|
| 42 | + '0' => 1, |
|
| 43 | + '1' => 0, |
|
| 44 | + '2' => 5, |
|
| 45 | + '3' => 7, |
|
| 46 | + '4' => 9, |
|
| 47 | + '5' => 13, |
|
| 48 | + '6' => 15, |
|
| 49 | + '7' => 17, |
|
| 50 | + '8' => 19, |
|
| 51 | + '9' => 21, |
|
| 52 | + 'A' => 1, |
|
| 53 | + 'B' => 0, |
|
| 54 | + 'C' => 5, |
|
| 55 | + 'D' => 7, |
|
| 56 | + 'E' => 9, |
|
| 57 | + 'F' => 13, |
|
| 58 | + 'G' => 15, |
|
| 59 | + 'H' => 17, |
|
| 60 | + 'I' => 19, |
|
| 61 | + 'J' => 21, |
|
| 62 | + 'K' => 2, |
|
| 63 | + 'L' => 4, |
|
| 64 | + 'M' => 18, |
|
| 65 | + 'N' => 20, |
|
| 66 | + 'O' => 11, |
|
| 67 | + 'P' => 3, |
|
| 68 | + 'Q' => 6, |
|
| 69 | + 'R' => 8, |
|
| 70 | + 'S' => 12, |
|
| 71 | + 'T' => 14, |
|
| 72 | + 'U' => 16, |
|
| 73 | + 'V' => 10, |
|
| 74 | + 'W' => 22, |
|
| 75 | + 'X' => 25, |
|
| 76 | + 'Y' => 24, |
|
| 77 | + 'Z' => 23 |
|
| 78 | + ); |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Array of all avaialable even characters. |
| 82 | 82 | */ |
| 83 | - private $even = array( |
|
| 84 | - '0' => 0, |
|
| 85 | - '1' => 1, |
|
| 86 | - '2' => 2, |
|
| 87 | - '3' => 3, |
|
| 88 | - '4' => 4, |
|
| 89 | - '5' => 5, |
|
| 90 | - '6' => 6, |
|
| 91 | - '7' => 7, |
|
| 92 | - '8' => 8, |
|
| 93 | - '9' => 9, |
|
| 94 | - 'A' => 0, |
|
| 95 | - 'B' => 1, |
|
| 96 | - 'C' => 2, |
|
| 97 | - 'D' => 3, |
|
| 98 | - 'E' => 4, |
|
| 99 | - 'F' => 5, |
|
| 100 | - 'G' => 6, |
|
| 101 | - 'H' => 7, |
|
| 102 | - 'I' => 8, |
|
| 103 | - 'J' => 9, |
|
| 104 | - 'K' => 10, |
|
| 105 | - 'L' => 11, |
|
| 106 | - 'M' => 12, |
|
| 107 | - 'N' => 13, |
|
| 108 | - 'O' => 14, |
|
| 109 | - 'P' => 15, |
|
| 110 | - 'Q' => 16, |
|
| 111 | - 'R' => 17, |
|
| 112 | - 'S' => 18, |
|
| 113 | - 'T' => 19, |
|
| 114 | - 'U' => 20, |
|
| 115 | - 'V' => 21, |
|
| 116 | - 'W' => 22, |
|
| 117 | - 'X' => 23, |
|
| 118 | - 'Y' => 24, |
|
| 119 | - 'Z' => 25 |
|
| 120 | - ); |
|
| 83 | + private $even = array( |
|
| 84 | + '0' => 0, |
|
| 85 | + '1' => 1, |
|
| 86 | + '2' => 2, |
|
| 87 | + '3' => 3, |
|
| 88 | + '4' => 4, |
|
| 89 | + '5' => 5, |
|
| 90 | + '6' => 6, |
|
| 91 | + '7' => 7, |
|
| 92 | + '8' => 8, |
|
| 93 | + '9' => 9, |
|
| 94 | + 'A' => 0, |
|
| 95 | + 'B' => 1, |
|
| 96 | + 'C' => 2, |
|
| 97 | + 'D' => 3, |
|
| 98 | + 'E' => 4, |
|
| 99 | + 'F' => 5, |
|
| 100 | + 'G' => 6, |
|
| 101 | + 'H' => 7, |
|
| 102 | + 'I' => 8, |
|
| 103 | + 'J' => 9, |
|
| 104 | + 'K' => 10, |
|
| 105 | + 'L' => 11, |
|
| 106 | + 'M' => 12, |
|
| 107 | + 'N' => 13, |
|
| 108 | + 'O' => 14, |
|
| 109 | + 'P' => 15, |
|
| 110 | + 'Q' => 16, |
|
| 111 | + 'R' => 17, |
|
| 112 | + 'S' => 18, |
|
| 113 | + 'T' => 19, |
|
| 114 | + 'U' => 20, |
|
| 115 | + 'V' => 21, |
|
| 116 | + 'W' => 22, |
|
| 117 | + 'X' => 23, |
|
| 118 | + 'Y' => 24, |
|
| 119 | + 'Z' => 25 |
|
| 120 | + ); |
|
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * Array of all avaialable omocodia characters. |
| 124 | 124 | */ |
| 125 | - private $omocodiaCodes = array( |
|
| 126 | - '0' => 'L', |
|
| 127 | - '1' => 'M', |
|
| 125 | + private $omocodiaCodes = array( |
|
| 126 | + '0' => 'L', |
|
| 127 | + '1' => 'M', |
|
| 128 | 128 | '2' => 'N', |
| 129 | 129 | '3' => 'P', |
| 130 | 130 | '4' => 'Q', |
@@ -133,20 +133,20 @@ discard block |
||
| 133 | 133 | '7' => 'T', |
| 134 | 134 | '8' => 'U', |
| 135 | 135 | '9' => 'V' |
| 136 | - ); |
|
| 136 | + ); |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Create a Codice Fiscale instance. |
|
| 140 | - * @param Subject $subject The subject that will have the codice fiscale. |
|
| 138 | + /** |
|
| 139 | + * Create a Codice Fiscale instance. |
|
| 140 | + * @param Subject $subject The subject that will have the codice fiscale. |
|
| 141 | 141 | * @param $properties An array with additional properties. |
| 142 | - */ |
|
| 143 | - public function __construct(Subject $subject, $properties = array()){ |
|
| 142 | + */ |
|
| 143 | + public function __construct(Subject $subject, $properties = array()){ |
|
| 144 | 144 | $this->subject = $subject; |
| 145 | 145 | |
| 146 | 146 | if (array_key_exists('omocodiaLevel', $properties)) { |
| 147 | 147 | $this->omocodiaLevel = $properties['omocodiaLevel']; |
| 148 | 148 | } |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | 152 | * Calculate the code fiscale. |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function calculate(){ |
| 156 | 156 | $temporaryCodiceFiscale = $this->calculateSurname() . $this->calculateName() . |
| 157 | - $this->calculateBirthDateAndGender() . $this->calculateBelfioreCode(); |
|
| 157 | + $this->calculateBirthDateAndGender() . $this->calculateBelfioreCode(); |
|
| 158 | 158 | $temporaryCodiceFiscale = $this->calculateOmocodia($temporaryCodiceFiscale); |
| 159 | 159 | return $temporaryCodiceFiscale . $this->calculateCheckDigit($temporaryCodiceFiscale); |
| 160 | 160 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $result = substr($consonants, 0, 3); |
| 184 | 184 | } else { |
| 185 | 185 | $vowels = str_replace(str_split($consonants), '', $this->subject->getSurname()); |
| 186 | - $result = substr($consonants . $vowels . 'XXX', 0, 3); |
|
| 186 | + $result = substr($consonants . $vowels . 'XXX', 0, 3); |
|
| 187 | 187 | } |
| 188 | 188 | return $result; |
| 189 | 189 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | $result = join($consonants); |
| 201 | 201 | } else{ |
| 202 | 202 | $vowels = str_replace(str_split($consonants), '', $this->subject->getName()); |
| 203 | - $result = substr($consonants . $vowels . 'XXX', 0, 3); |
|
| 203 | + $result = substr($consonants . $vowels . 'XXX', 0, 3); |
|
| 204 | 204 | } |
| 205 | 205 | return $result; |
| 206 | 206 | } |
@@ -234,20 +234,20 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | private function calculateCheckDigit($temporaryCodiceFiscale){ |
| 236 | 236 | $sumEven = 0; |
| 237 | - $sumOdd = 0; |
|
| 238 | - for ($i = 0; $i < 15; $i = $i + 2) |
|
| 239 | - { |
|
| 240 | - $k = $temporaryCodiceFiscale{$i}; |
|
| 241 | - $sumOdd = $sumOdd + $this->odd[$k]; |
|
| 242 | - } |
|
| 237 | + $sumOdd = 0; |
|
| 238 | + for ($i = 0; $i < 15; $i = $i + 2) |
|
| 239 | + { |
|
| 240 | + $k = $temporaryCodiceFiscale{$i}; |
|
| 241 | + $sumOdd = $sumOdd + $this->odd[$k]; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - for ($i = 1; $i < 15; $i = $i + 2) |
|
| 245 | - { |
|
| 246 | - $k = $temporaryCodiceFiscale{$i}; |
|
| 247 | - $sumEven = $sumEven + $this->even[$k]; |
|
| 248 | - } |
|
| 244 | + for ($i = 1; $i < 15; $i = $i + 2) |
|
| 245 | + { |
|
| 246 | + $k = $temporaryCodiceFiscale{$i}; |
|
| 247 | + $sumEven = $sumEven + $this->even[$k]; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return chr(($sumOdd + $sumEven) % 26 + 65); |
|
| 250 | + return chr(($sumOdd + $sumEven) % 26 + 65); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -18,13 +18,13 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | const ALL_OMOCODIA_LEVELS = -1; |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Create a Codice Fiscale instance. |
|
| 23 | - * @param Subject $subject The subject. |
|
| 21 | + /** |
|
| 22 | + * Create a Codice Fiscale instance. |
|
| 23 | + * @param Subject $subject The subject. |
|
| 24 | 24 | * @param $properties Array of additional properties. |
| 25 | - */ |
|
| 26 | - public function __construct(Subject $subject, $properties = array()){ |
|
| 27 | - $this->subject = $subject; |
|
| 25 | + */ |
|
| 26 | + public function __construct(Subject $subject, $properties = array()){ |
|
| 27 | + $this->subject = $subject; |
|
| 28 | 28 | |
| 29 | 29 | if (array_key_exists('codiceFiscaleToCheck', $properties)) { |
| 30 | 30 | $this->codiceFiscaleToCheck = $properties['codiceFiscaleToCheck']; |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | if (array_key_exists('omocodiaLevel', $properties)) { |
| 34 | 34 | $this->omocodiaLevel = $properties['omocodiaLevel']; |
| 35 | 35 | } |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Check if the given data is ok for the given codice fiscale. |
@@ -15,18 +15,18 @@ discard block |
||
| 15 | 15 | private $gender; |
| 16 | 16 | private $belfioreCode; |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Create a Codice Fiscale instance. |
|
| 20 | - * @param array $properties An array with all the properties. |
|
| 21 | - * Supported keys are: |
|
| 22 | - * - name: the name; |
|
| 23 | - * - surname: the surname; |
|
| 18 | + /** |
|
| 19 | + * Create a Codice Fiscale instance. |
|
| 20 | + * @param array $properties An array with all the properties. |
|
| 21 | + * Supported keys are: |
|
| 22 | + * - name: the name; |
|
| 23 | + * - surname: the surname; |
|
| 24 | 24 | * - birthDate: the birth date; |
| 25 | 25 | * - gender: the gender; |
| 26 | 26 | * - belfioreCode: the Belfiore code. |
| 27 | - */ |
|
| 28 | - public function __construct($properties){ |
|
| 29 | - //Set properties |
|
| 27 | + */ |
|
| 28 | + public function __construct($properties){ |
|
| 29 | + //Set properties |
|
| 30 | 30 | if (array_key_exists('name', $properties)) { |
| 31 | 31 | $this->name = strtoupper($properties['name']); |
| 32 | 32 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | if (array_key_exists('belfioreCode', $properties)) { |
| 50 | 50 | $this->belfioreCode = $properties['belfioreCode']; |
| 51 | 51 | } |
| 52 | - } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Get the name. |