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 |
||
7 | class DeleteSnapshotCommand extends Command |
||
8 | { |
||
9 | protected $signature = 'event-projector:delete-snapshot'; |
||
10 | |||
11 | protected $description = 'Delete snapshots'; |
||
12 | |||
13 | /** @var \Illuminate\Support\Collection */ |
||
14 | protected $snapshots; |
||
15 | |||
16 | public function __construct() |
||
20 | |||
21 | public function handle() |
||
43 | |||
44 | View Code Duplication | public function displaySnapshots() |
|
60 | } |
||
61 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: