| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code Lines | 43 |
| 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 |
||
| 20 | public function testAddAppendsItemToCollectionWithNextNumericIndex() |
||
| 21 | { |
||
| 22 | $array = Factory::create($this->fixtures['array']); |
||
| 23 | $this->assertEquals( |
||
| 24 | [ |
||
| 25 | 0 => 'first', |
||
| 26 | 1 => 'second', |
||
| 27 | 2 => 'third', |
||
| 28 | ], |
||
| 29 | $array->toArray() |
||
| 30 | ); |
||
| 31 | $array->add('fourth'); |
||
| 32 | $this->assertSame( |
||
| 33 | [ |
||
| 34 | 0 => 'first', |
||
| 35 | 1 => 'second', |
||
| 36 | 2 => 'third', |
||
| 37 | 3 => 'fourth', |
||
| 38 | ], |
||
| 39 | $array->toArray() |
||
| 40 | ); |
||
| 41 | $array->add('fifth'); |
||
| 42 | $this->assertSame( |
||
| 43 | [ |
||
| 44 | 0 => 'first', |
||
| 45 | 1 => 'second', |
||
| 46 | 2 => 'third', |
||
| 47 | 3 => 'fourth', |
||
| 48 | 4 => 'fifth', |
||
| 49 | ], |
||
| 50 | $array->toArray() |
||
| 51 | ); |
||
| 52 | |||
| 53 | $assoc = Factory::create($this->fixtures['assoc']); |
||
| 54 | $this->assertEquals( |
||
| 55 | [ |
||
| 56 | '1st' => 'first', |
||
| 57 | '2nd' => 'second', |
||
| 58 | '3rd' => 'third', |
||
| 59 | ], |
||
| 60 | $assoc->toArray() |
||
| 61 | ); |
||
| 62 | $assoc->add('fourth'); |
||
| 63 | $this->assertSame( |
||
| 64 | [ |
||
| 65 | '1st' => 'first', |
||
| 66 | '2nd' => 'second', |
||
| 67 | '3rd' => 'third', |
||
| 68 | 0 => 'fourth', |
||
| 69 | ], |
||
| 70 | $assoc->toArray() |
||
| 71 | ); |
||
| 72 | $assoc->add('fifth'); |
||
| 73 | $this->assertSame( |
||
| 74 | [ |
||
| 75 | '1st' => 'first', |
||
| 76 | '2nd' => 'second', |
||
| 77 | '3rd' => 'third', |
||
| 78 | 0 => 'fourth', |
||
| 79 | 1 => 'fifth', |
||
| 80 | ], |
||
| 81 | $assoc->toArray() |
||
| 82 | ); |
||
| 83 | } |
||
| 84 | } |
||
| 85 |