Vatin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 48
c 0
b 0
f 0
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getValidator() 0 7 2
A __toString() 0 4 1
1
<?php
2
3
namespace Eventjet\Vatin;
4
5
use Ddeboer\Vatin\Validator;
6
use Eventjet\Vatin\Exception\InvalidVatinFormatException;
7
8
class Vatin implements VatinInterface
9
{
10
    /** @var Validator */
11
    private static $validator;
12
    /** @var string */
13
    private $vatin;
14
15
    /**
16
     * Vatin constructor.
17
     *
18
     * Checks if the VAT identification number is correctly formatted. If it isn\'t, an exception is thrown.
19
     *
20
     * The constructor does NOT check if the VAT IN exists. It only checks the format. If you also want to check for the
21
     * existence, use the Eventjet\Vatin\VatinFactory instead.
22
     *
23
     * @param string $vatin
24
     * @throws InvalidVatinFormatException If the format is invalid
25
     */
26 8
    public function __construct($vatin)
27
    {
28 8
        if (!self::getValidator()->isValid($vatin, false)) {
29 5
            throw new InvalidVatinFormatException(sprintf(
30 5
                '"%s" is not a valid VAT identification number.',
31
                $vatin
32 5
            ));
33
        }
34 3
        $this->vatin = $vatin;
35 3
    }
36
37
    /**
38
     * @return Validator
39
     */
40 8
    private static function getValidator()
41
    {
42 8
        if (self::$validator === null) {
43 1
            self::$validator = new Validator;
44 1
        }
45 8
        return self::$validator;
46
    }
47
48
    /**
49
     * @return string
50
     */
51 3
    public function __toString()
52
    {
53 3
        return $this->vatin;
54
    }
55
}
56