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 |
||
36 | class CacheApiCommandController extends CommandController { |
||
37 | /** |
||
38 | * @var \TYPO3\CMS\Core\Log\LogManager $logManager |
||
39 | */ |
||
40 | protected $logManager; |
||
41 | |||
42 | /** |
||
43 | * @var \TYPO3\CMS\Core\Log\Logger $logger |
||
44 | */ |
||
45 | protected $logger; |
||
46 | |||
47 | /** |
||
48 | * @param \TYPO3\CMS\Core\Log\LogManager $logManager |
||
49 | * |
||
50 | * @return void |
||
51 | */ |
||
52 | public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) { |
||
55 | |||
56 | /** |
||
57 | * Initialize the object |
||
58 | */ |
||
59 | public function initializeObject() { |
||
62 | |||
63 | /** |
||
64 | * @var \Etobi\CoreAPI\Service\CacheApiService |
||
65 | */ |
||
66 | protected $cacheApiService; |
||
67 | |||
68 | /** |
||
69 | * Inject the CacheApiService |
||
70 | * |
||
71 | * @param \Etobi\CoreAPI\Service\CacheApiService $cacheApiService |
||
72 | */ |
||
73 | public function injectCacheApiService(\Etobi\CoreAPI\Service\CacheApiService $cacheApiService) { |
||
76 | |||
77 | /** |
||
78 | * Clear all caches. |
||
79 | * If hard, cache will be cleared in a more straightforward approach and the according backend hooks are not executed. |
||
80 | * |
||
81 | * @param boolean $hard |
||
82 | * @return void |
||
83 | */ |
||
84 | public function clearAllCachesCommand($hard = false) { |
||
90 | |||
91 | /** |
||
92 | * Clear system cache. |
||
93 | * |
||
94 | * @return void |
||
95 | */ |
||
96 | public function clearSystemCacheCommand() { |
||
102 | |||
103 | /** |
||
104 | * Clears the opcode cache. |
||
105 | * |
||
106 | * @param string|NULL $fileAbsPath The file as absolute path to be cleared |
||
107 | * or NULL to clear completely. |
||
108 | * |
||
109 | * @return void |
||
110 | */ |
||
111 | public function clearAllActiveOpcodeCacheCommand($fileAbsPath = NULL) { |
||
124 | |||
125 | /** |
||
126 | * Clear configuration cache (temp_CACHED_..). |
||
127 | * |
||
128 | * @return void |
||
129 | */ |
||
130 | public function clearConfigurationCacheCommand() { |
||
136 | |||
137 | /** |
||
138 | * Clear page cache. |
||
139 | * |
||
140 | * @return void |
||
141 | */ |
||
142 | public function clearPageCacheCommand() { |
||
148 | |||
149 | /** |
||
150 | * Clear all caches except the page cache. |
||
151 | * This is especially useful on big sites when you can't just drop the page cache. |
||
152 | * |
||
153 | * @return void |
||
154 | */ |
||
155 | public function clearAllExceptPageCacheCommand() { |
||
161 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.