GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c65aba...7222f9 )
by Edi
18:11
created

EnhancedSelection/EnhancedSelectionStorage.php (1 issue)

Upgrade to new PHP Analysis Engine

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
It seems like you code against a specific sub-type and not the parent class eZ\Publish\SPI\FieldType\StorageGateway as the method deleteFieldData() does only exist in the following sub-classes of eZ\Publish\SPI\FieldType\StorageGateway: Netgen\Bundle\EnhancedSe...electionStorage\Gateway, Netgen\Bundle\EnhancedSe...Gateway\DoctrineStorage, eZ\Publish\Core\FieldTyp...\KeywordStorage\Gateway, eZ\Publish\Core\FieldTyp...Gateway\DoctrineStorage, eZ\Publish\Core\FieldTyp...e\Gateway\LegacyStorage, eZ\Publish\Core\FieldTyp...LocationStorage\Gateway, eZ\Publish\Core\FieldTyp...Gateway\DoctrineStorage, eZ\Publish\Core\FieldTyp...e\Gateway\LegacyStorage, eZ\Publish\Core\FieldType\User\UserStorage\Gateway, eZ\Publish\Core\FieldTyp...Gateway\DoctrineStorage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

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

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
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