Date   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 0
dl 0
loc 100
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDay() 0 4 1
A getMonth() 0 4 1
A setMonth() 0 7 4
A setDay() 0 7 4
A format() 0 10 1
A toString() 0 4 1
A __toString() 0 4 1
A jsonSerialize() 0 4 1
1
<?php
2
/*
3
 * This file is part of the Slince/China package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace China\Holiday;
12
13
class Date implements DateInterface
14
{
15
    /**
16
     * 天.
17
     *
18
     * @var int
19
     */
20
    protected $day;
21
22
    /**
23
     * 月.
24
     *
25
     * @var int
26
     */
27
    protected $month;
28
29
    public function __construct($month, $day)
30
    {
31
        $this->month = $month;
32
        $this->day = $day;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getDay()
39
    {
40
        return $this->day;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getMonth()
47
    {
48
        return $this->month;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function setMonth($month)
55
    {
56
        if (!is_numeric($month) || $month < 1 && $month > 12) {
57
            throw new \InvalidArgumentException(sprintf('Wrong month, given "%s"', $month));
58
        }
59
        $this->month = $month;
0 ignored issues
show
Documentation Bug introduced by
It seems like $month can also be of type double or string. However, the property $month is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function setDay($day)
66
    {
67
        if (!is_numeric($day) || $day < 1 && $day > 31) {
68
            throw new \InvalidArgumentException(sprintf('Wrong day, given "%s"', $day));
69
        }
70
        $this->day = $day;
0 ignored issues
show
Documentation Bug introduced by
It seems like $day can also be of type double or string. However, the property $day is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function format($format)
77
    {
78
        return str_replace([
79
            '{month}',
80
            '{day}',
81
        ], [
82
            $this->month,
83
            $this->day,
84
        ], $format);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function toString()
91
    {
92
        return $this->format('{month}月{day}日');
93
    }
94
95
    /**
96
     * 字符串输出.
97
     *
98
     * @return string
99
     */
100
    public function __toString()
101
    {
102
        return $this->toString();
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function jsonSerialize()
109
    {
110
        return $this->toString();
111
    }
112
}