Completed
Push — master ( b1c6ca...52cd2c )
by Kamil
77:57 queued 60:05
created

SyliusUiExtension::loadEvents()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.2088
c 0
b 0
f 0
cc 5
nc 7
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\UiBundle\DependencyInjection;
15
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
20
use Zend\Stdlib\SplPriorityQueue;
21
22
final class SyliusUiExtension extends Extension
23
{
24
    public function load(array $config, ContainerBuilder $container): void
25
    {
26
        $config = $this->processConfiguration($this->getConfiguration([], $container), $config);
0 ignored issues
show
Documentation introduced by
$this->getConfiguration(array(), $container) is of type null|object, but the function expects a object<Symfony\Component...ConfigurationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
28
29
        $loader->load('services.xml');
30
31
        $this->loadEvents($config['events'], $container);
32
    }
33
34
    /**
35
     * @psalm-param array<string, array{blocks: array<string, array{template: string, priority: int, enabled: bool}>}> $eventsConfig
36
     */
37
    private function loadEvents(array $eventsConfig, ContainerBuilder $container): void
38
    {
39
        $templateEventExtensionDefinition = $container->getDefinition('sylius.twig.extension.template_event');
40
41
        $blocksForEvents = [];
42
        foreach ($eventsConfig as $eventName => $eventConfiguration) {
43
            $blocksPriorityQueue = new SplPriorityQueue();
44
45
            foreach ($eventConfiguration['blocks'] as $blockName => $details) {
46
                if (!$details['enabled']) {
47
                    continue;
48
                }
49
50
                $blocksPriorityQueue->insert($details['template'], $details['priority']);
51
            }
52
53
            if ($blocksPriorityQueue->count() === 0) {
54
                continue;
55
            }
56
57
            $blocksForEvents[$eventName] = $blocksPriorityQueue->toArray();
58
        }
59
60
        $templateEventExtensionDefinition->setArgument(1, $blocksForEvents);
61
    }
62
}
63