Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
7 | class Scripts |
||
8 | { |
||
9 | const BACKUP_EXTENSION = '.bak'; |
||
10 | const GIT_PATH = '.git'; |
||
11 | const HOOKS_PATH = 'hooks'; |
||
12 | const HOOK_FILENAME = 'commit-msg'; |
||
13 | const TEMPLATE_FILENAME = '.gitmessage'; |
||
14 | |||
15 | /** |
||
16 | * Default Permissions (Copied from example hooks) |
||
17 | * |
||
18 | * User: Read, Write, Execute |
||
19 | * Group: Read, Execute |
||
20 | * Other: Execute |
||
21 | */ |
||
22 | const EXECUTABLE_PERMISSIONS = 0751; |
||
23 | const HOOK_CONTENTS = <<<CONTENT |
||
24 | #!/bin/sh |
||
25 | |||
26 | vendor/bin/git-lint-validators git-lint-validator:hook $1 |
||
27 | CONTENT; |
||
28 | |||
29 | const TEMPLATE_CONTENTS = <<<CONTENT |
||
|
|||
30 | Subject line |
||
31 | |||
32 | # - Capitalise the subject line and do not end it with a period |
||
33 | # - Use the imperative mood in the subject line |
||
34 | # - Summarise changes in around 50 (soft limit, hard limit at 69) |
||
35 | # characters or less in the subject line |
||
36 | # - Separate subject line from body with a blank line |
||
37 | Subject body |
||
38 | # - Use the subject body to explain what and why vs. how |
||
39 | # - Wrap the subject body at 72 characters |
||
40 | |||
41 | CONTENT; |
||
42 | |||
43 | /** |
||
44 | * Installs and activates the Git commit message |
||
45 | * hook when confirmed by the user. An existing hook |
||
46 | * is backed with the .bak extension. |
||
47 | * |
||
48 | * @param Event $event The script event. |
||
49 | * |
||
50 | * @return boolean |
||
51 | */ |
||
52 | public static function installGitMessageHook(Event $event) |
||
103 | |||
104 | /** |
||
105 | * Installs and configures the Git commit message |
||
106 | * template when confirmed by the user. |
||
107 | * |
||
108 | * @param Event $event The script event. |
||
109 | * |
||
110 | * @return boolean |
||
111 | */ |
||
112 | public static function installGitCommitMessageTemplate(Event $event) |
||
153 | } |
||
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.