| Conditions | 1 |
| Paths | 1 |
| Total Lines | 11 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 1 |
| Changes | 0 | ||
| 1 | <?php |
||
| 35 | 8 | public function __construct(Container $container) |
|
| 36 | { |
||
| 37 | 8 | parent::__construct($container); |
|
| 38 | |||
| 39 | 8 | $this->parameters = [ |
|
| 40 | 8 | 'text' => null, |
|
| 41 | 'displayRule' => true, |
||
| 42 | 8 | 'attributes' => $this->app->makeWith(Attributes::class, ['attributes' => []]), |
|
| 43 | 8 | 'view' => $this->getElementConfig(Text::class)['view'], |
|
| 44 | ]; |
||
| 45 | } |
||
| 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: