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 |
||
15 | class RedisSetDriver implements DriverInterface |
||
16 | { |
||
17 | use MaxItemsTrait; |
||
18 | use RestartTrait; |
||
19 | use SerializerAwareTrait; |
||
20 | |||
21 | private $queues = []; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $scheduleKey; |
||
27 | |||
28 | /** |
||
29 | * @var Redis|Client |
||
30 | */ |
||
31 | private $redis; |
||
32 | |||
33 | /** |
||
34 | * @var integer |
||
35 | */ |
||
36 | private $refreshInterval; |
||
37 | |||
38 | /** |
||
39 | * Create new RedisSetDriver |
||
40 | * |
||
41 | * This driver is using redis set. With send message it add new item to set |
||
42 | * and in wait() command it is reading new items in this set. |
||
43 | * This driver doesn't use redis pubsub functionality, only redis sets. |
||
44 | * |
||
45 | * Managing connection to redis is up to you and you have to create it outsite |
||
46 | * of this class. You can use native Redis php extension or Predis extension. |
||
47 | 21 | * |
|
48 | * @see examples/redis |
||
49 | 21 | * |
|
50 | 3 | * @param Redis|Client $redis |
|
51 | * @param string $key |
||
52 | * @param integer $refreshInterval |
||
53 | 18 | * @param string $scheduleKey |
|
54 | 18 | */ |
|
55 | 18 | public function __construct($redis, string $key = 'hermes', int $refreshInterval = 1, string $scheduleKey = 'hermes_schedule') |
|
68 | |||
69 | /** |
||
70 | 6 | * {@inheritdoc} |
|
71 | */ |
||
72 | 6 | public function send(MessageInterface $message, int $priority = Dispatcher::PRIORITY_MEDIUM): bool |
|
82 | 6 | ||
83 | 3 | public function setupPriorityQueue(string $name, int $priority): void |
|
88 | |||
89 | private function getKey(int $priority): string |
||
96 | |||
97 | 4 | /**s |
|
98 | 6 | * {@inheritdoc} |
|
99 | * |
||
100 | * @throws RestartException |
||
101 | */ |
||
102 | public function wait(Closure $callback, array $priorities = []): void |
||
170 | } |
||
171 |
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.