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 |
||
14 | class RedisRestart implements RestartInterface |
||
15 | { |
||
16 | /** @var string */ |
||
17 | private $key; |
||
18 | |||
19 | /** @var \Predis\Client|\Redis */ |
||
20 | private $redis; |
||
21 | |||
22 | public function __construct($redis, string $key = 'hermes_restart') |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | * |
||
35 | * Returns true: |
||
36 | * |
||
37 | * - if restart timestamp is set, |
||
38 | * - and timestamp is not in future, |
||
39 | * - and hermes was started ($startTime) before timestamp |
||
40 | */ |
||
41 | public function shouldRestart(DateTime $startTime): bool |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | * |
||
66 | * Sets to Redis value `$restartTime` (or current DateTime) to `$key` defined in constructor. |
||
67 | */ |
||
68 | View Code Duplication | public function restart(DateTime $restartTime = null): bool |
|
76 | } |
||
77 |
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.