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 |
||
16 | class Queue |
||
17 | { |
||
18 | private $client; |
||
19 | private $name; |
||
20 | |||
21 | /** |
||
22 | * @param \Tarantool|\Tarantool\Client\Client $client |
||
23 | * @param string $name |
||
24 | * |
||
25 | * @throws \InvalidArgumentException |
||
26 | */ |
||
27 | 163 | public function __construct($client, $name) |
|
41 | |||
42 | /** |
||
43 | * @return string |
||
44 | */ |
||
45 | 1 | public function getName() |
|
49 | |||
50 | /** |
||
51 | * @param mixed $data |
||
52 | * @param array $options |
||
53 | * |
||
54 | * @return Task |
||
55 | */ |
||
56 | 32 | View Code Duplication | public function put($data, array $options = []) |
63 | |||
64 | /** |
||
65 | * @param int|float|null $timeout |
||
66 | * |
||
67 | * @return Task|null |
||
68 | */ |
||
69 | 18 | public function take($timeout = null) |
|
76 | |||
77 | /** |
||
78 | * @param int $taskId |
||
79 | * |
||
80 | * @return Task |
||
81 | */ |
||
82 | 8 | public function ack($taskId) |
|
88 | |||
89 | /** |
||
90 | * @param int $taskId |
||
91 | * @param array $options |
||
92 | * |
||
93 | * @return Task |
||
94 | */ |
||
95 | 10 | View Code Duplication | public function release($taskId, array $options = []) |
102 | |||
103 | /** |
||
104 | * @param int $taskId |
||
105 | * |
||
106 | * @return Task |
||
107 | */ |
||
108 | 12 | public function peek($taskId) |
|
114 | |||
115 | /** |
||
116 | * @param int $taskId |
||
117 | * |
||
118 | * @return Task |
||
119 | */ |
||
120 | 8 | public function bury($taskId) |
|
126 | |||
127 | /** |
||
128 | * @param int $count |
||
129 | * |
||
130 | * @return int |
||
131 | */ |
||
132 | 12 | public function kick($count) |
|
138 | |||
139 | /** |
||
140 | * @param int $taskId |
||
141 | * |
||
142 | * @return Task |
||
143 | */ |
||
144 | 10 | public function delete($taskId) |
|
150 | |||
151 | 8 | public function truncate() |
|
155 | |||
156 | /** |
||
157 | * @param string|null $path |
||
158 | * |
||
159 | * @return array|int |
||
160 | * |
||
161 | * @throws \InvalidArgumentException |
||
162 | */ |
||
163 | 58 | public function stats($path = null) |
|
181 | } |
||
182 |
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.