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 |
||
13 | class ThemeManager extends AssetManager |
||
14 | { |
||
15 | const THEME_FOLDER = '_themes'; |
||
16 | const THEME_DEFINITION_FILE = 'stakx-theme.yml'; |
||
17 | |||
18 | private $themeFolderRelative; |
||
19 | private $themeFolder; |
||
20 | private $themeFile; |
||
21 | private $themeData; |
||
22 | private $themeName; |
||
23 | |||
24 | public function __construct($themeName) |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | View Code Duplication | public function refreshItem($filePath) |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function shouldBeTracked($filePath) |
||
72 | { |
||
73 | $isThemeAsset = (substr($filePath, 0, strlen($this->themeFolderRelative)) === $this->themeFolderRelative); |
||
74 | |||
75 | return $isThemeAsset && parent::shouldBeTracked($filePath); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | View Code Duplication | public function createNewItem($filePath) |
|
89 | |||
90 | public function copyFiles() |
||
109 | } |
||
110 |
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.