| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| 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 |
||
| 49 | public function testLookup(): void |
||
| 50 | { |
||
| 51 | $memory = new Target\Memory(); |
||
| 52 | $this->assertTrue($memory->check($this->getTestDir())); |
||
| 53 | $testFiles = [ |
||
| 54 | 'dummyFile.tst' => $this->getTestDir() . 'dummyFile.tst', |
||
| 55 | 'dummyFile.0.tst' => $this->getTestDir() . 'dummyFile.0.tst', |
||
| 56 | 'dummyFile.1.tst' => $this->getTestDir() . 'dummyFile.1.tst', |
||
| 57 | 'dummyFile.2.tst' => $this->getTestDir() . 'dummyFile.2.tst', |
||
| 58 | ]; |
||
| 59 | $removal = $memory->removeMulti($testFiles); |
||
| 60 | $this->assertEquals([ |
||
| 61 | 'dummyFile.tst' => false, |
||
| 62 | 'dummyFile.0.tst' => false, |
||
| 63 | 'dummyFile.1.tst' => false, |
||
| 64 | 'dummyFile.2.tst' => false, |
||
| 65 | ], $removal); |
||
| 66 | |||
| 67 | $memory->save($this->getTestDir() . 'dummyFile.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
||
| 68 | $memory->save($this->getTestDir() . 'dummyFile.0.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
||
| 69 | $memory->save($this->getTestDir() . 'dummyFile.1.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
||
| 70 | $memory->save($this->getTestDir() . 'dummyFile.2.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
||
| 71 | |||
| 72 | // non-existent path |
||
| 73 | $this->assertEquals(0, count(array_filter(iterator_to_array($memory->lookup('this path does not exists')), [$this, 'dotDirs']))); |
||
| 74 | |||
| 75 | // empty path - must show everything |
||
| 76 | $this->assertEquals(4, count(array_filter(iterator_to_array($memory->lookup('')), [$this, 'dotDirs']))); |
||
| 77 | |||
| 78 | // normal path |
||
| 79 | $files = iterator_to_array($memory->lookup($this->getTestDir())); |
||
| 80 | sort($files); |
||
| 81 | $files = array_filter($files, [$this, 'dotDirs']); |
||
| 82 | |||
| 83 | $this->assertEquals(count($testFiles), count($files)); |
||
| 84 | $this->assertEquals('dummyFile.0.tst', reset($files)); |
||
| 85 | $this->assertEquals('dummyFile.1.tst', next($files)); |
||
| 86 | $this->assertEquals('dummyFile.2.tst', next($files)); |
||
| 87 | $this->assertEquals('dummyFile.tst', next($files)); |
||
| 88 | |||
| 89 | $removal = $memory->removeMulti($testFiles); |
||
| 90 | $this->assertFalse($memory->exists($this->getTestDir() . 'dummyFile.tst')); |
||
| 91 | $this->assertFalse($memory->exists($this->getTestDir() . 'dummyFile.0.tst')); |
||
| 92 | $this->assertFalse($memory->exists($this->getTestDir() . 'dummyFile.1.tst')); |
||
| 93 | $this->assertFalse($memory->exists($this->getTestDir() . 'dummyFile.2.tst')); |
||
| 94 | |||
| 95 | $this->assertEquals([ |
||
| 96 | 'dummyFile.tst' => true, |
||
| 97 | 'dummyFile.0.tst' => true, |
||
| 98 | 'dummyFile.1.tst' => true, |
||
| 99 | 'dummyFile.2.tst' => true, |
||
| 100 | ], $removal); |
||
| 101 | } |
||
| 142 |