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 |
||
| 9 | class MonologHandlerFactory |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Returns an instance of \Monolog\Handler\HandlerInterface |
||
| 13 | * @param string $name Then name of the handler you want to create |
||
| 14 | * @param array $config An array of config values to use |
||
| 15 | * @param string $title |
||
| 16 | * @return \Monolog\Handler\HandlerInterface |
||
| 17 | */ |
||
| 18 | 36 | public static function create($name, array $config = [], $title = null){ |
|
| 21 | |||
| 22 | /** |
||
| 23 | * Returns a PushoverHandler |
||
| 24 | * @param array $config An array of config values to use |
||
| 25 | * @param string $title The title/subject to use |
||
| 26 | * @return \Monolog\Handler\PushoverHandler |
||
| 27 | */ |
||
| 28 | 12 | protected static function pushover(array $config = [], $title = null){ |
|
| 29 | $defaults = [ |
||
| 30 | 9 | "title" => null, |
|
| 31 | 9 | "level" => Logger::DEBUG, |
|
| 32 | 9 | "bubble" => true, |
|
| 33 | 9 | "useSSL" => true, |
|
| 34 | 9 | "highPriorityLevel" => Logger::CRITICAL, |
|
| 35 | 9 | "emergencyLevel" => Logger::EMERGENCY, |
|
| 36 | 9 | "retry" => 30, |
|
| 37 | "expire" => 25200 |
||
| 38 | 9 | ]; |
|
| 39 | |||
| 40 | 9 | $c = array_merge($defaults,$config); |
|
| 41 | |||
| 42 | 9 | $c['title'] = $title; |
|
| 43 | |||
| 44 | 9 | return new \Monolog\Handler\PushoverHandler( |
|
| 45 | 9 | $c['token'], |
|
| 46 | 9 | $c['users'], |
|
| 47 | 9 | $c['title'], |
|
| 48 | 9 | $c['level'], |
|
| 49 | 9 | $c['bubble'], |
|
| 50 | 9 | $c['useSSL'], |
|
| 51 | 9 | $c['highPriorityLevel'], |
|
| 52 | 12 | $c['emergencyLevel'], |
|
| 53 | 9 | $c['retry'], |
|
| 54 | 9 | $c['expire']); |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Returns a FlowdockHandler |
||
| 59 | * @param array $config An array of config values to use |
||
| 60 | * @param string $title The title/subject to use |
||
| 61 | * @return \Monolog\Handler\FlowdockHandler |
||
| 62 | */ |
||
| 63 | 3 | View Code Duplication | protected static function flowdock(array $config = [], $title = null){ |
|
1 ignored issue
–
show
|
|||
| 64 | $defaults = [ |
||
| 65 | 3 | "level" => Logger::DEBUG, |
|
| 66 | 3 | "bubble" => true, |
|
| 67 | 3 | ]; |
|
| 68 | |||
| 69 | 3 | $c = array_merge($defaults,$config); |
|
| 70 | |||
| 71 | 3 | return new \Monolog\Handler\FlowdockHandler( |
|
| 72 | 3 | $c['token'], |
|
| 73 | 3 | $c['level'], |
|
| 74 | 3 | $c['bubble']); |
|
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Returns a FleepHookHandler |
||
| 79 | * @param array $config An array of config values to use |
||
| 80 | * @param string $title The title/subject to use |
||
| 81 | * @return \Monolog\Handler\FleepHookHandler |
||
| 82 | */ |
||
| 83 | 3 | View Code Duplication | protected static function fleephook(array $config = [], $title = null){ |
|
1 ignored issue
–
show
|
|||
| 84 | $defaults = [ |
||
| 85 | 3 | "level" => Logger::DEBUG, |
|
| 86 | 3 | "bubble" => true, |
|
| 87 | 3 | ]; |
|
| 88 | |||
| 89 | 3 | $c = array_merge($defaults,$config); |
|
| 90 | |||
| 91 | 3 | return new \Monolog\Handler\FleepHookHandler( |
|
| 92 | 3 | $c['token'], |
|
| 93 | 3 | $c['level'], |
|
| 94 | 3 | $c['bubble']); |
|
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Returns a PlivoHandler |
||
| 99 | * @param array $config An array of config values to use |
||
| 100 | * @param string $title The title/subject to use |
||
| 101 | * @return \Tylercd100\Monolog\Handler\PlivoHandler |
||
| 102 | */ |
||
| 103 | 3 | View Code Duplication | protected static function plivo(array $config = [], $title = null){ |
| 127 | |||
| 128 | /** |
||
| 129 | * Returns a TwilioHandler |
||
| 130 | * @param array $config An array of config values to use |
||
| 131 | * @param string $title The title/subject to use |
||
| 132 | * @return \Tylercd100\Monolog\Handler\TwilioHandler |
||
| 133 | */ |
||
| 134 | 3 | View Code Duplication | protected static function twilio(array $config = [], $title = null){ |
| 158 | |||
| 159 | /** |
||
| 160 | * Returns a RavenHandler |
||
| 161 | * @param array $config An array of config values to use |
||
| 162 | * @param string $title The title/subject to use |
||
| 163 | * @return \Monolog\Handler\RavenHandler |
||
| 164 | */ |
||
| 165 | 3 | protected static function raven(array $config = [], $title = null){ |
|
| 180 | |||
| 181 | /** |
||
| 182 | * Returns a SlackHandler |
||
| 183 | * @param array $config An array of config values to use |
||
| 184 | * @param string $title The title/subject to use |
||
| 185 | * @return \Monolog\Handler\SlackHandler |
||
| 186 | */ |
||
| 187 | 9 | protected static function slack(array $config = [], $title = null){ |
|
| 211 | |||
| 212 | /** |
||
| 213 | * Returns a HipChatHandler |
||
| 214 | * @param array $config An array of config values to use |
||
| 215 | * @param string $title The title/subject to use |
||
| 216 | * @return \Monolog\Handler\HipChatHandler |
||
| 217 | */ |
||
| 218 | 9 | protected static function hipchat(array $config = [], $title = null){ |
|
| 244 | |||
| 245 | /** |
||
| 246 | * Creates Mail Monolog Handler |
||
| 247 | * @param array $config An array of config values to use |
||
| 248 | * @param string $title The title/subject to use |
||
| 249 | * @return \Monolog\Handler\MailHandler |
||
| 250 | */ |
||
| 251 | 6 | protected static function mail(array $config = [], $title = null) |
|
| 259 | |||
| 260 | /** |
||
| 261 | * Creates Mail Monolog Handler |
||
| 262 | * @param array $config An array of config values to use |
||
| 263 | * @param string $title The title/subject to use |
||
| 264 | * @return \Monolog\Handler\SwiftMailerHandler |
||
| 265 | */ |
||
| 266 | 3 | protected static function swiftMail(array $config, $title = null) |
|
| 284 | |||
| 285 | /** |
||
| 286 | * Creates Mail Monolog Handler |
||
| 287 | * @param array $config An array of config values to use |
||
| 288 | * @param string $title The title/subject to use |
||
| 289 | * @return \Monolog\Handler\NativeMailerHandler |
||
| 290 | */ |
||
| 291 | 3 | protected static function nativeMail(array $config, $title = null) |
|
| 312 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.