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 |
||
| 34 | class LogEntry extends ObjectAbstract implements LogEntryInterface |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | * @access protected |
||
| 39 | */ |
||
| 40 | protected $channel; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string |
||
| 44 | * @access protected |
||
| 45 | */ |
||
| 46 | protected $message; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var string |
||
| 50 | * @access protected |
||
| 51 | */ |
||
| 52 | protected $level; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var array |
||
| 56 | * @access protected |
||
| 57 | */ |
||
| 58 | protected $context; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var string |
||
| 62 | * @access protected |
||
| 63 | */ |
||
| 64 | protected $formatted; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var float |
||
| 68 | * @access protected |
||
| 69 | */ |
||
| 70 | protected $timestamp; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * is log stopped propagation ? |
||
| 74 | * |
||
| 75 | * @var bool |
||
| 76 | * @access protected |
||
| 77 | */ |
||
| 78 | protected $stopped = false; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Create the log entry |
||
| 82 | * |
||
| 83 | * @param string $channel |
||
| 84 | * @param string $level |
||
| 85 | * @param string $message |
||
| 86 | * @param array $context |
||
| 87 | * @param float $timestamp |
||
| 88 | * @throws InvalidArgumentException if level invalid |
||
| 89 | * @access protected |
||
| 90 | */ |
||
| 91 | public function __construct( |
||
| 105 | |||
| 106 | /** |
||
| 107 | * {@inheritDoc} |
||
| 108 | */ |
||
| 109 | public function setChannel( |
||
| 115 | |||
| 116 | /** |
||
| 117 | * {@inheritDoc} |
||
| 118 | */ |
||
| 119 | public function getChannel()/*# : string */ |
||
| 123 | |||
| 124 | /** |
||
| 125 | * {@inheritDoc} |
||
| 126 | */ |
||
| 127 | public function setMessage( |
||
| 133 | |||
| 134 | /** |
||
| 135 | * {@inheritDoc} |
||
| 136 | */ |
||
| 137 | public function getMessage()/*# : string */ |
||
| 141 | |||
| 142 | /** |
||
| 143 | * {@inheritDoc} |
||
| 144 | */ |
||
| 145 | public function setLevel( |
||
| 157 | |||
| 158 | /** |
||
| 159 | * {@inheritDoc} |
||
| 160 | */ |
||
| 161 | public function getLevel()/*# : string */ |
||
| 165 | |||
| 166 | /** |
||
| 167 | * {@inheritDoc} |
||
| 168 | */ |
||
| 169 | public function setFormatted(/*# string */ $formatted) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * {@inheritDoc} |
||
| 177 | */ |
||
| 178 | public function getFormatted()/*# string */ |
||
| 186 | |||
| 187 | /** |
||
| 188 | * {@inheritDoc} |
||
| 189 | */ |
||
| 190 | public function setTimestamp( |
||
| 196 | |||
| 197 | /** |
||
| 198 | * {@inheritDoc} |
||
| 199 | */ |
||
| 200 | public function getTimestamp()/*# : float */ |
||
| 204 | |||
| 205 | /** |
||
| 206 | * {@inheritDoc} |
||
| 207 | */ |
||
| 208 | public function setContext(array $context) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * {@inheritDoc} |
||
| 216 | */ |
||
| 217 | public function getContext()/*# : array */ |
||
| 221 | |||
| 222 | /** |
||
| 223 | * {@inheritDoc} |
||
| 224 | */ |
||
| 225 | public function stopPropagation(/*# : bool */ $flag = true) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * {@inheritDoc} |
||
| 233 | */ |
||
| 234 | public function isPropagationStopped()/*# : bool */ |
||
| 238 | |||
| 239 | /** |
||
| 240 | * {@inheritDoc} |
||
| 241 | */ |
||
| 242 | public function __toString()/*# : string */ |
||
| 246 | } |
||
| 247 |