| 1 | <?php |
||
| 15 | class MenuItem |
||
| 16 | { |
||
| 17 | |||
| 18 | use MethodPropertyAccess, ObjectOptions; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $label; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $link; |
||
| 29 | |||
| 30 | |||
| 31 | /** |
||
| 32 | * MenuItem constructor. |
||
| 33 | * |
||
| 34 | * @param $label |
||
| 35 | * @param $link |
||
| 36 | * @param array $options |
||
| 37 | */ |
||
| 38 | public function __construct($label, $link, array $options = [ ]) |
||
| 48 | |||
| 49 | |||
| 50 | /** |
||
| 51 | * Return this menu item's label. |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | public function label() |
||
| 59 | |||
| 60 | |||
| 61 | /** |
||
| 62 | * Return this menu item's link. |
||
| 63 | * |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function link() |
||
| 70 | |||
| 71 | |||
| 72 | /** |
||
| 73 | * Return this menu item's weight. |
||
| 74 | * |
||
| 75 | * @return int |
||
|
1 ignored issue
–
show
|
|||
| 76 | */ |
||
| 77 | public function weight() |
||
| 81 | |||
| 82 | |||
| 83 | /** |
||
| 84 | * Mark this menu item as the currently active one. |
||
| 85 | * |
||
| 86 | * @param string $class |
||
| 87 | * |
||
| 88 | * @return $this |
||
| 89 | */ |
||
| 90 | public function active($class = 'active') |
||
| 96 | } |
||
| 97 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: