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 |
||
| 11 | View Code Duplication | class JobEvent extends AbstractEvent implements PushViaWebsocket |
|
| 12 | { |
||
| 13 | use JsonSerializableTrait; |
||
| 14 | |||
| 15 | const ADDED = 'message_queue.added'; |
||
| 16 | const HANDLED = 'message_queue.handled'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var Job |
||
| 20 | */ |
||
| 21 | private $job; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param string $type |
||
| 25 | * @param Job $job |
||
| 26 | */ |
||
| 27 | 3 | public function __construct(string $type, Job $job) |
|
| 28 | { |
||
| 29 | 3 | parent::__construct($type); |
|
| 30 | 3 | $this->job = $job; |
|
| 31 | 3 | } |
|
| 32 | |||
| 33 | /** |
||
| 34 | * @return Job |
||
| 35 | */ |
||
| 36 | 1 | public function getJob() : Job |
|
| 40 | } |
||
| 41 |