| 1 | <?php declare(strict_types = 1); |
||
| 8 | class SoapClient extends \SoapClient |
||
| 9 | { |
||
| 10 | |||
| 11 | /** @var \SlevomatEET\Cryptography\CryptographyService */ |
||
| 12 | private $cryptoService; |
||
| 13 | |||
| 14 | /** @var \SlevomatEET\Driver\SoapClientDriver */ |
||
| 15 | private $clientDriver; |
||
| 16 | |||
| 17 | 1 | public function __construct(string $wsdl, CryptographyService $cryptoService, SoapClientDriver $clientDriver) |
|
| 30 | |||
| 31 | /** |
||
| 32 | * @param array $parameters |
||
| 33 | * @return mixed |
||
| 34 | */ |
||
| 35 | 1 | public function OdeslaniTrzby(array $parameters) |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @param string $request |
||
| 42 | * @param string $location |
||
| 43 | * @param string $action |
||
| 44 | * @param int $version |
||
| 45 | * @param int $oneWay |
||
| 46 | * @return string|null |
||
| 47 | */ |
||
| 48 | 1 | public function __doRequest($request, $location, $action, $version, $oneWay = 0) |
|
| 58 | |||
| 59 | } |
||
| 60 |
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: