Year   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A equals() 0 4 2
A __construct() 0 16 5
1
<?php
2
/**
3
 * Copyright 2016 Alexandru Guzinschi <[email protected]>.
4
 *
5
 * This software may be modified and distributed under the terms
6
 * of the MIT license. See the LICENSE file for details.
7
 */
8
namespace Gentle\Embeddable\Date;
9
10
use Gentle\Embeddable\Embeddable;
11
12
/**
13
 * @author Alexandru Guzinschi <[email protected]>
14
 */
15
final class Year extends Embeddable
16
{
17
    /**
18
     * @param string|int $year
19
     *
20
     * @throws \InvalidArgumentException
21
     * @throws \LengthException If received value is not a full numeric representation of a year.
22
     */
23 53
    public function __construct($year)
24
    {
25 53
        if (is_int($year)) {
26 17
            $year = (string)$year;
27
        }
28
29 53
        if (!is_string($year) || !ctype_digit($year)) {
30 9
            throw new \InvalidArgumentException(sprintf('Expected string or integer and got %s', gettype($year)));
31
        }
32
33 44
        if (4 !== mb_strlen($year)) {
34 6
            throw new \LengthException('Expected a full numeric representation of a year.');
35
        }
36
37 38
        $this->value = $year;
38 38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 6
    public function equals(Embeddable $object)
44
    {
45 6
        return get_class($object) === 'Gentle\Embeddable\Date\Year' && $this->value === (string)$object;
46
    }
47
}
48