Completed
Pull Request — master (#12)
by Antonio
02:17
created

InverseCalculator::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
crap 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 15
    public function __construct($codiceFiscale, $properties = array())
21
    {
22 15
        parent::__construct($codiceFiscale, $properties);
23
        
24 15
        if ($this->isFormallyValid()) {
25 15
            $codiceFiscaleWithoutOmocodia = $this->getCodiceFiscaleWithoutOmocodia();
26
            
27
            // calculate belfiore code
28 15
            $this->belfioreCode = substr($codiceFiscaleWithoutOmocodia, 11, 4);
29 15
        }
30 15
    }
31
32
    /**
33
     * Return the belfiore code
34
     *
35
     * @return string
36
     */
37 15
    public function getBelfioreCode()
38
    {
39 15
        return $this->belfioreCode;
40
    }
41
42
    /**
43
     * Return the Subject calculated from codice fiscale
44
     *
45
     * @return \CodiceFiscale\Subject
46
     */
47 15
    public function getSubject()
48
    {
49 15
        return new Subject(array(
50 15
            "gender" => $this->getGender(),
51 15
            "birthDate" => $this->getBirthDate(),
52 15
            "belfioreCode" => $this->getBelfioreCode()
53 15
                ));
54
    }
55
}
56