Conditions | 2 |
Paths | 2 |
Total Lines | 9 |
Code Lines | 5 |
Lines | 0 |
Ratio | 0 % |
Tests | 5 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
22 | 8 | public function build($parameters = []) |
|
23 | { |
||
24 | 8 | $text = $this->app->makeWith(Text::class, $this->mergeParameters($parameters)); |
|
|
|||
25 | 8 | if (array_key_exists('displayRule', $this->parameters)) { |
|
26 | 8 | $text->setDisplayRule($this->parameters['displayRule']); |
|
27 | } |
||
28 | |||
29 | 8 | return $text; |
|
30 | } |
||
31 | |||
46 | } |
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: