| Conditions | 2 |
| Paths | 2 |
| Total Lines | 73 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 55 | public function testIfCorrectFilesAreBeingYielded() |
||
| 56 | { |
||
| 57 | $isHidden = m::mock('Flyfinder\Specification\IsHidden'); |
||
| 58 | $filesystem = m::mock('League\Flysystem\Filesystem'); |
||
| 59 | |||
| 60 | $listContents1 = [ |
||
| 61 | 0 => [ |
||
| 62 | "type" => "dir", |
||
| 63 | "path" => ".hiddendir", |
||
| 64 | "dirname" => "", |
||
| 65 | "basename" => ".hiddendir", |
||
| 66 | "filename" => ".hiddendir", |
||
| 67 | ], |
||
| 68 | 1 => [ |
||
| 69 | "type" => "file", |
||
| 70 | "path" => "test.txt", |
||
| 71 | "basename" => "test.txt" |
||
| 72 | ], |
||
| 73 | ]; |
||
| 74 | |||
| 75 | $listContents2 = [ |
||
| 76 | 0 => [ |
||
| 77 | "type" => "file", |
||
| 78 | "path" => ".hiddendir/.test.txt", |
||
| 79 | "dirname" => ".hiddendir", |
||
| 80 | "basename" => ".test.txt", |
||
| 81 | "filename" => ".test", |
||
| 82 | "extension" => "txt", |
||
| 83 | ], |
||
| 84 | ]; |
||
| 85 | |||
| 86 | $filesystem->shouldReceive('listContents') |
||
| 87 | ->with('') |
||
| 88 | ->andReturn($listContents1); |
||
| 89 | |||
| 90 | $filesystem->shouldReceive('listContents') |
||
| 91 | ->with('.hiddendir') |
||
| 92 | ->andReturn($listContents2); |
||
| 93 | |||
| 94 | $isHidden->shouldReceive('isSatisfiedBy') |
||
| 95 | ->with($listContents1[0]) |
||
| 96 | ->andReturn(true); |
||
| 97 | |||
| 98 | $isHidden->shouldReceive('isSatisfiedBy') |
||
| 99 | ->with($listContents1[1]) |
||
| 100 | ->andReturn(false); |
||
| 101 | |||
| 102 | $isHidden->shouldReceive('isSatisfiedBy') |
||
| 103 | ->with($listContents2[0]) |
||
| 104 | ->andReturn(true); |
||
| 105 | |||
| 106 | $this->fixture->setFilesystem($filesystem); |
||
| 107 | $generator = $this->fixture->handle($isHidden); |
||
| 108 | |||
| 109 | $result = []; |
||
| 110 | |||
| 111 | foreach ($generator as $value) { |
||
| 112 | $result[] = $value; |
||
| 113 | } |
||
| 114 | |||
| 115 | $expected = [ |
||
| 116 | 0 => [ |
||
| 117 | "type" => "file", |
||
| 118 | "path" => ".hiddendir/.test.txt", |
||
| 119 | "dirname" => ".hiddendir", |
||
| 120 | "basename" => ".test.txt", |
||
| 121 | "filename" => ".test", |
||
| 122 | "extension" => "txt", |
||
| 123 | ] |
||
| 124 | ]; |
||
| 125 | |||
| 126 | $this->assertEquals($expected, $result); |
||
| 127 | } |
||
| 128 | } |
||
| 129 |