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 |
||
| 19 | class Jobs extends Base implements Iface |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Executes the command |
||
| 23 | * |
||
| 24 | * @param array $argv Associative array from $_SERVER['argv'] |
||
|
|
|||
| 25 | */ |
||
| 26 | public static function usage() |
||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * Returns the command usage and options |
||
| 34 | * |
||
| 35 | * @return string Command usage and options |
||
| 36 | */ |
||
| 37 | public static function run( array $argv ) |
||
| 59 | |||
| 60 | |||
| 61 | /** |
||
| 62 | * Returns the configuration based on the given options |
||
| 63 | * |
||
| 64 | * @param array $options Associative list of given options |
||
| 65 | * @return array Multi-dimensional array of configuration settings |
||
| 66 | */ |
||
| 67 | protected static function getConfig( array $options ) |
||
| 83 | |||
| 84 | |||
| 85 | /** |
||
| 86 | * Returns a new context object |
||
| 87 | * |
||
| 88 | * @param \Interop\Container\ContainerInterface $container Dependency injection container |
||
| 89 | * @return \Aimeos\MShop\Context\Item\Standard Context object |
||
| 90 | */ |
||
| 91 | protected static function getContext( \Interop\Container\ContainerInterface $container ) |
||
| 113 | |||
| 114 | |||
| 115 | /** |
||
| 116 | * Removes the cached data for the given sites |
||
| 117 | * |
||
| 118 | * @param \Aimeos\Bootstrap $aimeos Aimeos bootstrap object |
||
| 119 | * @param \Aimeos\MShop\Context\Item\Iface $ctx Context object |
||
| 120 | * @param array $siteItems List of site items implementing \Aimeos\MShop\Locale\Site\Iface |
||
| 121 | */ |
||
| 122 | protected static function execute( \Aimeos\Bootstrap $aimeos, \Aimeos\MShop\Context\Item\Iface $ctx, array $siteItems, $jobs ) |
||
| 138 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.