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 |
||
| 9 | class Layout |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var \Illuminate\View\View |
||
| 13 | */ |
||
| 14 | public $layout; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var \Illuminate\View\View |
||
| 18 | */ |
||
| 19 | protected $view; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var \Illuminate\Http\Request |
||
| 23 | */ |
||
| 24 | protected $request; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var \Illuminate\Config\Repository |
||
| 28 | */ |
||
| 29 | protected $config; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | protected $layoutOptions; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param \Illuminate\View\Factory $view |
||
| 38 | * @param \Illuminate\Http\Request $request |
||
| 39 | * @param \Illuminate\Config\Repository $config |
||
| 40 | */ |
||
| 41 | public function __construct(Factory $view, Request $request, Repository $config) |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Set up the initial layout to be used. |
||
| 50 | * |
||
| 51 | * @param $layoutOptions |
||
| 52 | * |
||
| 53 | * @return $this |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function setUp($layoutOptions) |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Change the selected layout to something else and ready it for content. |
||
| 67 | * |
||
| 68 | * @param $view |
||
| 69 | * |
||
| 70 | * @return $this |
||
| 71 | */ |
||
| 72 | View Code Duplication | public function change($view) |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Auto determine a logic page title. |
||
| 83 | */ |
||
| 84 | public function setPageTitle() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Determine which layout to use based on the request. |
||
| 100 | * |
||
| 101 | * @param $layout |
||
| 102 | * |
||
| 103 | * @return \Illuminate\Contracts\View\View |
||
| 104 | */ |
||
| 105 | protected function determineLayout($layout) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Make sure that we have a valid set of layout options. |
||
| 128 | * |
||
| 129 | * @param $layoutOptions |
||
| 130 | * |
||
| 131 | * @return mixed |
||
| 132 | */ |
||
| 133 | private function verifyLayoutOptions($layoutOptions) |
||
| 153 | } |
||
| 154 |