Conditions | 6 |
Paths | 10 |
Total Lines | 51 |
Code Lines | 30 |
Lines | 8 |
Ratio | 15.69 % |
Changes | 2 | ||
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 |
||
52 | public static function installGitMessageHook(Event $event) |
||
53 | { |
||
54 | $hookContent = self::HOOK_CONTENTS; |
||
55 | $inputOutput = $event->getIO(); |
||
56 | $question = "Do you want to install and activate the Git "; |
||
57 | $question .= "commit message hook? "; |
||
58 | |||
59 | if ($inputOutput->askConfirmation($question, false)) { |
||
60 | $gitDirectory = implode(DIRECTORY_SEPARATOR, [dirname(__DIR__, 4), self::GIT_PATH]); |
||
61 | |||
62 | View Code Duplication | if (!is_dir($gitDirectory)) { |
|
1 ignored issue
–
show
|
|||
63 | $errorMessage = "Couldn't locate the .git directory. "; |
||
64 | $errorMessage .= "Aborting the Git hook installation."; |
||
65 | |||
66 | $inputOutput->error($errorMessage); |
||
67 | |||
68 | return false; |
||
69 | } |
||
70 | |||
71 | $hookFile = implode(DIRECTORY_SEPARATOR, [$gitDirectory, self::HOOKS_PATH, self::HOOK_FILENAME]); |
||
72 | $existingHookFile = false; |
||
73 | |||
74 | if (file_exists($hookFile)) { |
||
75 | $existingHookFile = copy( |
||
76 | $hookFile, |
||
77 | $hookFile . self::BACKUP_EXTENSION |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | file_put_contents($hookFile, $hookContent); |
||
82 | chmod($hookFile, self::EXECUTABLE_PERMISSIONS); |
||
83 | |||
84 | $inputOutput->write("Installed and activated the Git commit message hook."); |
||
85 | |||
86 | if ($existingHookFile) { |
||
87 | $inputOutput->write("Backed previous Git commit message hook."); |
||
88 | } |
||
89 | |||
90 | if ($inputOutput->isVerbose()) { |
||
91 | $inputOutput->write("Wrote"); |
||
92 | $inputOutput->write("<comment>$hookContent</comment>"); |
||
93 | $inputOutput->write("into <info>$hookFile</info> and made it executable."); |
||
94 | } |
||
95 | |||
96 | return true; |
||
97 | } |
||
98 | |||
99 | $inputOutput->write("Aborted installation and activation of the Git commit message hook."); |
||
100 | |||
101 | return false; |
||
102 | } |
||
103 | |||
154 |
This check looks for improperly formatted assignments.
Every assignment must have exactly one space before and one space after the equals operator.
To illustrate:
will have no issues, while
will report issues in lines 1 and 2.