Completed
Branch master (5ced4e)
by Davide
02:05
created
src/DavidePastore/CodiceFiscale/Calculator.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -39,92 +39,92 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 * @param Subject $subject The subject that will have the codice fiscale.
141 141
      * @param $properties An array with additional properties.
142 142
 	 */
143
-	public function __construct(Subject $subject, $properties = array()){
143
+	public function __construct(Subject $subject, $properties = array()) {
144 144
         $this->subject = $subject;
145 145
         
146 146
         if (array_key_exists('omocodiaLevel', $properties)) {
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      * Calculate the code fiscale.
153 153
      * @returns Returns the complete codice fiscale.
154 154
      */
155
-    public function calculate(){
155
+    public function calculate() {
156 156
         $temporaryCodiceFiscale = $this->calculateSurname() . $this->calculateName() .
157 157
                $this->calculateBirthDateAndGender() . $this->calculateBelfioreCode();
158 158
         $temporaryCodiceFiscale = $this->calculateOmocodia($temporaryCodiceFiscale);
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
      * Calculate all possibilities for the code fiscale.
164 164
      * @returns Returns the complete codice fiscale.
165 165
      */
166
-    public function calculateAllPossibilities(){
166
+    public function calculateAllPossibilities() {
167 167
         $allPossibilities = array();
168
-        for($i = 0; $i < 8; $i++){
168
+        for ($i = 0; $i < 8; $i++) {
169 169
             $this->omocodiaLevel = $i;
170 170
             $allPossibilities[] = $this->calculate();
171 171
         }
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
      * Calculate the surname part of the codice fiscale.
178 178
      * @returns Returns the surname part of the codice fiscale.
179 179
      */
180
-    private function calculateSurname(){
180
+    private function calculateSurname() {
181 181
         $consonants = str_replace($this->vowels, '', $this->subject->getSurname());
182
-        if(strlen($consonants) > 2){
182
+        if (strlen($consonants) > 2) {
183 183
             $result = substr($consonants, 0, 3);
184 184
         } else {
185 185
             $vowels = str_replace(str_split($consonants), '', $this->subject->getSurname());
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
      * Calculate the name part of the codice fiscale.
193 193
      * @returns Returns the name part of the codice fiscale.
194 194
      */
195
-    private function calculateName(){
195
+    private function calculateName() {
196 196
         $consonants = str_replace($this->vowels, '', $this->subject->getName());
197
-        if(strlen($consonants) > 3){
197
+        if (strlen($consonants) > 3) {
198 198
             $result = $consonants[0] . $consonants[2] . $consonants[3];
199
-        } else if(strlen($consonants) == 3){
199
+        } else if (strlen($consonants) == 3) {
200 200
             $result = join($consonants);
201
-        } else{
201
+        } else {
202 202
             $vowels = str_replace(str_split($consonants), '', $this->subject->getName());
203 203
 			$result = substr($consonants . $vowels . 'XXX', 0, 3);
204 204
         }
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
      * Calculate the birth date and the gender.
210 210
      * @returns Returns the birth date and gender part of the codice fiscale.
211 211
      */
212
-    private function calculateBirthDateAndGender(){
212
+    private function calculateBirthDateAndGender() {
213 213
         $year = $this->subject->getBirthDate()->format('y');
214 214
         $month = $this->months[$this->subject->getBirthDate()->format('n')];
215 215
         $day = $this->subject->getBirthDate()->format('d');
216
-        if($this->subject->getGender() == "F"){
216
+        if ($this->subject->getGender() == "F") {
217 217
             $day += 40;
218 218
         }
219 219
         return $year . $month . $day;
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * Calculate the Belfiore code.
224 224
      * @returns Returns the Belfiore code.
225 225
      */
226
-    private function calculateBelfioreCode(){
226
+    private function calculateBelfioreCode() {
227 227
         return $this->subject->getBelfioreCode();
228 228
     }
229 229
     
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
      * @param $temporaryCodiceFiscale The first part of the codice fiscale.
233 233
      * @returns Returns the check digit part of the codice fiscale.
234 234
      */
235
-    private function calculateCheckDigit($temporaryCodiceFiscale){
235
+    private function calculateCheckDigit($temporaryCodiceFiscale) {
236 236
         $sumEven = 0;
237 237
 		$sumOdd = 0;
238 238
 		for ($i = 0; $i < 15; $i = $i + 2)
@@ -255,12 +255,12 @@  discard block
 block discarded – undo
255 255
      * @param $temporaryCodiceFiscale The first part of the codice fiscale.
256 256
      * @returns Returns the new codice fiscale.
257 257
      */
258
-    private function calculateOmocodia($temporaryCodiceFiscale){
259
-        if($this->omocodiaLevel > 0){
258
+    private function calculateOmocodia($temporaryCodiceFiscale) {
259
+        if ($this->omocodiaLevel > 0) {
260 260
             $omocodiaLevelApplied = 0;
261
-            for($i = strlen($temporaryCodiceFiscale) - 1; $i > 0; $i--){
261
+            for ($i = strlen($temporaryCodiceFiscale) - 1; $i > 0; $i--) {
262 262
                 $k = $temporaryCodiceFiscale{$i};
263
-                if($omocodiaLevelApplied < $this->omocodiaLevel && is_numeric($k)){
263
+                if ($omocodiaLevelApplied < $this->omocodiaLevel && is_numeric($k)) {
264 264
                     $newChar = $this->omocodiaCodes[$k];
265 265
                     $temporaryCodiceFiscale{$i} = $newChar;
266 266
                     $omocodiaLevelApplied++;
Please login to merge, or discard this patch.
src/DavidePastore/CodiceFiscale/Checker.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,13 +18,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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.
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * @param Subject $subject The subject.
24 24
      * @param $properties Array of additional properties.
25 25
 	 */
26
-	public function __construct(Subject $subject, $properties = array()){
26
+	public function __construct(Subject $subject, $properties = array()) {
27 27
 		$this->subject = $subject;
28 28
         
29 29
         if (array_key_exists('codiceFiscaleToCheck', $properties)) {
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
      * Check if the given data is ok for the given codice fiscale.
40 40
      * @returns Returns true if the codice fiscale is ok, false otherwise.
41 41
      */
42
-    public function check(){
42
+    public function check() {
43 43
         $calculator = new Calculator($this->subject, array(
44 44
             "omocodiaLevel" => $this->omocodiaLevel
45 45
         ));
46
-        if($this->omocodiaLevel == Checker::ALL_OMOCODIA_LEVELS){
46
+        if ($this->omocodiaLevel == Checker::ALL_OMOCODIA_LEVELS) {
47 47
             $values = $calculator->calculateAllPossibilities();
48 48
         } else {
49 49
             $values = array($calculator->calculate());
Please login to merge, or discard this patch.
src/DavidePastore/CodiceFiscale/Subject.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,18 +15,18 @@  discard block
 block discarded – undo
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
 block discarded – undo
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.
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      * - gender: the gender;
26 26
      * - belfioreCode: the Belfiore code.
27 27
 	 */
28
-	public function __construct($properties){
28
+	public function __construct($properties) {
29 29
 		//Set properties
30 30
         if (array_key_exists('name', $properties)) {
31 31
             $this->name = strtoupper($properties['name']);
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
         }
37 37
         
38 38
         if (array_key_exists('birthDate', $properties)) {
39
-            if(!$properties['birthDate'] instanceof \DateTime){
39
+            if (!$properties['birthDate'] instanceof \DateTime) {
40 40
                 $properties['birthDate'] = new \DateTime($properties['birthDate']);
41 41
             }
42 42
             $this->birthDate = $properties['birthDate'];
@@ -55,14 +55,14 @@  discard block
 block discarded – undo
55 55
      * Get the name.
56 56
      * @return Returns the name.
57 57
      */
58
-    public function getName(){
58
+    public function getName() {
59 59
         return $this->name;
60 60
     }
61 61
     
62 62
     /**
63 63
      * Set the name.
64 64
      */
65
-    public function setName($name){
65
+    public function setName($name) {
66 66
         $this->name = $name;
67 67
     }
68 68
 
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
      * Get the name.
71 71
      * @return Returns the name.
72 72
      */
73
-    public function getSurname(){
73
+    public function getSurname() {
74 74
         return $this->surname;
75 75
     }
76 76
     
77 77
     /**
78 78
      * Set the surname.
79 79
      */
80
-    public function setSurname($surname){
80
+    public function setSurname($surname) {
81 81
         $this->surname = $surname;
82 82
     }
83 83
     
@@ -85,14 +85,14 @@  discard block
 block discarded – undo
85 85
      * Get the birthDate.
86 86
      * @return Returns the birthDate.
87 87
      */
88
-    public function getBirthDate(){
88
+    public function getBirthDate() {
89 89
         return $this->birthDate;
90 90
     }
91 91
     
92 92
     /**
93 93
      * Set the birthDate.
94 94
      */
95
-    public function setBirthDate($birthDate){
95
+    public function setBirthDate($birthDate) {
96 96
         $this->birthDate = $birthDate;
97 97
     }
98 98
     
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
      * Get the gender.
101 101
      * @return Returns the gender.
102 102
      */
103
-    public function getGender(){
103
+    public function getGender() {
104 104
         return $this->gender;
105 105
     }
106 106
     
107 107
     /**
108 108
      * Set the gender.
109 109
      */
110
-    public function setGender($gender){
110
+    public function setGender($gender) {
111 111
         $this->gender = $gender;
112 112
     }
113 113
     
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
      * Get the belfioreCode.
116 116
      * @return Returns the belfioreCode.
117 117
      */
118
-    public function getBelfioreCode(){
118
+    public function getBelfioreCode() {
119 119
         return $this->belfioreCode;
120 120
     }
121 121
     
122 122
     /**
123 123
      * Set the belfioreCode.
124 124
      */
125
-    public function setBelfioreCode($belfioreCode){
125
+    public function setBelfioreCode($belfioreCode) {
126 126
         $this->belfioreCode = $belfioreCode;
127 127
     }
128 128
 }
Please login to merge, or discard this patch.