Completed
Push — master ( 59c50d...1e8f66 )
by Davide
02:13
created
src/DavidePastore/CodiceFiscale/Calculator.php 1 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.