Passed
Push — master ( 749d1f...eee29c )
by Gerard
02:16
created

GbereSimpleAuthExtension::prepend()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gbere\SimpleAuth\DependencyInjection;
6
7
use Exception;
8
use Symfony\Component\Config\FileLocator;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
11
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
12
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
13
14
class GbereSimpleAuthExtension extends Extension implements PrependExtensionInterface
15
{
16
    /**
17
     * @throws Exception
18
     */
19
    public function load(array $configs, ContainerBuilder $container): void
20
    {
21
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
22
        $loader->load('services.yaml');
23
24
        $configuration = $this->getConfiguration($configs, $container);
25
        $config = $this->processConfiguration($configuration, $configs);
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
Bug introduced by
It seems like $configuration can also be of type null; however, parameter $configuration of Symfony\Component\Depend...:processConfiguration() does only seem to accept Symfony\Component\Config...\ConfigurationInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        $config = $this->processConfiguration(/** @scrutinizer ignore-type */ $configuration, $configs);
Loading history...
26
    }
27
28
    public function prepend(ContainerBuilder $container): void
29
    {
30
        if ('test' === $container->getParameter('kernel.environment')) {
31
            // https://github.com/symfony/symfony/issues/24461#issuecomment-355839669
32
            $extensionConfigsRefl = new \ReflectionProperty(ContainerBuilder::class, 'extensionConfigs');
33
            $extensionConfigsRefl->setAccessible(true);
34
            $extensionConfigs = $extensionConfigsRefl->getValue($container);
35
            $extensionConfigs['security'][0]['access_control'] = array_merge([
36
                ['path' => '^/gbere-auth-test-role-admin', 'role' => 'ROLE_ADMIN'],
37
                ['path' => '^/gbere-auth-test-role-user', 'role' => 'ROLE_USER'], ],
38
                $extensionConfigs['security'][0]['access_control']
39
            );
40
41
            $extensionConfigsRefl->setValue($container, $extensionConfigs);
42
        }
43
    }
44
}
45