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 |
||
| 13 | class Redirect { |
||
| 14 | /** |
||
| 15 | * Constructor. |
||
| 16 | * |
||
| 17 | * Static-only class, so nothing here. |
||
| 18 | */ |
||
| 19 | private function __construct() {} |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 23 | * so we can bring them directly to their site in calypso. |
||
| 24 | * |
||
| 25 | * @param string $url the full URL. |
||
| 26 | * @return string $url without the guff |
||
| 27 | */ |
||
| 28 | View Code Duplication | private static function build_raw_urls( $url ) { |
|
| 34 | |||
| 35 | /** |
||
| 36 | * Builds and returns an URL using the jetpack.com/redirect service |
||
| 37 | * |
||
| 38 | * Note to WP.com: Changes to this method must be synced to wpcom |
||
| 39 | * |
||
| 40 | * @param string $source The URL handler registered in the server. |
||
| 41 | * @param array|string $args { |
||
| 42 | * Optional. Additional arguments to build the url. |
||
| 43 | * |
||
| 44 | * @type string $site URL of the site; Default is current site. |
||
| 45 | * @type string $path Additional path to be appended to the URL. |
||
| 46 | * @type string $query Query parameters to be added to the URL. |
||
| 47 | * @type string $anchor Anchor to be added to the URL. |
||
| 48 | * } |
||
| 49 | * |
||
| 50 | * @return string The built URL |
||
| 51 | */ |
||
| 52 | public static function get_url( $source, $args = array() ) { |
||
| 78 | } |
||
| 79 |
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: