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 |
||
26 | class PurgeListener extends AccessControlledListener |
||
27 | { |
||
28 | const DEFAULT_PURGE_METHOD = 'PURGE'; |
||
29 | |||
30 | const DEFAULT_CLEAR_CACHE_HEADER = 'Clear-Cache'; |
||
31 | |||
32 | /** |
||
33 | * The purge method to use. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | private $purgeMethod; |
||
38 | |||
39 | /** |
||
40 | * The clear cache header to use. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | private $clearCacheHeader; |
||
45 | |||
46 | 8 | /** |
|
47 | * When creating the purge listener, you can configure an additional option. |
||
48 | 8 | * |
|
49 | * - purge_method: HTTP method that identifies purge requests. |
||
50 | 6 | * |
|
51 | 6 | * @param array $options Options to overwrite the default options |
|
52 | * |
||
53 | * @throws \InvalidArgumentException if unknown keys are found in $options |
||
54 | * |
||
55 | * @see AccessControlledListener::__construct |
||
56 | 1 | */ |
|
57 | public function __construct(array $options = []) |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public static function getSubscribedEvents() |
||
75 | |||
76 | /** |
||
77 | 4 | * Look at unsafe requests and handle purge requests. |
|
78 | 2 | * |
|
79 | * Prevents access when the request comes from a non-authorized client. |
||
80 | 2 | * |
|
81 | * @param CacheEvent $event |
||
82 | */ |
||
83 | 2 | public function handlePurge(CacheEvent $event) |
|
124 | |||
125 | /** |
||
126 | * Add the purge_method option. |
||
127 | * |
||
128 | * @return OptionsResolver |
||
129 | */ |
||
130 | View Code Duplication | protected function getOptionsResolver() |
|
140 | } |
||
141 |
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.