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 |
||
13 | class ViewRenderFile2 implements |
||
14 | ViewRenderFileInterface, |
||
15 | ConfigureInterface, |
||
16 | InjectionAwareInterface |
||
17 | { |
||
18 | use ConfigureTrait, |
||
19 | InjectionAwareTrait; |
||
20 | |||
21 | |||
22 | |||
23 | /** |
||
24 | * Render the view file. |
||
25 | * |
||
26 | * @param string $file to include as view file. |
||
27 | * @param array $data to expose within the view. |
||
28 | * |
||
29 | * @throws \Anax\View\Exception when template file is not found. |
||
30 | * |
||
31 | * @return void |
||
32 | * |
||
33 | * @SuppressWarnings(PHPMD.UnusedLocalVariable) |
||
34 | */ |
||
35 | View Code Duplication | public function render($file, $data) |
|
46 | |||
47 | |||
48 | |||
49 | /** |
||
50 | * TODO: Remove when updating oophp to new view classes. Its here for |
||
51 | * backward compability with views from oophp that used the trait |
||
52 | * ViewHelperTrait for view helpers which is now obsolete. |
||
53 | */ |
||
54 | public function asset($url = "") |
||
58 | |||
59 | public function url($url = "") |
||
63 | |||
64 | public function renderView($template, $data = []) |
||
68 | |||
69 | public function regionHasContent($region) |
||
73 | |||
74 | public function renderRegion($region) |
||
78 | |||
79 | public function classList(...$args) |
||
83 | |||
84 | public function currentUrl() |
||
88 | |||
89 | public function currentRoute() |
||
93 | } |
||
94 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.