1 | <?php declare(strict_types = 1); |
||
10 | class SoapClient extends \SoapClient |
||
11 | { |
||
12 | |||
13 | /** @var CryptographyService */ |
||
14 | private $cryptoService; |
||
15 | |||
16 | /** @var SoapClientDriver */ |
||
17 | private $clientDriver; |
||
18 | |||
19 | 1 | public function __construct(string $wsdl, CryptographyService $cryptoService, SoapClientDriver $clientDriver) |
|
32 | |||
33 | /** |
||
34 | * @param mixed[] $parameters |
||
35 | * @return mixed |
||
36 | */ |
||
37 | 1 | public function OdeslaniTrzby(array $parameters) |
|
41 | |||
42 | /** |
||
43 | * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint |
||
44 | * |
||
45 | * @param string $request |
||
46 | * @param string $location |
||
47 | * @param string $action |
||
48 | * @param int $version |
||
49 | * @param int $oneWay |
||
50 | * @return string|null |
||
51 | */ |
||
52 | 1 | public function __doRequest($request, $location, $action, $version, $oneWay = 0): ?string |
|
62 | |||
63 | } |
||
64 |
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: