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 namespace Anomaly\Streams\Platform\Addon\Console\Command; |
||
| 15 | class WriteAddonSeeder |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The addon path. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $path; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The addon type. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | private $type; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The addon slug. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | private $slug; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The vendor slug. |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $vendor; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Create a new WriteAddonSeeder instance. |
||
| 48 | * |
||
| 49 | * @param string $path The path |
||
| 50 | * @param string $type The type |
||
| 51 | * @param string $slug The slug |
||
| 52 | * @param string $vendor The vendor |
||
| 53 | * @param StreamCollection $streams The streams |
||
| 54 | */ |
||
| 55 | public function __construct($path, $type, $slug, $vendor, StreamCollection $streams) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Handle the command. |
||
| 66 | * |
||
| 67 | * @param Parser $parser |
||
| 68 | * @param Filesystem $filesystem |
||
| 69 | */ |
||
| 70 | public function handle(Parser $parser, Filesystem $filesystem) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Gets the uses. |
||
| 98 | * |
||
| 99 | * @param string $namespace The namespace |
||
| 100 | * @return Collection The uses. |
||
| 101 | */ |
||
| 102 | View Code Duplication | public function getUses($namespace) |
|
| 113 | |||
| 114 | /** |
||
| 115 | * Gets the calls. |
||
| 116 | * |
||
| 117 | * @return Collection The calls. |
||
| 118 | */ |
||
| 119 | View Code Duplication | public function getCalls() |
|
| 130 | |||
| 131 | /** |
||
| 132 | * Gets the name. |
||
| 133 | * |
||
| 134 | * @param string $slug The slug |
||
| 135 | * @return string The name. |
||
| 136 | */ |
||
| 137 | public function getName($slug) |
||
| 141 | } |
||
| 142 |
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: