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 |
||
| 8 | trait MatcherTrait |
||
| 9 | { |
||
| 10 | private $name; |
||
| 11 | private $isBot; |
||
| 12 | private $channels; |
||
| 13 | private $users; |
||
| 14 | private $patterns; |
||
| 15 | |||
| 16 | abstract protected function debug($message, array $context = array()); |
||
| 17 | |||
| 18 | public function matches(Message $message) : array |
||
| 38 | |||
| 39 | protected function matchesIsBot(Message $message) : bool |
||
| 48 | |||
| 49 | View Code Duplication | protected function matchesChannels(Message $message) : bool |
|
| 58 | |||
| 59 | View Code Duplication | protected function matchesUsers(Message $message) : bool |
|
| 68 | |||
| 69 | protected function matchPatterns(Message $message): array |
||
| 81 | |||
| 82 | private function setName($name) |
||
| 86 | |||
| 87 | private function setIsBot($isBot) |
||
| 91 | |||
| 92 | private function setChannels(array $channels) |
||
| 96 | |||
| 97 | private function setUsers(array $users) |
||
| 101 | |||
| 102 | private function setPatterns(array $patterns) |
||
| 106 | } |