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 |
||
25 | class RavenHandler extends AbstractProcessingHandler |
||
26 | { |
||
27 | /** |
||
28 | * Translates Monolog log levels to Raven log levels. |
||
29 | */ |
||
30 | private $logLevels = array( |
||
31 | Logger::DEBUG => Raven_Client::DEBUG, |
||
32 | Logger::INFO => Raven_Client::INFO, |
||
33 | Logger::NOTICE => Raven_Client::INFO, |
||
34 | Logger::WARNING => Raven_Client::WARNING, |
||
35 | Logger::ERROR => Raven_Client::ERROR, |
||
36 | Logger::CRITICAL => Raven_Client::FATAL, |
||
37 | Logger::ALERT => Raven_Client::FATAL, |
||
38 | Logger::EMERGENCY => Raven_Client::FATAL, |
||
39 | ); |
||
40 | |||
41 | /** |
||
42 | * @var string should represent the current version of the calling |
||
43 | * software. Can be any string (git commit, version number) |
||
44 | */ |
||
45 | private $release; |
||
46 | |||
47 | /** |
||
48 | * @var Raven_Client the client object that sends the message to the server |
||
49 | */ |
||
50 | protected $ravenClient; |
||
51 | |||
52 | /** |
||
53 | * @var LineFormatter The formatter to use for the logs generated via handleBatch() |
||
54 | */ |
||
55 | protected $batchFormatter; |
||
56 | |||
57 | /** |
||
58 | * @param Raven_Client $ravenClient |
||
59 | * @param int $level The minimum logging level at which this handler will be triggered |
||
60 | * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not |
||
61 | */ |
||
62 | public function __construct(Raven_Client $ravenClient, $level = Logger::DEBUG, $bubble = true) |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function handleBatch(array $records) |
||
106 | |||
107 | /** |
||
108 | * Sets the formatter for the logs generated by handleBatch(). |
||
109 | * |
||
110 | * @param FormatterInterface $formatter |
||
111 | */ |
||
112 | public function setBatchFormatter(FormatterInterface $formatter) |
||
116 | |||
117 | /** |
||
118 | * Gets the formatter for the logs generated by handleBatch(). |
||
119 | * |
||
120 | * @return FormatterInterface |
||
121 | */ |
||
122 | public function getBatchFormatter() |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | protected function write(array $record) |
||
193 | |||
194 | /** |
||
195 | * {@inheritDoc} |
||
196 | */ |
||
197 | protected function getDefaultFormatter() |
||
201 | |||
202 | /** |
||
203 | * Gets the default formatter for the logs generated by handleBatch(). |
||
204 | * |
||
205 | * @return FormatterInterface |
||
206 | */ |
||
207 | protected function getDefaultBatchFormatter() |
||
211 | |||
212 | /** |
||
213 | * Gets extra parameters supported by Raven that can be found in "extra" and "context" |
||
214 | * |
||
215 | * @return array |
||
216 | */ |
||
217 | protected function getExtraParameters() |
||
221 | |||
222 | /** |
||
223 | * @param string $value |
||
224 | * @return self |
||
225 | */ |
||
226 | public function setRelease($value) |
||
232 | } |
||
233 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.