Completed
Push — master ( 59c50d...1e8f66 )
by Davide
02:13
created
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.
src/DavidePastore/CodiceFiscale/Calculator.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -40,92 +40,92 @@  discard block
 block discarded – undo
40 40
      * Array of all avaialable odd characters.
41 41
      */
42 42
     private $odd = array(
43
-		'0' => 1, 
44
-		'1' => 0, 
45
-		'2' => 5, 
46
-		'3' => 7, 
47
-		'4' => 9, 
48
-		'5' => 13, 
49
-		'6' => 15, 
50
-		'7' => 17, 
51
-		'8' => 19, 
52
-		'9' => 21, 
53
-		'A' => 1,
54
-		'B' => 0,
55
-		'C' => 5,
56
-		'D' => 7,
57
-		'E' => 9,
58
-		'F' => 13,
59
-		'G' => 15,
60
-		'H' => 17,
61
-		'I' => 19,
62
-		'J' => 21,
63
-		'K' => 2,
64
-		'L' => 4,
65
-		'M' => 18,
66
-		'N' => 20,
67
-		'O' => 11,
68
-		'P' => 3,
69
-		'Q' => 6,
70
-		'R' => 8,
71
-		'S' => 12,
72
-		'T' => 14,
73
-		'U' => 16,
74
-		'V' => 10,
75
-		'W' => 22,
76
-		'X' => 25,
77
-		'Y' => 24,
78
-		'Z' => 23
79
-	);
43
+        '0' => 1, 
44
+        '1' => 0, 
45
+        '2' => 5, 
46
+        '3' => 7, 
47
+        '4' => 9, 
48
+        '5' => 13, 
49
+        '6' => 15, 
50
+        '7' => 17, 
51
+        '8' => 19, 
52
+        '9' => 21, 
53
+        'A' => 1,
54
+        'B' => 0,
55
+        'C' => 5,
56
+        'D' => 7,
57
+        'E' => 9,
58
+        'F' => 13,
59
+        'G' => 15,
60
+        'H' => 17,
61
+        'I' => 19,
62
+        'J' => 21,
63
+        'K' => 2,
64
+        'L' => 4,
65
+        'M' => 18,
66
+        'N' => 20,
67
+        'O' => 11,
68
+        'P' => 3,
69
+        'Q' => 6,
70
+        'R' => 8,
71
+        'S' => 12,
72
+        'T' => 14,
73
+        'U' => 16,
74
+        'V' => 10,
75
+        'W' => 22,
76
+        'X' => 25,
77
+        'Y' => 24,
78
+        'Z' => 23
79
+    );
80 80
 	
81 81
     /**
82 82
      * Array of all avaialable even characters.
83 83
      */
84
-	private $even = array(
85
-		'0' => 0, 
86
-		'1' => 1, 
87
-		'2' => 2, 
88
-		'3' => 3, 
89
-		'4' => 4, 
90
-		'5' => 5, 
91
-		'6' => 6, 
92
-		'7' => 7, 
93
-		'8' => 8, 
94
-		'9' => 9, 
95
-		'A' => 0,
96
-		'B' => 1,
97
-		'C' => 2,
98
-		'D' => 3,
99
-		'E' => 4,
100
-		'F' => 5,
101
-		'G' => 6,
102
-		'H' => 7,
103
-		'I' => 8,
104
-		'J' => 9,
105
-		'K' => 10,
106
-		'L' => 11,
107
-		'M' => 12,
108
-		'N' => 13,
109
-		'O' => 14,
110
-		'P' => 15,
111
-		'Q' => 16,
112
-		'R' => 17,
113
-		'S' => 18,
114
-		'T' => 19,
115
-		'U' => 20,
116
-		'V' => 21,
117
-		'W' => 22,
118
-		'X' => 23,
119
-		'Y' => 24,
120
-		'Z' => 25
121
-	);
84
+    private $even = array(
85
+        '0' => 0, 
86
+        '1' => 1, 
87
+        '2' => 2, 
88
+        '3' => 3, 
89
+        '4' => 4, 
90
+        '5' => 5, 
91
+        '6' => 6, 
92
+        '7' => 7, 
93
+        '8' => 8, 
94
+        '9' => 9, 
95
+        'A' => 0,
96
+        'B' => 1,
97
+        'C' => 2,
98
+        'D' => 3,
99
+        'E' => 4,
100
+        'F' => 5,
101
+        'G' => 6,
102
+        'H' => 7,
103
+        'I' => 8,
104
+        'J' => 9,
105
+        'K' => 10,
106
+        'L' => 11,
107
+        'M' => 12,
108
+        'N' => 13,
109
+        'O' => 14,
110
+        'P' => 15,
111
+        'Q' => 16,
112
+        'R' => 17,
113
+        'S' => 18,
114
+        'T' => 19,
115
+        'U' => 20,
116
+        'V' => 21,
117
+        'W' => 22,
118
+        'X' => 23,
119
+        'Y' => 24,
120
+        'Z' => 25
121
+    );
122 122
     
123 123
     /**
124 124
      * Array of all avaialable omocodia characters.
125 125
      */
126
-	private $omocodiaCodes = array(
127
-		'0' => 'L',
128
-		'1' => 'M',
126
+    private $omocodiaCodes = array(
127
+        '0' => 'L',
128
+        '1' => 'M',
129 129
         '2' => 'N',
130 130
         '3' => 'P',
131 131
         '4' => 'Q',
@@ -134,20 +134,20 @@  discard block
 block discarded – undo
134 134
         '7' => 'T',
135 135
         '8' => 'U',
136 136
         '9' => 'V'
137
-	);
137
+    );
138 138
 	
139
-	/**
140
-	 * Create a Codice Fiscale instance.
141
-	 * @param Subject $subject The subject that will have the codice fiscale.
139
+    /**
140
+     * Create a Codice Fiscale instance.
141
+     * @param Subject $subject The subject that will have the codice fiscale.
142 142
      * @param $properties An array with additional properties.
143
-	 */
144
-	public function __construct(Subject $subject, $properties = array()){
143
+     */
144
+    public function __construct(Subject $subject, $properties = array()){
145 145
         $this->subject = $subject;
146 146
         
147 147
         if (array_key_exists('omocodiaLevel', $properties)) {
148 148
             $this->omocodiaLevel = $properties['omocodiaLevel'];
149 149
         }
150
-	}
150
+    }
151 151
     
152 152
     /**
153 153
      * Calculate the code fiscale.
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function calculate(){
157 157
         $temporaryCodiceFiscale = $this->calculateSurname() . $this->calculateName() .
158
-               $this->calculateBirthDateAndGender() . $this->calculateBelfioreCode();
158
+                $this->calculateBirthDateAndGender() . $this->calculateBelfioreCode();
159 159
         $temporaryCodiceFiscale = $this->calculateOmocodia($temporaryCodiceFiscale);
160 160
         return $temporaryCodiceFiscale . $this->calculateCheckDigit($temporaryCodiceFiscale);
161 161
     }
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             $result = substr($consonants, 0, 3);
185 185
         } else {
186 186
             $vowels = str_replace(str_split($consonants), '', $this->subject->getSurname());
187
-			$result = substr($consonants . $vowels . 'XXX', 0, 3);
187
+            $result = substr($consonants . $vowels . 'XXX', 0, 3);
188 188
         }
189 189
         return $result;
190 190
     }
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
             $result = join($consonants);
202 202
         } else{
203 203
             $vowels = str_replace(str_split($consonants), '', $this->subject->getName());
204
-			$result = substr($consonants . $vowels . 'XXX', 0, 3);
204
+            $result = substr($consonants . $vowels . 'XXX', 0, 3);
205 205
         }
206 206
         return $result;
207 207
     }
@@ -250,10 +250,10 @@  discard block
 block discarded – undo
250 250
     private function calculateSumByDictionary($temporaryCodiceFiscale, $dictionaryArray, $i){
251 251
         $sum = 0;
252 252
         for (; $i < 15; $i = $i + 2)
253
-		{
254
-			$k = $temporaryCodiceFiscale{$i};
255
-			$sum = $sum + $dictionaryArray[$k];
256
-		}
253
+        {
254
+            $k = $temporaryCodiceFiscale{$i};
255
+            $sum = $sum + $dictionaryArray[$k];
256
+        }
257 257
         return $sum;
258 258
     }
259 259
     
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * @param Subject $subject The subject that will have the codice fiscale.
142 142
      * @param $properties An array with additional properties.
143 143
 	 */
144
-	public function __construct(Subject $subject, $properties = array()){
144
+	public function __construct(Subject $subject, $properties = array()) {
145 145
         $this->subject = $subject;
146 146
         
147 147
         if (array_key_exists('omocodiaLevel', $properties)) {
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      * Calculate the code fiscale.
154 154
      * @returns Returns the complete codice fiscale.
155 155
      */
156
-    public function calculate(){
156
+    public function calculate() {
157 157
         $temporaryCodiceFiscale = $this->calculateSurname() . $this->calculateName() .
158 158
                $this->calculateBirthDateAndGender() . $this->calculateBelfioreCode();
159 159
         $temporaryCodiceFiscale = $this->calculateOmocodia($temporaryCodiceFiscale);
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
      * Calculate all possibilities for the code fiscale.
165 165
      * @returns Returns the complete codice fiscale.
166 166
      */
167
-    public function calculateAllPossibilities(){
167
+    public function calculateAllPossibilities() {
168 168
         $allPossibilities = array();
169
-        for($i = 0; $i < 8; $i++){
169
+        for ($i = 0; $i < 8; $i++) {
170 170
             $this->omocodiaLevel = $i;
171 171
             $allPossibilities[] = $this->calculate();
172 172
         }
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
      * Calculate the surname part of the codice fiscale.
179 179
      * @returns Returns the surname part of the codice fiscale.
180 180
      */
181
-    private function calculateSurname(){
181
+    private function calculateSurname() {
182 182
         $consonants = str_replace($this->vowels, '', $this->subject->getSurname());
183
-        if(strlen($consonants) > 2){
183
+        if (strlen($consonants) > 2) {
184 184
             $result = substr($consonants, 0, 3);
185 185
         } else {
186 186
             $vowels = str_replace(str_split($consonants), '', $this->subject->getSurname());
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
      * Calculate the name part of the codice fiscale.
194 194
      * @returns Returns the name part of the codice fiscale.
195 195
      */
196
-    private function calculateName(){
196
+    private function calculateName() {
197 197
         $consonants = str_replace($this->vowels, '', $this->subject->getName());
198
-        if(strlen($consonants) > 3){
198
+        if (strlen($consonants) > 3) {
199 199
             $result = $consonants[0] . $consonants[2] . $consonants[3];
200
-        } else if(strlen($consonants) == 3){
200
+        } else if (strlen($consonants) == 3) {
201 201
             $result = join($consonants);
202
-        } else{
202
+        } else {
203 203
             $vowels = str_replace(str_split($consonants), '', $this->subject->getName());
204 204
 			$result = substr($consonants . $vowels . 'XXX', 0, 3);
205 205
         }
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
      * Calculate the birth date and the gender.
211 211
      * @returns Returns the birth date and gender part of the codice fiscale.
212 212
      */
213
-    private function calculateBirthDateAndGender(){
213
+    private function calculateBirthDateAndGender() {
214 214
         $year = $this->subject->getBirthDate()->format('y');
215 215
         $month = $this->months[$this->subject->getBirthDate()->format('n')];
216 216
         $day = $this->subject->getBirthDate()->format('d');
217
-        if($this->subject->getGender() == "F"){
217
+        if ($this->subject->getGender() == "F") {
218 218
             $day += 40;
219 219
         }
220 220
         return $year . $month . $day;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      * Calculate the Belfiore code.
225 225
      * @returns Returns the Belfiore code.
226 226
      */
227
-    private function calculateBelfioreCode(){
227
+    private function calculateBelfioreCode() {
228 228
         return $this->subject->getBelfioreCode();
229 229
     }
230 230
     
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
      * @param $temporaryCodiceFiscale The first part of the codice fiscale.
234 234
      * @returns Returns the check digit part of the codice fiscale.
235 235
      */
236
-    private function calculateCheckDigit($temporaryCodiceFiscale){
236
+    private function calculateCheckDigit($temporaryCodiceFiscale) {
237 237
         $sumEven = $this->calculateSumByDictionary($temporaryCodiceFiscale, $this->even, 1);
238 238
         $sumOdd = $this->calculateSumByDictionary($temporaryCodiceFiscale, $this->odd, 0);
239 239
         return chr(($sumOdd + $sumEven) % 26 + 65);
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      * @returns Returns the sum by the given dictionary for the given temporary codice fiscale.
248 248
      *
249 249
      */
250
-    private function calculateSumByDictionary($temporaryCodiceFiscale, $dictionaryArray, $i){
250
+    private function calculateSumByDictionary($temporaryCodiceFiscale, $dictionaryArray, $i) {
251 251
         $sum = 0;
252 252
         for (; $i < 15; $i = $i + 2)
253 253
 		{
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
      * @param $temporaryCodiceFiscale The first part of the codice fiscale.
263 263
      * @returns Returns the new codice fiscale.
264 264
      */
265
-    private function calculateOmocodia($temporaryCodiceFiscale){
266
-        if($this->omocodiaLevel > 0){
265
+    private function calculateOmocodia($temporaryCodiceFiscale) {
266
+        if ($this->omocodiaLevel > 0) {
267 267
             $omocodiaLevelApplied = 0;
268
-            for($i = strlen($temporaryCodiceFiscale) - 1; $i > 0; $i--){
268
+            for ($i = strlen($temporaryCodiceFiscale) - 1; $i > 0; $i--) {
269 269
                 $k = $temporaryCodiceFiscale{$i};
270
-                if($omocodiaLevelApplied < $this->omocodiaLevel && is_numeric($k)){
270
+                if ($omocodiaLevelApplied < $this->omocodiaLevel && is_numeric($k)) {
271 271
                     $newChar = $this->omocodiaCodes[$k];
272 272
                     $temporaryCodiceFiscale{$i} = $newChar;
273 273
                     $omocodiaLevelApplied++;
Please login to merge, or discard this patch.