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 |
||
| 18 | class FormAwareHook extends Hook |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var FormInterface |
||
| 22 | */ |
||
| 23 | private $form; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | private $templates = []; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param FormInterface $form |
||
| 32 | */ |
||
| 33 | public function __construct(FormInterface $form) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function getFormData() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param FormInterface|string|int $child |
||
| 48 | * @param string|null $type |
||
| 49 | * @param array $options |
||
| 50 | * @return self |
||
| 51 | */ |
||
| 52 | public function formAdd($child, $type = null, array $options = []) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $template |
||
| 67 | * @param array $templateVars |
||
| 68 | * @return self |
||
| 69 | */ |
||
| 70 | View Code Duplication | public function addTemplate($template, $templateVars = []) |
|
| 78 | |||
| 79 | /** |
||
| 80 | * @return array |
||
| 81 | */ |
||
| 82 | public function getTemplates() |
||
| 86 | } |
||
| 87 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.