Conditions | 6 |
Paths | 10 |
Total Lines | 56 |
Code Lines | 34 |
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 |
||
19 | public static function installGitMessageHook(Event $event) |
||
20 | { |
||
21 | $gitHookContent = <<<CONTENT |
||
22 | #!/bin/sh |
||
23 | |||
24 | vendor/bin/git-lint-validators git-lint-validator:hook $1 |
||
25 | CONTENT; |
||
26 | |||
27 | $io = $event->getIO(); |
||
28 | $question = "Do you want to install and activate the Git " |
||
29 | . "commit message hook? "; |
||
30 | |||
31 | if ($io->askConfirmation($question, false)) { |
||
32 | $gitDirectory = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . '.git'; |
||
33 | if (!is_dir($gitDirectory)) { |
||
34 | $errorMessage = "Couldn't locate the .git directory. " |
||
35 | . "Aborting the Git hook installation."; |
||
36 | $io->error($errorMessage); |
||
37 | |||
38 | return false; |
||
39 | } |
||
40 | |||
41 | $gitCommitMessageHookFile = $gitDirectory |
||
42 | . DIRECTORY_SEPARATOR . 'hooks' |
||
43 | . DIRECTORY_SEPARATOR . 'commit-msg'; |
||
44 | |||
45 | $backedExistingGitCommitMessageHookFile = false; |
||
46 | if (file_exists($gitCommitMessageHookFile)) { |
||
47 | $backedExistingGitCommitMessageHookFile = copy( |
||
48 | $gitCommitMessageHookFile, |
||
49 | $gitCommitMessageHookFile . '.bak' |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | file_put_contents($gitCommitMessageHookFile, $gitHookContent); |
||
54 | chmod($gitCommitMessageHookFile, 0751); |
||
55 | |||
56 | $io->write("Installed and activated the Git commit message hook."); |
||
57 | |||
58 | if ($backedExistingGitCommitMessageHookFile) { |
||
59 | $io->write("Backed previous Git commit message hook."); |
||
60 | } |
||
61 | |||
62 | if ($io->isVerbose()) { |
||
63 | $io->write("Wrote"); |
||
64 | $io->write("<comment>$gitHookContent</comment>"); |
||
65 | $io->write("into <info>$gitCommitMessageHookFile</info> and made it executable."); |
||
66 | } |
||
67 | |||
68 | return true; |
||
69 | } |
||
70 | |||
71 | $io->write("Aborted installation and activation of the Git commit message hook."); |
||
72 | |||
73 | return false; |
||
74 | } |
||
75 | } |
||
76 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.