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 |
||
| 10 | class ConsoleFileLogger extends CFileLogRoute |
||
| 11 | {
|
||
| 12 | public $showLog = true; |
||
| 13 | |||
| 14 | private $timers = array(); |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var CFileLogRoute $logger |
||
| 18 | */ |
||
| 19 | private $logger; |
||
| 20 | |||
| 21 | public function __construct($fileName) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $message |
||
| 33 | * @param bool $writeNow |
||
| 34 | * @param bool $writeMemoryUsage |
||
| 35 | */ |
||
| 36 | View Code Duplication | public function log($message, $writeNow = false, $writeMemoryUsage = false) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $message |
||
| 52 | * @param bool $writeNow |
||
| 53 | * @param bool $writeMemoryUsage |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function warning($message, $writeNow = false, $writeMemoryUsage = false) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * @param string $message |
||
| 71 | * @param bool $writeNow |
||
| 72 | * @param bool $writeMemoryUsage |
||
| 73 | */ |
||
| 74 | View Code Duplication | public function error($message, $writeNow = true, $writeMemoryUsage = true) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Сохраняет лог в файл с очисткой сообщений из памяти |
||
| 90 | */ |
||
| 91 | public function flush() |
||
| 95 | |||
| 96 | public function __destruct() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Сохраняет лог в файл, сообщения остаются в памяти при прямом вызове метода |
||
| 103 | */ |
||
| 104 | public function onFlush() |
||
| 108 | |||
| 109 | public function addMemoryUsage(&$message) |
||
| 116 | |||
| 117 | public function formatTime($time) |
||
| 121 | |||
| 122 | public function startTimer($timerId) |
||
| 129 | |||
| 130 | public function finishTimer($timerId, $message = '') |
||
| 141 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..