| Conditions | 5 |
| Paths | 16 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 62 | public function getParameters() |
||
| 63 | { |
||
| 64 | $parameters = [ |
||
| 65 | 'ACTIVITE' => $this->activity, |
||
| 66 | 'DATEQ' => $this->date instanceof \DateTime ? $this->date->format('dmYHis') : null, |
||
| 67 | ]; |
||
| 68 | |||
| 69 | if (true === $this->showCountry) { |
||
| 70 | $parameters['PAYS'] = ''; |
||
| 71 | } |
||
| 72 | |||
| 73 | if (method_exists($this, 'getTransactionNumber')) { |
||
| 74 | $parameters['NUMTRANS'] = $this->getTransactionNumber(); |
||
|
|
|||
| 75 | } |
||
| 76 | if (method_exists($this, 'getCallNumber')) { |
||
| 77 | $parameters['NUMAPPEL'] = $this->getCallNumber(); |
||
| 78 | } |
||
| 79 | |||
| 80 | return $parameters; |
||
| 81 | } |
||
| 82 | } |
||
| 83 |
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: