Completed
Push — master ( ec0306...353f5c )
by Davide
8s
created

Checker::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 6
nc 4
nop 2
crap 3
1
<?php
2
3
namespace CodiceFiscale;
4
5
/**
6
 * Codice Fiscale checker.
7
 *
8
 * @author davidepastore
9
 */
10
class Checker
11
{
12
    private $subject;
13
    private $omocodiaLevel = self::ALL_OMOCODIA_LEVELS;
14
    private $codiceFiscaleToCheck;
15
16
    /**
17
     * Constant to check for all the omocodia levels.
18
     */
19
    const ALL_OMOCODIA_LEVELS = -1;
20
21
    /**
22
     * Create a Codice Fiscale instance.
23
     *
24
     * @param Subject $subject The subject.
25
     * @param $properties Array of additional properties.
26
     */
27 3
    public function __construct(Subject $subject, $properties = array())
28
    {
29 3
        $this->subject = $subject;
30
31 3
        if (array_key_exists('codiceFiscaleToCheck', $properties)) {
32 3
            $this->codiceFiscaleToCheck = $properties['codiceFiscaleToCheck'];
33 3
        }
34
35 3
        if (array_key_exists('omocodiaLevel', $properties)) {
36 3
            $this->omocodiaLevel = $properties['omocodiaLevel'];
37 3
        }
38 3
    }
39
40
    /**
41
     * Check if the given data is ok for the given codice fiscale.
42
     *
43
     * @returns Returns true if the codice fiscale is ok, false otherwise.
44
     */
45 3
    public function check()
46
    {
47 3
        $calculator = new Calculator($this->subject, array(
48 3
            'omocodiaLevel' => $this->omocodiaLevel,
49 3
        ));
50 3
        if ($this->omocodiaLevel == self::ALL_OMOCODIA_LEVELS) {
51 1
            $values = $calculator->calculateAllPossibilities();
52 1
        } else {
53 2
            $values = array($calculator->calculate());
54
        }
55
56 3
        return in_array($this->codiceFiscaleToCheck, $values);
57
    }
58
}
59