1 | <?php |
||
14 | class Menu implements MenuContract |
||
15 | { |
||
16 | /** |
||
17 | * @var BuilderContract[] |
||
18 | */ |
||
19 | protected $menuList = []; |
||
20 | |||
21 | /** |
||
22 | * @var Container |
||
23 | */ |
||
24 | protected $container; |
||
25 | |||
26 | /** |
||
27 | * @inheritDoc |
||
28 | */ |
||
29 | 8 | public function __construct(Container $container) |
|
33 | |||
34 | /** |
||
35 | * @inheritDoc |
||
36 | */ |
||
37 | 5 | public function make($name, callable $callback = null, $type = Builder::UL, $attributes = [], $activeAttributes = []) |
|
53 | |||
54 | /** |
||
55 | * @inheritDoc |
||
56 | */ |
||
57 | 4 | public function get($name) |
|
65 | |||
66 | /** |
||
67 | * @inheritDoc |
||
68 | */ |
||
69 | 1 | public function render($name, $view = null) |
|
73 | |||
74 | /** |
||
75 | * @inheritDoc |
||
76 | */ |
||
77 | 3 | public function has($name) |
|
81 | |||
82 | /** |
||
83 | * @inheritDoc |
||
84 | */ |
||
85 | 1 | public function forget($name) |
|
91 | |||
92 | /** |
||
93 | * @inheritDoc |
||
94 | */ |
||
95 | 1 | public function fromArray($name, array $builder) |
|
109 | |||
110 | /** |
||
111 | * @inheritDoc |
||
112 | */ |
||
113 | 1 | public function toArray($name) |
|
121 | } |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: