Day   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
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 35
ccs 12
cts 12
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 18 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 Day extends Embeddable
16
{
17
    /**
18
     * @param string|int $day
19
     *
20
     * @throws \InvalidArgumentException
21
     * @throws \OutOfRangeException
22
     */
23 55
    public function __construct($day)
24
    {
25 55
        if (is_int($day)) {
26 18
            $day = (string)$day;
27
        }
28
29 55
        if (!is_string($day) || !ctype_digit($day)) {
30 8
            throw new \InvalidArgumentException(sprintf('Expected string or integer and got %s', gettype($day)));
31
        }
32
33 47
        if (!in_array((int)$day, range(1, 31), true)) {
34 8
            throw new \OutOfRangeException(
35 8
                sprintf('Expected a numeric representation of a day in a range of 1 - 31 (%d).', (int)$day)
36
            );
37
        }
38
39 39
        $this->value = str_pad($day, 2, 0, STR_PAD_LEFT);
40 39
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 8
    public function equals(Embeddable $object)
46
    {
47 8
        return get_class($object) === 'Gentle\Embeddable\Date\Day' && $this->value === (string)$object;
48
    }
49
}
50