| Conditions | 2 |
| Paths | 2 |
| Total Lines | 11 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | 21 | public function getResult () : Result |
|
| 38 | { |
||
| 39 | // Cache |
||
| 40 | 21 | if ( $this->_Result !== null ) : |
|
| 41 | 11 | return $this->_Result; |
|
| 42 | endif; |
||
| 43 | |||
| 44 | 21 | $this->compute(); |
|
|
1 ignored issue
–
show
|
|||
| 45 | |||
| 46 | 21 | return $this->_Result; |
|
| 47 | } |
||
| 48 | |||
| 62 |
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 sub-classes 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 parent class: