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 |
||
28 | class MenuLinks extends FieldPluginBase implements ContainerFactoryPluginInterface { |
||
29 | use DependencySerializationTrait; |
||
30 | |||
31 | /** |
||
32 | * The menu link tree. |
||
33 | * |
||
34 | * @var \Drupal\Core\Menu\MenuLinkTreeInterface |
||
35 | */ |
||
36 | protected $menuLinkTree; |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function __construct(array $configuration, $pluginId, $pluginDefinition, MenuLinkTreeInterface $menuLinkTree) { |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function resolveValues($value, array $args, ResolveInfo $info) { |
||
72 | |||
73 | } |
||
74 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to 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
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.