| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 69 | public function testFirstAndLastDays() |
||
| 70 | { |
||
| 71 | # First day of this month |
||
| 72 | $dt = Dt::create([ |
||
| 73 | "day" => Dt::FIRST_DAY, "month" => dt::THIS_MONTH, "year" => dt::THIS_YEAR, |
||
| 74 | ]); |
||
| 75 | |||
| 76 | $dateTime = new \DateTime("first day of " . Dt::getMonth((int) date('m')) . " " . date('Y')); |
||
| 77 | |||
| 78 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
| 79 | |||
| 80 | # Last day of this month |
||
| 81 | $dt = Dt::create([ |
||
| 82 | "day" => Dt::LAST_DAY, "month" => dt::THIS_MONTH, "year" => dt::THIS_YEAR, |
||
| 83 | ]); |
||
| 84 | |||
| 85 | $dateTime = new \DateTime("last day of " . Dt::getMonth((int) date('m')) . " " . date('Y')); |
||
| 86 | |||
| 87 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
| 88 | |||
| 89 | # first day of last month |
||
| 90 | $dt = Dt::create([ |
||
| 91 | "day" => Dt::FIRST_DAY, "month" => dt::LAST_MONTH, "year" => dt::THIS_YEAR, |
||
| 92 | ]); |
||
| 93 | |||
| 94 | $dateTime = new \DateTime("first day of -1 month"); |
||
| 95 | |||
| 96 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
| 97 | |||
| 98 | # last day of last month |
||
| 99 | $dt = Dt::create([ |
||
| 100 | "day" => Dt::LAST_DAY, "month" => dt::LAST_MONTH, "year" => dt::THIS_YEAR, |
||
| 101 | ]); |
||
| 102 | |||
| 103 | $dateTime = new \DateTime("last day of -1 month"); |
||
| 104 | |||
| 105 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
| 106 | |||
| 107 | # first day of June of last year |
||
| 108 | $dt = Dt::create([ |
||
| 109 | "day" => Dt::FIRST_DAY, "month" => 6, "year" => dt::LAST_YEAR, |
||
| 110 | ]); |
||
| 111 | |||
| 112 | $dateTime = new \DateTime("first day of June " . (date('Y') - 1)); |
||
| 113 | |||
| 114 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
| 115 | |||
| 116 | # last day of June of last year |
||
| 117 | $dt = Dt::create([ |
||
| 118 | "day" => Dt::LAST_DAY, "month" => 6, "year" => dt::LAST_YEAR, |
||
| 119 | ]); |
||
| 120 | |||
| 121 | $dateTime = new \DateTime("last day of June " . (date('Y') - 1)); |
||
| 122 | |||
| 123 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
| 124 | |||
| 125 | # 10th day of June of last year |
||
| 126 | $dt = Dt::create([ |
||
| 127 | "day" => 10, "month" => 6, "year" => dt::LAST_YEAR, |
||
| 128 | ]); |
||
| 129 | |||
| 130 | $dateTime = new \DateTime("first day of June " . (date('Y') - 1)); |
||
| 131 | $dateTime->add(new \DateInterval('P9D')); |
||
| 132 | |||
| 133 | $this->assertEquals($dt->format('d/m/Y'), $dateTime->format('d/m/Y')); |
||
| 134 | } |
||
| 136 |