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 ( e5413e...3eb92c )
by Mario
03:50
created

ConfigurationUtility::isActionAllowedToRun()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace Netgen\InformationCollection\Core\Action;
4
5
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
6
use eZ\Publish\Core\MVC\ConfigResolverInterface;
7
use Netgen\InformationCollection\API\Action\ActionInterface;
8
use OutOfBoundsException;
9
use function sprintf;
10
use function in_array;
11
12
final class ConfigurationUtility
13
{
14
    /**
15
     * @var array
16
     */
17
    private $actionsdConfiguration;
18
19
    /**
20
     * @var array
21
     */
22
    private $singleActionConfiguration;
23
24
    public function __construct(ConfigResolverInterface $configResolver)
25
    {
26
        $this->actionsdConfiguration = $configResolver->getParameter('actions', 'netgen_information_collection');
0 ignored issues
show
Documentation Bug introduced by
It seems like $configResolver->getPara...nformation_collection') of type * is incompatible with the declared type array of property $actionsdConfiguration.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
        $this->singleActionConfiguration = $configResolver->getParameter('action_config', 'netgen_information_collection');
0 ignored issues
show
Documentation Bug introduced by
It seems like $configResolver->getPara...nformation_collection') of type * is incompatible with the declared type array of property $singleActionConfiguration.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28
    }
29
30
    public function isActionAllowedToRun(ActionInterface $action, array $config): bool
31
    {
32
        $identifier = new Identifier($action);
33
34
        if (in_array($identifier->getPrimary(), $config, false)) {
35
            return true;
36
        }
37
38
        if (in_array($identifier->getSecondary(), $config, false)) {
39
            return true;
40
        }
41
42
        return false;
43
    }
44
45
    public function getActionConfiguration(ActionInterface $action): array
46
    {
47
        $identifier = new Identifier($action);
48
49
        if (in_array($identifier->getPrimary(), $this->singleActionConfiguration, false)) {
50
            return $this->singleActionConfiguration[$identifier->getPrimary()];
51
        }
52
53
        if (in_array($identifier->getSecondary(), $this->singleActionConfiguration, false)) {
54
            return $this->singleActionConfiguration[$identifier->getSecondary()];
55
        }
56
57
        throw new OutOfBoundsException(sprintf('There is no configuration available for %s', $identifier->getSecondary()));
58
    }
59
60
    /**
61
     * Returns configuration for given content type identifier if exists
62
     * or default one.
63
     *
64
     * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
65
     *
66
     * @return array
67
     */
68
    public function getConfigPerContentType(ContentType $contentType): array
69
    {
70
        if (!empty($this->actionsdConfiguration['content_types'][$contentType->identifier])) {
71
            return $this->actionsdConfiguration['content_types'][$contentType->identifier];
72
        }
73
74
        if (!empty($this->actionsdConfiguration['default'])) {
75
            return $this->actionsdConfiguration['default'];
76
        }
77
78
        return [];
79
    }
80
}
81