| Conditions | 1 |
| Paths | 1 |
| Total Lines | 75 |
| Code Lines | 54 |
| 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 |
||
| 110 | public function testRemoveDuplicates() |
||
| 111 | { |
||
| 112 | Injector::inst()->get(URLArrayObject::class)->addUrls( |
||
| 113 | array( |
||
| 114 | 'test1' => 1, |
||
| 115 | 'test2' => 1, |
||
| 116 | 'test3' => 1 |
||
| 117 | ) |
||
| 118 | ); |
||
| 119 | Injector::inst()->get(URLArrayObject::class)->addUrls( |
||
| 120 | array( |
||
| 121 | 'test2' => 2, // duplicate |
||
| 122 | 'test3' => 2, // duplicate |
||
| 123 | ) |
||
| 124 | ); |
||
| 125 | Injector::inst()->get(URLArrayObject::class)->addUrls( |
||
| 126 | array( |
||
| 127 | 'test2' => 3, // duplicate |
||
| 128 | ) |
||
| 129 | ); |
||
| 130 | $test1Objs = StaticPagesQueue::get()->filter( |
||
| 131 | array( |
||
| 132 | 'URLSegment' => 'test1' |
||
| 133 | ) |
||
| 134 | )->first(); |
||
| 135 | $test2Objs = StaticPagesQueue::get()->filter( |
||
| 136 | array( |
||
| 137 | 'URLSegment' => 'test2' |
||
| 138 | ) |
||
| 139 | )->first(); |
||
| 140 | $test3Objs = StaticPagesQueue::get()->filter( |
||
| 141 | array( |
||
| 142 | 'URLSegment' => 'test3' |
||
| 143 | ) |
||
| 144 | )->first(); |
||
| 145 | $this->assertCount(1, $test1Objs); |
||
| 146 | $this->assertCount(3, $test2Objs); |
||
| 147 | $this->assertCount(2, $test3Objs); |
||
| 148 | |||
| 149 | StaticPagesQueue::remove_duplicates($test1Objs->first()->ID); |
||
| 150 | $test1Objs = StaticPagesQueue::get()->filter( |
||
| 151 | array( |
||
| 152 | 'URLSegment' => 'test1' |
||
| 153 | ) |
||
| 154 | )->first(); |
||
| 155 | $test2Objs = StaticPagesQueue::get()->filter( |
||
| 156 | array( |
||
| 157 | 'URLSegment' => 'test2' |
||
| 158 | ) |
||
| 159 | )->first(); |
||
| 160 | $test3Objs = StaticPagesQueue::get()->filter( |
||
| 161 | array( |
||
| 162 | 'URLSegment' => 'test3' |
||
| 163 | ) |
||
| 164 | )->first(); |
||
| 165 | $this->assertCount(1, $test1Objs); |
||
| 166 | $this->assertCount(3, $test2Objs); |
||
| 167 | $this->assertCount(2, $test3Objs); |
||
| 168 | |||
| 169 | StaticPagesQueue::remove_duplicates($test2Objs->first()->ID); |
||
| 170 | $test2Objs = StaticPagesQueue::get()->filter( |
||
| 171 | array( |
||
| 172 | 'URLSegment' => 'test2' |
||
| 173 | ) |
||
| 174 | ); |
||
| 175 | $this->assertCount(1, $test2Objs); |
||
| 176 | |||
| 177 | StaticPagesQueue::remove_duplicates($test3Objs->first()->ID); |
||
| 178 | $test3Objs = StaticPagesQueue::get()->filter( |
||
| 179 | array( |
||
| 180 | 'URLSegment' => 'test3' |
||
| 181 | ) |
||
| 182 | ); |
||
| 183 | $this->assertCount(1, $test3Objs); |
||
| 184 | } |
||
| 185 | } |
||
| 186 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.