Conditions | 1 |
Paths | 1 |
Total Lines | 71 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
74 | public function testFirstAndLastDays() |
||
75 | { |
||
76 | # First day of this month |
||
77 | $dt = Dt::create([ |
||
78 | "day" => Dt::FIRST_DAY, "month" => dt::THIS_MONTH, "year" => dt::THIS_YEAR |
||
79 | ]); |
||
80 | |||
81 | $dateTime = new \DateTime("first day of " . Dt::getMonth((int) date('m')) . " " . date('Y')); |
||
82 | |||
83 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
84 | |||
85 | |||
86 | # Last day of this month |
||
87 | $dt = Dt::create([ |
||
88 | "day" => Dt::LAST_DAY, "month" => dt::THIS_MONTH, "year" => dt::THIS_YEAR |
||
89 | ]); |
||
90 | |||
91 | $dateTime = new \DateTime("last day of " . Dt::getMonth((int) date('m')) . " " . date('Y')); |
||
92 | |||
93 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
94 | |||
95 | |||
96 | # first day of last month |
||
97 | $dt = Dt::create([ |
||
98 | "day" => Dt::FIRST_DAY, "month" => dt::LAST_MONTH, "year" => dt::THIS_YEAR |
||
99 | ]); |
||
100 | |||
101 | $dateTime = new \DateTime("first day of -1 month"); |
||
102 | |||
103 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
104 | |||
105 | |||
106 | # last day of last month |
||
107 | $dt = Dt::create([ |
||
108 | "day" => Dt::LAST_DAY, "month" => dt::LAST_MONTH, "year" => dt::THIS_YEAR |
||
109 | ]); |
||
110 | |||
111 | $dateTime = new \DateTime("last day of -1 month"); |
||
112 | |||
113 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
114 | |||
115 | |||
116 | # first day of June of last year |
||
117 | $dt = Dt::create([ |
||
118 | "day" => Dt::FIRST_DAY, "month" => 6, "year" => dt::LAST_YEAR |
||
119 | ]); |
||
120 | |||
121 | $dateTime = new \DateTime("first day of June " . (date('Y') - 1)); |
||
122 | |||
123 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
124 | |||
125 | |||
126 | # last day of June of last year |
||
127 | $dt = Dt::create([ |
||
128 | "day" => Dt::LAST_DAY, "month" => 6, "year" => dt::LAST_YEAR |
||
129 | ]); |
||
130 | |||
131 | $dateTime = new \DateTime("last day of June " . (date('Y') - 1)); |
||
132 | |||
133 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
134 | |||
135 | |||
136 | # 10th day of June of last year |
||
137 | $dt = Dt::create([ |
||
138 | "day" => 10, "month" => 6, "year" => dt::LAST_YEAR |
||
139 | ]); |
||
140 | |||
141 | $dateTime = new \DateTime("first day of June " . (date('Y') - 1)); |
||
142 | $dateTime->add(new \DateInterval('P9D')); |
||
143 | |||
144 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
145 | } |
||
146 | } |