1 | <?php |
||
2 | |||
3 | namespace VasilDakov\Shipping\Adapter; |
||
4 | |||
5 | use VasilDakov\Shipping\Response; |
||
6 | |||
7 | class DummyAdapter implements AdapterInterface |
||
8 | { |
||
9 | private const NAME = 'Econt'; |
||
10 | |||
11 | public function getName(): string |
||
12 | { |
||
13 | return self::NAME; |
||
14 | } |
||
15 | |||
16 | public function getCountries(): Response\GetCountriesResponse |
||
17 | { |
||
18 | // TODO: Implement getCountries() method. |
||
19 | } |
||
0 ignored issues
–
show
|
|||
20 | |||
21 | public function getCities(array $data) |
||
22 | { |
||
23 | // TODO: Implement getCities() method. |
||
24 | } |
||
0 ignored issues
–
show
The expression
ImplicitReturnNode returns the type null which is incompatible with the return type mandated by VasilDakov\Shipping\Adap...rInterface::getCities() of VasilDakov\Shipping\Response\GetCitiesResponse .
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
![]() |
|||
25 | |||
26 | public function getOffices(array $data) |
||
27 | { |
||
28 | // TODO: Implement getOffices() method. |
||
29 | } |
||
0 ignored issues
–
show
The expression
ImplicitReturnNode returns the type null which is incompatible with the return type mandated by VasilDakov\Shipping\Adap...Interface::getOffices() of VasilDakov\Shipping\Response\GetOfficesResponse .
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
![]() |
|||
30 | |||
31 | public function track(array $data) |
||
32 | { |
||
33 | // TODO: Implement track() method. |
||
34 | } |
||
35 | } |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: