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 //phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase |
||
29 | class CustomAutoloaderPlugin implements PluginInterface, EventSubscriberInterface { |
||
30 | |||
31 | /** |
||
32 | * IO object. |
||
33 | * |
||
34 | * @var IOInterface IO object. |
||
35 | */ |
||
36 | private $io; |
||
37 | |||
38 | /** |
||
39 | * Composer object. |
||
40 | * |
||
41 | * @var Composer Composer object. |
||
42 | */ |
||
43 | private $composer; |
||
44 | |||
45 | /** |
||
46 | * Do nothing. |
||
47 | * |
||
48 | * @param Composer $composer Composer object. |
||
49 | * @param IOInterface $io IO object. |
||
50 | */ |
||
51 | public function activate( Composer $composer, IOInterface $io ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
55 | |||
56 | /** |
||
57 | * Do nothing. |
||
58 | * phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
59 | * |
||
60 | * @param Composer $composer Composer object. |
||
61 | * @param IOInterface $io IO object. |
||
62 | */ |
||
63 | public function deactivate( Composer $composer, IOInterface $io ) { |
||
69 | |||
70 | /** |
||
71 | * Do nothing. |
||
72 | * phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
73 | * |
||
74 | * @param Composer $composer Composer object. |
||
75 | * @param IOInterface $io IO object. |
||
76 | */ |
||
77 | public function uninstall( Composer $composer, IOInterface $io ) { |
||
83 | |||
84 | /** |
||
85 | * Tell composer to listen for events and do something with them. |
||
86 | * |
||
87 | * @return array List of subscribed events. |
||
88 | */ |
||
89 | public static function getSubscribedEvents() { |
||
94 | |||
95 | /** |
||
96 | * Generate the custom autolaoder. |
||
97 | * |
||
98 | * @param Event $event Script event object. |
||
99 | */ |
||
100 | public function postAutoloadDump( Event $event ) { |
||
121 | |||
122 | /** |
||
123 | * Determine the suffix for the autoloader class. |
||
124 | * |
||
125 | * Reuses an existing suffix from vendor/autoload_packages.php or vendor/autoload.php if possible. |
||
126 | * |
||
127 | * @return string Suffix. |
||
128 | */ |
||
129 | private function determineSuffix() { |
||
160 | |||
161 | } |
||
162 |