MonthDay::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
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