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 |
||
| 7 | class NavbarPresenter extends Presenter |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * {@inheritdoc }. |
||
| 11 | */ |
||
| 12 | 1 | public function getOpenTagWrapper() |
|
| 16 | |||
| 17 | /** |
||
| 18 | * {@inheritdoc }. |
||
| 19 | */ |
||
| 20 | 1 | public function getCloseTagWrapper() |
|
| 24 | |||
| 25 | /** |
||
| 26 | * {@inheritdoc }. |
||
| 27 | */ |
||
| 28 | public function getMenuWithoutDropdownWrapper($item) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritdoc }. |
||
| 35 | */ |
||
| 36 | public function getActiveState($item, $state = ' class="active"') |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get active state on child items. |
||
| 43 | * |
||
| 44 | * @param $item |
||
| 45 | * @param string $state |
||
| 46 | * |
||
| 47 | * @return null|string |
||
| 48 | */ |
||
| 49 | public function getActiveStateOnChild($item, $state = 'active') |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc }. |
||
| 56 | */ |
||
| 57 | public function getDividerWrapper() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc }. |
||
| 64 | */ |
||
| 65 | public function getHeaderWrapper($item) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritdoc }. |
||
| 72 | */ |
||
| 73 | View Code Duplication | public function getMenuWithDropDownWrapper($item) |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Get multilevel menu wrapper. |
||
| 89 | * |
||
| 90 | * @param \Nwidart\Menus\MenuItem $item |
||
| 91 | * |
||
| 92 | * @return string` |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function getMultiLevelDropdownWrapper($item) |
|
| 107 | } |
||
| 108 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.