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 |
||
15 | class LoggerConfigurationManager |
||
16 | { |
||
17 | use FileUtils, LoggerUtils; |
||
18 | |||
19 | /** |
||
20 | * @var Container ログ設定コンテナ |
||
21 | */ |
||
22 | private $logContainer; |
||
23 | |||
24 | /** |
||
25 | * @var array<string> ログ設定情報 |
||
26 | */ |
||
27 | private $configMap; |
||
28 | |||
29 | /** |
||
30 | * Constructor |
||
31 | */ |
||
32 | public function __construct() |
||
37 | |||
38 | /** |
||
39 | * 設定を読み込む |
||
40 | * @param string $configPath 設定ファイル相対パス |
||
41 | * @throws LoggerException |
||
42 | */ |
||
43 | public function load($configPath) |
||
53 | |||
54 | /** |
||
55 | * ログ設定を返却する |
||
56 | * @return Container ログ設定 |
||
57 | */ |
||
58 | public function getConfig() |
||
62 | |||
63 | /** |
||
64 | * 設定ファイルを読み込む |
||
65 | * @param string $configPath 設定アイル相対パス |
||
66 | * @throws LoggerException |
||
67 | */ |
||
68 | private function loadConfigFile($configPath) |
||
78 | |||
79 | /** |
||
80 | * ログレベルを読み込む |
||
81 | * @throws LoggerException |
||
82 | */ |
||
83 | View Code Duplication | private function loadLogLevel() |
|
97 | |||
98 | /** |
||
99 | * ログ保存先パスを読み込む |
||
100 | * @throws LoggerException |
||
101 | */ |
||
102 | private function loadLogFilePath() |
||
120 | |||
121 | /** |
||
122 | * ログローテートサイクルを読み込む |
||
123 | * @throws LoggerException |
||
124 | */ |
||
125 | View Code Duplication | private function loadRotateCycle() |
|
138 | |||
139 | /** |
||
140 | * ログローテートサイズを読み込む |
||
141 | * @throws LoggerException |
||
142 | */ |
||
143 | View Code Duplication | private function loadRotateSize() |
|
156 | |||
157 | /** |
||
158 | * アプリケーション名を読み込む |
||
159 | */ |
||
160 | private function loadApplicationName() |
||
168 | |||
169 | /** |
||
170 | * ロガーフォーマットを読み込む |
||
171 | */ |
||
172 | private function loadFormat() |
||
182 | |||
183 | /** |
||
184 | * ログローテートサイクルを時間に変換 |
||
185 | * @param string ローテートサイクル |
||
186 | * @return int ローテート時間 |
||
187 | */ |
||
188 | private function cycle2value($cycle) |
||
213 | } |
||
214 |
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.