| Conditions | 3 |
| Paths | 3 |
| Total Lines | 61 |
| Code Lines | 39 |
| 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 |
||
| 48 | protected function mockIterator( |
||
| 49 | \Iterator $iterator, |
||
| 50 | array $items, |
||
| 51 | $includeCallsToKey = FALSE |
||
| 52 | ) { |
||
| 53 | $iterator |
||
| 54 | ->expects( |
||
| 55 | $this->at(0) |
||
| 56 | ) |
||
| 57 | ->method('rewind') |
||
| 58 | ; |
||
| 59 | $counter = 1; |
||
| 60 | |||
| 61 | foreach ($items as $k => $v) { |
||
| 62 | $iterator |
||
| 63 | ->expects( |
||
| 64 | $this->at($counter++) |
||
| 65 | ) |
||
| 66 | ->method('valid') |
||
| 67 | ->will( |
||
| 68 | $this->returnValue(TRUE) |
||
| 69 | ) |
||
| 70 | ; |
||
| 71 | $iterator |
||
| 72 | ->expects( |
||
| 73 | $this->at($counter++) |
||
| 74 | ) |
||
| 75 | ->method('current') |
||
| 76 | ->will( |
||
| 77 | $this->returnValue($v) |
||
| 78 | ) |
||
| 79 | ; |
||
| 80 | if ($includeCallsToKey) { |
||
| 81 | $iterator |
||
| 82 | ->expects( |
||
| 83 | $this->at($counter++) |
||
| 84 | ) |
||
| 85 | ->method('key') |
||
| 86 | ->will( |
||
| 87 | $this->returnValue($k) |
||
| 88 | ) |
||
| 89 | ; |
||
| 90 | } |
||
| 91 | $iterator |
||
| 92 | ->expects( |
||
| 93 | $this->at($counter++) |
||
| 94 | ) |
||
| 95 | ->method('next') |
||
| 96 | ; |
||
| 97 | } |
||
| 98 | |||
| 99 | $iterator |
||
| 100 | ->expects( |
||
| 101 | $this->at($counter) |
||
| 102 | ) |
||
| 103 | ->method('valid') |
||
| 104 | ->will( |
||
| 105 | $this->returnValue(FALSE) |
||
| 106 | ) |
||
| 107 | ; |
||
| 108 | } |
||
| 109 | |||
| 202 |
It seems like you are relying on a variable being defined by an iteration: