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 |
||
| 10 | class Piwik |
||
| 11 | { |
||
| 12 | use Utils\HtmlInjectorTrait; |
||
| 13 | |||
| 14 | private $options = [ |
||
| 15 | ['trackPageView'], |
||
| 16 | ['enableLinkTracking'], |
||
| 17 | ]; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var int|null The site's ID |
||
| 21 | */ |
||
| 22 | private $siteId = 1; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string|null The Piwik url |
||
| 26 | */ |
||
| 27 | private $piwikUrl; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Constructor.Set the Piwik's url. |
||
| 31 | * |
||
| 32 | * @param string $piwikUrl |
||
| 33 | */ |
||
| 34 | public function __construct($piwikUrl = null) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Set the site's id. |
||
| 43 | * |
||
| 44 | * @param int $siteId |
||
| 45 | * |
||
| 46 | * @return self |
||
| 47 | */ |
||
| 48 | public function siteId($siteId) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Set the piwik url. |
||
| 57 | * |
||
| 58 | * @param string $url |
||
| 59 | * |
||
| 60 | * @return self |
||
| 61 | */ |
||
| 62 | public function piwikUrl($url) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Add an option. |
||
| 76 | * |
||
| 77 | * @param string $name |
||
| 78 | * ... |
||
| 79 | * |
||
| 80 | * @return self |
||
| 81 | */ |
||
| 82 | public function addOption($name) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Execute the middleware. |
||
| 91 | * |
||
| 92 | * @param ServerRequestInterface $request |
||
| 93 | * @param ResponseInterface $response |
||
| 94 | * @param callable $next |
||
| 95 | * |
||
| 96 | * @return ResponseInterface |
||
| 97 | */ |
||
| 98 | View Code Duplication | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Returns the piwik code. |
||
| 111 | * |
||
| 112 | * @return string |
||
| 113 | */ |
||
| 114 | private function getCode() |
||
| 138 | } |
||
| 139 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.