Completed
Pull Request — master (#12)
by Antonio
01:27
created

InverseCalculator::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace CodiceFiscale;
4
5
/**
6
 * Description of InverseCalculator
7
 *
8
 * @author Antonio Turdo <[email protected]>
9
 */
10
class InverseCalculator extends Validator {
11
    
12
    private $belfioreCode = null;
13
    
14
    /**
15
     * Create an InverseCalculator instance.
16
     * 
17
     * @param string $codiceFiscale the codice fiscale to validate
18
     * @param array $properties  An array with additional properties.
19
     */
20
    public function __construct($codiceFiscale, $properties = array()) {
21
        parent::__construct($codiceFiscale, $properties);
22
        
23
        if ($this->isFormallyValid()) {
24
            $codiceFiscaleWithoutOmocodia = $this->getCodiceFiscaleWithoutOmocodia();
25
            
26
            // calculate belfiore code
27
            $this->belfioreCode = substr($codiceFiscaleWithoutOmocodia, 11, 4);
28
        }
29
    }
30
31
    /**
32
     * Return the belfiore code
33
     * 
34
     * @return string
35
     */
36
    public function getBelfioreCode() {
37
        return $this->belfioreCode;
38
    }
39
40
    /**
41
     * Return the Subject calculated from codice fiscale 
42
     * 
43
     * @return \CodiceFiscale\Subject
44
     */
45
    public function getSubject(){
46
        return new Subject(array(
47
            "gender" => $this->getGender(),
48
            "birthDate" => $this->getBirthDate(),
49
            "belfioreCode" => $this->getBelfioreCode()
50
                ));
51
    }   
52
    
53
}
54