| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 28 | public function testLookup(): void |
||
| 29 | { |
||
| 30 | $volume = new Target\VolumeTargetFlat(); |
||
| 31 | $this->assertTrue($volume->check($this->getTestDir())); |
||
| 32 | $testFiles = [ |
||
| 33 | 'dummyFile.tst' => $this->getTestDir() . 'dummyFile.tst', |
||
| 34 | 'dummyFile.0.tst' => $this->getTestDir() . 'dummyFile.0.tst', |
||
| 35 | 'dummyFile.1.tst' => $this->getTestDir() . 'dummyFile.1.tst', |
||
| 36 | 'dummyFile.2.tst' => $this->getTestDir() . 'dummyFile.2.tst', |
||
| 37 | ]; |
||
| 38 | $removal = $volume->removeMulti($testFiles); |
||
| 39 | $this->assertEquals([ |
||
| 40 | 'dummyFile.tst' => false, |
||
| 41 | 'dummyFile.0.tst' => false, |
||
| 42 | 'dummyFile.1.tst' => false, |
||
| 43 | 'dummyFile.2.tst' => false, |
||
| 44 | ], $removal); |
||
| 45 | |||
| 46 | file_put_contents($this->getTestDir() . 'dummyFile.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
||
| 47 | file_put_contents($this->getTestDir() . 'dummyFile.0.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
||
| 48 | file_put_contents($this->getTestDir() . 'dummyFile.1.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
||
| 49 | file_put_contents($this->getTestDir() . 'dummyFile.2.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
||
| 50 | |||
| 51 | // non-existent path |
||
| 52 | $this->assertEquals(0, count(array_filter(array_filter(iterator_to_array($volume->lookup('this path does not exists'))), [$this, 'dotDirs']))); |
||
| 53 | |||
| 54 | // empty path - must show everything |
||
| 55 | // 5 -> + gitkeep; but here goes into exec path, so the results are environment-dependent |
||
| 56 | // $this->assertEquals(5, count(array_filter(array_filter(iterator_to_array($volume->lookup(''))), [$this, 'dotDirs']))); |
||
| 57 | |||
| 58 | $files = iterator_to_array($volume->lookup($this->getTestDir())); |
||
| 59 | sort($files); |
||
| 60 | $files = array_filter(array_filter($files), [$this, 'dotDirs']); |
||
| 61 | |||
| 62 | $this->assertEquals(count($testFiles) + 1, count($files)); // because gitkeep |
||
| 63 | $this->assertEquals(DIRECTORY_SEPARATOR . '.gitkeep', reset($files)); |
||
| 64 | $this->assertEquals(DIRECTORY_SEPARATOR . 'dummyFile.0.tst', next($files)); |
||
| 65 | $this->assertEquals(DIRECTORY_SEPARATOR . 'dummyFile.1.tst', next($files)); |
||
| 66 | $this->assertEquals(DIRECTORY_SEPARATOR . 'dummyFile.2.tst', next($files)); |
||
| 67 | $this->assertEquals(DIRECTORY_SEPARATOR . 'dummyFile.tst', next($files)); |
||
| 68 | |||
| 69 | $removal = $volume->removeMulti($testFiles); |
||
| 70 | $this->assertFalse($volume->exists($this->getTestDir() . 'dummyFile.tst')); |
||
| 71 | $this->assertFalse($volume->exists($this->getTestDir() . 'dummyFile.0.tst')); |
||
| 72 | $this->assertFalse($volume->exists($this->getTestDir() . 'dummyFile.1.tst')); |
||
| 73 | $this->assertFalse($volume->exists($this->getTestDir() . 'dummyFile.2.tst')); |
||
| 74 | |||
| 75 | $this->assertEquals([ |
||
| 76 | 'dummyFile.tst' => true, |
||
| 77 | 'dummyFile.0.tst' => true, |
||
| 78 | 'dummyFile.1.tst' => true, |
||
| 79 | 'dummyFile.2.tst' => true, |
||
| 80 | ], $removal); |
||
| 81 | } |
||
| 88 |