MonthDay   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A now() 0 7 1
1
<?php
2
3
namespace ValueObjects\DateTime;
4
5
use ValueObjects\Exception\InvalidNativeArgumentException;
6
use ValueObjects\Number\Natural;
7
8
class MonthDay extends Natural
9
{
10
    const MIN_MONTH_DAY = 1;
11
    const MAX_MONTH_DAY = 31;
12
13
    /**
14
     * Returns a new MonthDay
15
     *
16
     * @param int $value
17
     */
18 30
    public function __construct($value)
19
    {
20
        $options = array(
21 30
            'options' => array('min_range' => self::MIN_MONTH_DAY, 'max_range' => self::MAX_MONTH_DAY)
22 30
        );
23
24 30
        $value = filter_var($value, FILTER_VALIDATE_INT, $options);
25
26 30
        if (false === $value) {
27 1
            throw new InvalidNativeArgumentException($value, array('int (>=0, <=31)'));
28
        }
29
30 29
        parent::__construct($value);
31 29
    }
32
33
    /**
34
     * Returns the current month day.
35
     *
36
     * @return MonthDay
37
     */
38 4
    public static function now()
39
    {
40 4
        $now      = new \DateTime('now');
41 4
        $monthDay = \intval($now->format('j'));
42
43 4
        return new static($monthDay);
44
    }
45
}
46