| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 33 |
| 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 |
||
| 60 | public function testCheckedOutRevisionIsAtExpectedRevisionState() : void |
||
| 61 | { |
||
| 62 | $repoPath = tempnam(sys_get_temp_dir(), 'test-git-repo-'); |
||
| 63 | |||
| 64 | unlink($repoPath); |
||
| 65 | mkdir($repoPath); |
||
| 66 | |||
| 67 | (new Process(['git', 'init'], $repoPath)) |
||
| 68 | ->mustRun(); |
||
| 69 | |||
| 70 | (new Process(['git', 'config', 'user.email', '[email protected]'], $repoPath)) |
||
| 71 | ->mustRun(); |
||
| 72 | |||
| 73 | (new Process(['git', 'config', 'user.name', 'Mr Magoo'], $repoPath)) |
||
| 74 | ->mustRun(); |
||
| 75 | |||
| 76 | (new Process(['git', 'commit', '-m', 'initial commit', '--allow-empty'], $repoPath)) |
||
| 77 | ->mustRun(); |
||
| 78 | |||
| 79 | $firstCommit = Revision::fromSha1( |
||
| 80 | (new Process(['git', 'rev-parse', 'HEAD'], $repoPath)) |
||
| 81 | ->mustRun() |
||
| 82 | ->getOutput() |
||
| 83 | ); |
||
| 84 | |||
| 85 | file_put_contents($repoPath . '/a-file.txt', 'file contents'); |
||
| 86 | |||
| 87 | (new Process(['git', 'add', 'a-file.txt'], $repoPath)) |
||
| 88 | ->mustRun(); |
||
| 89 | |||
| 90 | (new Process(['git', 'commit', '-m', 'second commit', '--allow-empty'], $repoPath)) |
||
| 91 | ->mustRun(); |
||
| 92 | |||
| 93 | $secondCommit = Revision::fromSha1( |
||
| 94 | (new Process(['git', 'rev-parse', 'HEAD'], $repoPath)) |
||
| 95 | ->mustRun() |
||
| 96 | ->getOutput() |
||
| 97 | ); |
||
| 98 | |||
| 99 | $git = new GitCheckoutRevisionToTemporaryPath(); |
||
| 100 | |||
| 101 | $sourceRepository = CheckedOutRepository::fromPath($repoPath); |
||
| 102 | $first = $git->checkout($sourceRepository, $firstCommit); |
||
| 103 | $second = $git->checkout($sourceRepository, $secondCommit); |
||
| 104 | |||
| 105 | self::assertFileDoesNotExist($first->__toString() . '/a-file.txt'); |
||
| 106 | self::assertFileExists($second->__toString() . '/a-file.txt'); |
||
| 107 | |||
| 108 | $git->remove($first); |
||
| 109 | $git->remove($second); |
||
| 110 | |||
| 111 | (new Process(['rm', '-rf', $repoPath]))->mustRun(); |
||
| 112 | } |
||
| 147 |