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\Http\Controller; |
||
| 17 | class EntryController extends AdminController |
||
| 18 | { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * The addon collection. |
||
| 22 | * |
||
| 23 | * @var AddonCollection |
||
| 24 | */ |
||
| 25 | protected $addons; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * The stream repository. |
||
| 29 | * |
||
| 30 | * @var StreamRepositoryInterface |
||
| 31 | */ |
||
| 32 | protected $streams; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * The authorizer service. |
||
| 36 | * |
||
| 37 | * @var Authorizer |
||
| 38 | */ |
||
| 39 | protected $authorizer; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The entry repository. |
||
| 43 | * |
||
| 44 | * @var EntryRepositoryInterface |
||
| 45 | */ |
||
| 46 | protected $repository; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Create a new EntryController instance. |
||
| 50 | * |
||
| 51 | * @param AddonCollection $addons |
||
| 52 | * @param Authorizer $authorizer |
||
| 53 | * @param StreamRepositoryInterface $streams |
||
| 54 | * @param EntryRepositoryInterface $repository |
||
| 55 | */ |
||
| 56 | public function __construct( |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Restore an entry. |
||
| 72 | * |
||
| 73 | * @param $addon |
||
| 74 | * @param $namespace |
||
| 75 | * @param $stream |
||
| 76 | * @param $id |
||
| 77 | * @return \Illuminate\Http\RedirectResponse |
||
| 78 | */ |
||
| 79 | public function restore($addon, $namespace, $stream, $id) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Export all entries. |
||
| 114 | * |
||
| 115 | * @param $addon |
||
| 116 | * @param $namespace |
||
| 117 | * @param $stream |
||
| 118 | * @return \Illuminate\Http\RedirectResponse |
||
| 119 | */ |
||
| 120 | public function export($addon, $namespace, $stream) |
||
| 163 | } |
||
| 164 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: