Year   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 2
dl 0
loc 54
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isLeap() 0 4 2
A now() 0 4 1
A fromString() 0 4 1
A fromNative() 0 4 1
1
<?php
2
3
namespace BestServedCold\PhalueObjects\DateTime\Unit;
4
5
use BestServedCold\PhalueObjects\Contract\DateTime as DateTimeInterface;
6
use BestServedCold\PhalueObjects\DateTime\DateTimeTrait;
7
use BestServedCold\PhalueObjects\Mathematical\Integer;
8
9
/**
10
 * Class Year
11
 *
12
 * @package   BestServedCold\PhalueObjects\DateTime\Unit
13
 * @author    Adam Lewis <[email protected]>
14
 * @copyright Copyright (c) 2015 Best Served Cold Media Limited
15
 * @license   http://http://opensource.org/licenses/GPL-3.0 GPL License
16
 * @link      http://bestservedcold.com
17
 * @since     0.0.1-alpha
18
 * @version   0.0.2-alpha
19
 */
20
final class Year extends Integer implements DateTimeInterface
21
{
22
    use DateTimeTrait;
23
24
    /**
25
     * @param int $value
26
     */
27 28
    public function __construct($value)
28
    {
29 28
        parent::__construct($value);
30 28
        $this->native = new \DateTime("$value-01-01");
31 28
    }
32
33
    /***
34
     * @return bool
35
     */
36 2
    public function isLeap()
37
    {
38 2
        return $this->native->format('L') === '1' ? true : false;
39
    }
40
41
    /**
42
     * Now.
43
     *
44
     * @return static
45
     */
46 11
    public static function now()
47
    {
48 11
        return new static(self::getNowDateTimeFormat('Y'));
49
    }
50
51
    /**
52
     * From String.
53
     *
54
     * @param  $string
55
     *
56
     * @return static
57
     */
58 1
    public static function fromString($string)
59
    {
60 1
        return new static((int) $string);
61
    }
62
63
    /**
64
     * From Native
65
     *
66
     * @param \DateTime $native
67
     * @return DateTimeInterface
68
     */
69 1
    public static function fromNative(\DateTime $native)
70
    {
71 1
        return new static((int) $native->format('Y'));
72
    }
73
}
74