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 ( 36acbf )
by Mario
11:02
created

ActionRegistry::prepareActions()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\Core\Action;
6
7
use function in_array;
8
use Netgen\InformationCollection\API\Action\ActionInterface;
9
use Netgen\InformationCollection\API\Action\CrucialActionInterface;
10
use Netgen\InformationCollection\API\Exception\ActionFailedException;
11
use Netgen\InformationCollection\API\Priority;
12
use Netgen\InformationCollection\API\Value\Event\InformationCollected;
13
use eZ\Publish\Core\MVC\ConfigResolverInterface;
14
use Psr\Log\LoggerInterface;
15
use function usort;
16
17
class ActionRegistry implements ActionInterface
18
{
19
    /**
20
     * @var \eZ\Publish\Core\MVC\ConfigResolverInterface
21
     */
22
    protected $configResolver;
23
24
    /**
25
     * @var array
26
     */
27
    protected $actions;
28
29
    /**
30
     * @var \Psr\Log\LoggerInterface
31
     */
32
    protected $logger;
33
34
    /**
35
     * @var bool
36
     */
37
    protected $debug = false;
38
39
    /**
40
     * ActionAggregate constructor.
41
     *
42
     * @param array $config
0 ignored issues
show
Documentation introduced by
There is no parameter named $config. Did you maybe mean $configResolver?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
43
     * @param LoggerInterface $logger
44
     */
45
    public function __construct(iterable $actions, ConfigResolverInterface $configResolver, LoggerInterface $logger)
46
    {
47
        $this->actions = $actions;
48
        $this->configResolver = $configResolver;
49
        $this->config = $configResolver->getParameter('actions', 'netgen_information_collection');
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean configResolver?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
50
        $this->logger = $logger;
51
    }
52
53
    public function act(InformationCollected $event): void
54
    {
55
        $config = $this->prepareConfig($event->getContentType()->identifier);
56
57
        foreach ($this->actions as $action) {
58
            if ($this->canActionAct($action, $config)) {
59
                try {
60
                    $action->act($event);
61
                } catch (ActionFailedException $e) {
62
                    $this->logger
63
                        ->error($e->getMessage());
64
65
                    if ($this->debug) {
66
                        throw $e;
67
                    }
68
69
                    if ($action instanceof CrucialActionInterface) {
70
                        break;
71
                    }
72
                }
73
            }
74
        }
75
    }
76
77
    /**
78
     * Sets debug variable based on kernel.debug param.
79
     *
80
     * @param bool $debug
81
     */
82
    public function setDebug($debug)
83
    {
84
        $this->debug = $debug;
85
    }
86
87
    /**
88
     * Check if given action can act.
89
     *
90
     * @param ActionInterface $action
91
     * @param array $config
92
     *
93
     * @return bool
94
     */
95
    protected function canActionAct(ActionInterface $action, array $config): bool
96
    {
97
        return in_array(get_class($action), $config, true);
98
    }
99
100
    /**
101
     * Returns configuration for given content type identifier if exists
102
     * or default one.
103
     *
104
     * @param string $contentTypeIdentifier
105
     *
106
     * @return array
107
     */
108
    protected function prepareConfig($contentTypeIdentifier): array
109
    {
110
        if (!empty($this->config['content_types'][$contentTypeIdentifier])) {
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean configResolver?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
111
            return $this->config['content_types'][$contentTypeIdentifier];
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean configResolver?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
112
        }
113
114
        if (!empty($this->config['default'])) {
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean configResolver?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
115
            return $this->config['default'];
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean configResolver?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
116
        }
117
118
        return [];
119
    }
120
}
121