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 PhpQuickProfiler |
||
| 16 | { |
||
| 17 | |||
| 18 | /** @var Particletree\Pqp\Console */ |
||
| 19 | protected $console; |
||
| 20 | |||
| 21 | /** @var integer */ |
||
| 22 | protected $startTime; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param Particletree\Pqp\Console $console |
||
| 26 | * @param integer $startTime |
||
| 27 | */ |
||
| 28 | public function __construct(Console $console, $startTime = null) |
||
| 37 | |||
| 38 | /*------------------------------------------- |
||
| 39 | AGGREGATE DATA ON THE FILES INCLUDED |
||
| 40 | -------------------------------------------*/ |
||
| 41 | |||
| 42 | public function gatherFileData() { |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Get data about memory usage of the application |
||
| 72 | * |
||
| 73 | * @returns array |
||
| 74 | */ |
||
| 75 | public function gatherMemoryData() |
||
| 84 | |||
| 85 | /*-------------------------------------------------------- |
||
| 86 | QUERY DATA -- DATABASE OBJECT WITH LOGGING REQUIRED |
||
| 87 | ----------------------------------------------------------*/ |
||
| 88 | |||
| 89 | public function gatherQueryData() { |
||
| 109 | |||
| 110 | /*-------------------------------------------------------- |
||
| 111 | CALL SQL EXPLAIN ON THE QUERY TO FIND MORE INFO |
||
| 112 | ----------------------------------------------------------*/ |
||
| 113 | |||
| 114 | function attemptToExplainQuery($query) { |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Get data about speed of the application |
||
| 129 | * |
||
| 130 | * @returns array |
||
| 131 | */ |
||
| 132 | public function gatherSpeedData() |
||
| 141 | |||
| 142 | /*------------------------------------------- |
||
| 143 | HELPER FUNCTIONS TO FORMAT DATA |
||
| 144 | -------------------------------------------*/ |
||
| 145 | |||
| 146 | public function getReadableFileSize($size, $retstring = null) { |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Static formatter for human-readable time |
||
| 164 | * Only handles time up to 60 minutes gracefully |
||
| 165 | * |
||
| 166 | * @param integer $time time in seconds |
||
| 167 | * @return string |
||
| 168 | */ |
||
| 169 | View Code Duplication | public static function getReadableTime($time) |
|
| 184 | |||
| 185 | |||
| 186 | /** |
||
| 187 | * Triggers end display of the profiling data |
||
| 188 | * |
||
| 189 | * @param Display $display |
||
| 190 | */ |
||
| 191 | public function display(Display $display) |
||
| 201 | } |
||
| 202 |
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..