Completed
Push — symfony3-fqcn-sylius-3 ( 1d8d47 )
by Kamil
18:35
created

SyliusReviewExtension::resolveResources()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
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
namespace Sylius\Bundle\ReviewBundle\DependencyInjection;
13
14
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
18
19
/**
20
 * @author Mateusz Zalewski <[email protected]>
21
 * @author Grzegorz Sadowski <[email protected]>
22
 */
23
final class SyliusReviewExtension extends AbstractResourceExtension
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function load(array $config, ContainerBuilder $container)
29
    {
30
        $config = $this->processConfiguration($this->getConfiguration($config, $container), $config);
0 ignored issues
show
Documentation introduced by
$this->getConfiguration($config, $container) is of type object|null, 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...
31
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
32
33
        $this->registerResources('sylius', $config['driver'], $this->resolveResources($config['resources'], $container), $container);
34
35
        $loader->load('services.xml');
36
37
        $this->addProperTagToReviewDeleteListener($container);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    private function resolveResources(array $resources, ContainerBuilder $container)
44
    {
45
        $container->setParameter('sylius.review.subjects', $resources);
46
47
        $resolvedResources = [];
48
        foreach ($resources as $subjectName => $subjectConfig) {
49
            foreach ($subjectConfig as $resourceName => $resourceConfig) {
50
                if (is_array($resourceConfig)) {
51
                    $resolvedResources[$subjectName.'_'.$resourceName] = $resourceConfig;
52
                }
53
            }
54
        }
55
56
        return $resolvedResources;
57
    }
58
59
    /**
60
     * @param ContainerBuilder $container
61
     */
62
    private function addProperTagToReviewDeleteListener(ContainerBuilder $container)
63
    {
64
        if (!$container->hasDefinition('sylius.listener.review_delete')) {
65
            return;
66
        }
67
68
        $listenerDefinition = $container->getDefinition('sylius.listener.review_delete');
69
        $listenerDefinition->addTag('doctrine.event_listener', ['event' => 'postRemove', 'method' => 'recalculateSubjectRating']);
70
    }
71
}
72