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 |
||
| 26 | class Html |
||
| 27 | { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * An array to hold namespaces. |
||
| 31 | * |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | protected static $_namespaces = []; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * An array to hold method references. |
||
| 38 | * |
||
| 39 | * @var array |
||
| 40 | */ |
||
| 41 | protected static $_registry = []; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Class loader method. |
||
| 45 | * |
||
| 46 | * @param string $key The name of helper method to load, (prefix).(class).function. |
||
| 47 | * @return mixed Result of JHtml::call($function, $args) |
||
| 48 | */ |
||
| 49 | public static function _($key) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Add namespaces list. |
||
| 82 | * |
||
| 83 | * @param string $namespace |
||
| 84 | * @return void |
||
| 85 | */ |
||
| 86 | public static function addNameSpace($namespace) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Clean registered namespaces. |
||
| 93 | * |
||
| 94 | * @return void |
||
| 95 | */ |
||
| 96 | public static function clean() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Get namespaces list. |
||
| 103 | * |
||
| 104 | * @return array |
||
| 105 | */ |
||
| 106 | public static function getNameSpaces() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Registers a function to be called with a specific key. |
||
| 113 | * |
||
| 114 | * @param string $key |
||
| 115 | * @param string $function Function or method |
||
| 116 | * @return bool |
||
| 117 | */ |
||
| 118 | View Code Duplication | public static function register($key, $function) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * Removes a key for a method from registry. |
||
| 131 | * |
||
| 132 | * @param string $key The name of the key |
||
| 133 | * @return boolean True if a set key is unset |
||
| 134 | */ |
||
| 135 | View Code Duplication | public static function unRegister($key) |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Function caller method. |
||
| 148 | * |
||
| 149 | * @param callable $function Function or method to call |
||
| 150 | * @param array $args Arguments to be passed to function |
||
| 151 | * @return mixed Function result or false on error. |
||
| 152 | * @see https://secure.php.net/manual/en/function.call-user-func-array.php |
||
| 153 | * @throws \InvalidArgumentException |
||
| 154 | */ |
||
| 155 | protected static function _call($function, $args) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Check html class exists. |
||
| 168 | * |
||
| 169 | * @param string $className |
||
| 170 | * @return bool |
||
| 171 | */ |
||
| 172 | protected function _classExists($className) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Method to extract a key. |
||
| 188 | * |
||
| 189 | * @param string $key The name of helper method to load, (prefix).(class).function |
||
| 190 | * prefix and class are optional and can be used to load custom html helpers. |
||
| 191 | * @return array |
||
| 192 | */ |
||
| 193 | protected static function _extract($key) |
||
| 204 | } |
||
| 205 |
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: