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 |
||
| 14 | class Util |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Symfony\Component\Filesystem. |
||
| 18 | * |
||
| 19 | * @var Filesystem |
||
| 20 | */ |
||
| 21 | protected static $fs; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Return Symfony\Component\Filesystem instance. |
||
| 25 | * |
||
| 26 | * @return Filesystem |
||
| 27 | */ |
||
| 28 | public static function getFS() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Runs a Git command on the repository. |
||
| 39 | * |
||
| 40 | * @param string $command The command. |
||
| 41 | * |
||
| 42 | * @throws \RuntimeException If the command failed. |
||
| 43 | * |
||
| 44 | * @return string The trimmed output from the command. |
||
| 45 | */ |
||
| 46 | public static function runGitCommand($command) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Sort array items by date. |
||
| 68 | * |
||
| 69 | * @param $a |
||
| 70 | * @param $b |
||
| 71 | * |
||
| 72 | * @return int |
||
| 73 | */ |
||
| 74 | View Code Duplication | public static function sortByDate($a, $b) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Checks if a date is valid. |
||
| 91 | * |
||
| 92 | * @param string $date |
||
| 93 | * @param string $format |
||
| 94 | * |
||
| 95 | * @return bool |
||
| 96 | */ |
||
| 97 | public static function dateIsValid(string $date, string $format = 'Y-m-d'): bool |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Date to DateTime. |
||
| 106 | * |
||
| 107 | * @param mixed $date |
||
| 108 | * |
||
| 109 | * @return \DateTime |
||
| 110 | */ |
||
| 111 | public static function dateToDatetime($date): \DateTime |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Format class name. |
||
| 129 | * |
||
| 130 | * @param \object $class |
||
| 131 | * @param array $options |
||
| 132 | * |
||
| 133 | * @return string |
||
| 134 | */ |
||
| 135 | public static function formatClassName($class, array $options = []): string |
||
| 147 | |||
| 148 | /** |
||
| 149 | * search multidimensional array for key and return value. |
||
| 150 | */ |
||
| 151 | public function arraySearchByKey(string $keyVal, array $array) |
||
| 165 | } |
||
| 166 |
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: