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 |
||
10 | class MonologHandlerFactory |
||
11 | { |
||
12 | /** |
||
13 | * Returns an instance of \Monolog\Handler\HandlerInterface |
||
14 | * @param string $name Then name of the handler you want to create |
||
15 | * @param array $config An array of config values to use |
||
16 | * @param string $title |
||
17 | * @return \Monolog\Handler\HandlerInterface |
||
18 | */ |
||
19 | 39 | public static function create($name, array $config = [], $title = null){ |
|
35 | |||
36 | /** |
||
37 | * Returns a PushoverHandler |
||
38 | * @param array $config An array of config values to use |
||
39 | * @param string $title The title/subject to use |
||
40 | * @return \Monolog\Handler\PushoverHandler |
||
41 | */ |
||
42 | 12 | protected static function pushover(array $config = [], $title = null){ |
|
70 | |||
71 | /** |
||
72 | * Returns a PushoverHandler |
||
73 | * @param array $config An array of config values to use |
||
74 | * @param string $title The title/subject to use |
||
75 | * @return \Tylercd100\Monolog\Handler\MailgunHandler |
||
76 | */ |
||
77 | 6 | protected static function mailgun(array $config = [], $title = null){ |
|
101 | |||
102 | /** |
||
103 | * Returns a FlowdockHandler |
||
104 | * @param array $config An array of config values to use |
||
105 | * @param string $title The title/subject to use |
||
106 | * @return \Monolog\Handler\FlowdockHandler |
||
107 | */ |
||
108 | 3 | View Code Duplication | protected static function flowdock(array $config = [], $title = null){ |
121 | |||
122 | /** |
||
123 | * Returns a FleepHookHandler |
||
124 | * @param array $config An array of config values to use |
||
125 | * @param string $title The title/subject to use |
||
126 | * @return \Monolog\Handler\FleepHookHandler |
||
127 | */ |
||
128 | 3 | View Code Duplication | protected static function fleephook(array $config = [], $title = null){ |
141 | |||
142 | /** |
||
143 | * Returns a PlivoHandler |
||
144 | * @param array $config An array of config values to use |
||
145 | * @param string $title The title/subject to use |
||
146 | * @return \Tylercd100\Monolog\Handler\PlivoHandler |
||
147 | */ |
||
148 | 3 | View Code Duplication | protected static function plivo(array $config = [], $title = null){ |
172 | |||
173 | /** |
||
174 | * Returns a TwilioHandler |
||
175 | * @param array $config An array of config values to use |
||
176 | * @param string $title The title/subject to use |
||
177 | * @return \Tylercd100\Monolog\Handler\TwilioHandler |
||
178 | */ |
||
179 | 3 | View Code Duplication | protected static function twilio(array $config = [], $title = null){ |
203 | |||
204 | /** |
||
205 | * Returns a RavenHandler |
||
206 | * @param array $config An array of config values to use |
||
207 | * @param string $title The title/subject to use |
||
208 | * @return \Monolog\Handler\RavenHandler |
||
209 | */ |
||
210 | 3 | protected static function raven(array $config = [], $title = null){ |
|
225 | |||
226 | /** |
||
227 | * Returns a SlackHandler |
||
228 | * @param array $config An array of config values to use |
||
229 | * @param string $title The title/subject to use |
||
230 | * @return \Monolog\Handler\SlackHandler |
||
231 | */ |
||
232 | 9 | protected static function slack(array $config = [], $title = null){ |
|
256 | |||
257 | /** |
||
258 | * Returns a HipChatHandler |
||
259 | * @param array $config An array of config values to use |
||
260 | * @param string $title The title/subject to use |
||
261 | * @return \Monolog\Handler\HipChatHandler |
||
262 | */ |
||
263 | 9 | protected static function hipchat(array $config = [], $title = null){ |
|
289 | |||
290 | /** |
||
291 | * Creates Mail Monolog Handler |
||
292 | * @param array $config An array of config values to use |
||
293 | * @param string $title The title/subject to use |
||
294 | * @return \Monolog\Handler\MailHandler |
||
295 | */ |
||
296 | 12 | protected static function mail(array $config = [], $title = null) |
|
304 | |||
305 | /** |
||
306 | * Creates Mail Monolog Handler |
||
307 | * @param array $config An array of config values to use |
||
308 | * @param string $title The title/subject to use |
||
309 | * @return \Monolog\Handler\SwiftMailerHandler |
||
310 | */ |
||
311 | 9 | protected static function swiftMail(array $config, $title = null) |
|
329 | |||
330 | /** |
||
331 | * Creates Mail Monolog Handler |
||
332 | * @param array $config An array of config values to use |
||
333 | * @param string $title The title/subject to use |
||
334 | * @return \Monolog\Handler\NativeMailerHandler |
||
335 | */ |
||
336 | 3 | protected static function nativeMail(array $config, $title = null) |
|
357 | } |
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.