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 |
||
12 | trait LoggerUtils |
||
13 | { |
||
14 | /** |
||
15 | * デフォルトロガーフォーマッタ |
||
16 | * @return string デフォルトロガーフォーマッタ |
||
17 | */ |
||
18 | public function defaultLoggerFormatter() |
||
22 | |||
23 | /** |
||
24 | * デフォルトDateTimeフォーマッタ |
||
25 | * @return string デフォルトDateTimeフォーマッタ |
||
26 | */ |
||
27 | public function defaultDateTimeFormatter() |
||
31 | |||
32 | /** |
||
33 | * ログメッセージにスタックトレースの内容を追加する |
||
34 | * @param string ログメッセージ |
||
35 | * @param string スタックトレース文字列 |
||
36 | * @return string 加工済みログメッセージ |
||
37 | */ |
||
38 | public function addStackTrace($msg, $stacktrace) |
||
52 | |||
53 | /** |
||
54 | * ログレベルを数値に変換 |
||
55 | * ログレベルはWebStream独自、PSR-3両方対応 |
||
56 | * @param string ログレベル文字列 |
||
57 | * @throws LoggerException |
||
58 | * @return int ログレベル数値 |
||
59 | */ |
||
60 | View Code Duplication | public function toLogLevelValue(string $level) |
|
86 | } |
||
87 |
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.