These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection; |
||
6 | |||
7 | use eZ\Publish\SPI\FieldType\GatewayBasedStorage; |
||
8 | use eZ\Publish\SPI\Persistence\Content\Field; |
||
9 | use eZ\Publish\SPI\Persistence\Content\VersionInfo; |
||
10 | |||
11 | final class EnhancedSelectionStorage extends GatewayBasedStorage |
||
12 | { |
||
13 | public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context): ?bool |
||
14 | { |
||
15 | $this->gateway->deleteFieldData($versionInfo, [$field->id]); |
||
0 ignored issues
–
show
|
|||
16 | if (!empty($field->value->externalData)) { |
||
17 | $this->gateway->storeFieldData($versionInfo, $field); |
||
18 | } |
||
19 | |||
20 | return null; |
||
21 | } |
||
22 | |||
23 | public function getFieldData(VersionInfo $versionInfo, Field $field, array $context): void |
||
24 | { |
||
25 | $this->gateway->getFieldData($versionInfo, $field); |
||
26 | } |
||
27 | |||
28 | public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array $context): bool |
||
29 | { |
||
30 | $this->gateway->deleteFieldData($versionInfo, $fieldIds); |
||
31 | |||
32 | return true; |
||
33 | } |
||
34 | |||
35 | public function hasFieldData(): bool |
||
36 | { |
||
37 | return true; |
||
38 | } |
||
39 | |||
40 | public function getIndexData(VersionInfo $versionInfo, Field $field, array $context) |
||
41 | { |
||
42 | return false; |
||
43 | } |
||
44 | } |
||
45 |
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: