Conditions | 1 |
Paths | 1 |
Total Lines | 13 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 1 |
Changes | 0 |
1 | <?php declare(strict_types = 1); |
||
17 | 1 | public function __construct(string $wsdl, CryptographyService $cryptoService, SoapClientDriver $clientDriver) |
|
18 | { |
||
19 | $options = [ |
||
20 | 1 | 'soap_version' => SOAP_1_1, |
|
21 | 1 | 'encoding' => 'UTF-8', |
|
22 | 'trace' => true, |
||
23 | 'exceptions' => true, |
||
24 | 1 | 'cache_wsdl' => WSDL_CACHE_DISK, |
|
25 | ]; |
||
26 | 1 | parent::__construct($wsdl, $options); |
|
|
|||
27 | 1 | $this->cryptoService = $cryptoService; |
|
28 | 1 | $this->clientDriver = $clientDriver; |
|
29 | 1 | } |
|
30 | |||
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: