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\View; |
||
| 21 | class ViewComposer |
||
| 22 | { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Runtime cache. |
||
| 26 | * |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | protected $cache = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * The view factory. |
||
| 33 | * |
||
| 34 | * @var Factory |
||
| 35 | */ |
||
| 36 | protected $view; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The agent utility. |
||
| 40 | * |
||
| 41 | * @var Mobile_Detect |
||
| 42 | */ |
||
| 43 | protected $agent; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The event dispatcher. |
||
| 47 | * |
||
| 48 | * @var Dispatcher |
||
| 49 | */ |
||
| 50 | protected $events; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The current theme. |
||
| 54 | * |
||
| 55 | * @var Theme|null |
||
| 56 | */ |
||
| 57 | protected $theme; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The active module. |
||
| 61 | * |
||
| 62 | * @var Module|null |
||
| 63 | */ |
||
| 64 | protected $module; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The addon collection. |
||
| 68 | * |
||
| 69 | * @var AddonCollection |
||
| 70 | */ |
||
| 71 | protected $addons; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The request object. |
||
| 75 | * |
||
| 76 | * @var Request |
||
| 77 | */ |
||
| 78 | protected $request; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The view overrides collection. |
||
| 82 | * |
||
| 83 | * @var ViewOverrides |
||
| 84 | */ |
||
| 85 | protected $overrides; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The application instance. |
||
| 89 | * |
||
| 90 | * @var Application |
||
| 91 | */ |
||
| 92 | protected $application; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The view mobile overrides. |
||
| 96 | * |
||
| 97 | * @var ViewMobileOverrides |
||
| 98 | */ |
||
| 99 | protected $mobiles; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Create a new ViewComposer instance. |
||
| 103 | * |
||
| 104 | * @param Factory $view |
||
| 105 | * @param Mobile_Detect $agent |
||
| 106 | * @param Dispatcher $events |
||
| 107 | * @param AddonCollection $addons |
||
| 108 | * @param ViewOverrides $overrides |
||
| 109 | * @param Request $request |
||
| 110 | * @param ViewMobileOverrides $mobiles |
||
| 111 | * @param Application $application |
||
| 112 | */ |
||
| 113 | public function __construct( |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Compose the view before rendering. |
||
| 142 | * |
||
| 143 | * @param View $view |
||
| 144 | * @return View |
||
| 145 | */ |
||
| 146 | public function compose(View $view) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Get the override view path. |
||
| 165 | * |
||
| 166 | * @param $view |
||
| 167 | * @return null|string |
||
| 168 | */ |
||
| 169 | public function getOverloadPath(View $view) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @param View $view |
||
| 258 | */ |
||
| 259 | protected function setPath(View $view) |
||
| 298 | } |
||
| 299 |