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 |
||
| 31 | trait OrderByTrait |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * {@inheritDoc} |
||
| 35 | */ |
||
| 36 | public function orderBy($col) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritDoc} |
||
| 43 | */ |
||
| 44 | public function orderByDesc($col) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritDoc} |
||
| 51 | */ |
||
| 52 | public function orderByTpl(/*# string */ $template, $col) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritDoc} |
||
| 59 | */ |
||
| 60 | public function orderByRaw(/*# string */ $rawString) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param string|string[] $col |
||
| 67 | * @param string $suffix 'ASC' or 'DESC' |
||
| 68 | * @param bool $rawMode |
||
| 69 | * @return $this |
||
| 70 | * @access protected |
||
| 71 | */ |
||
| 72 | View Code Duplication | protected function realOrderBy( |
|
| 85 | |||
| 86 | /** |
||
| 87 | * Multitple orderbys |
||
| 88 | * |
||
| 89 | * @param array $cols |
||
| 90 | * @param string $suffix 'ASC' or 'DESC' |
||
| 91 | * @access protected |
||
| 92 | */ |
||
| 93 | protected function multipleOrderBy(array $cols, /*# sting */ $suffix) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Build ORDER BY |
||
| 102 | * |
||
| 103 | * @param array $settings |
||
| 104 | * @return string |
||
| 105 | * @access protected |
||
| 106 | */ |
||
| 107 | protected function buildOrderby(array $settings)/*# : string */ |
||
| 118 | |||
| 119 | abstract protected function isRaw($str, /*# bool */ $rawMode)/*# : bool */; |
||
| 128 | } |
||
| 129 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: