DdrGitkiWebExtension::load()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Dontdrinkandroot\Gitki\WebBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
11
class DdrGitkiWebExtension extends Extension implements PrependExtensionInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function load(array $configs, ContainerBuilder $container)
17
    {
18
        $configuration = new Configuration();
19
        $config = $this->processConfiguration($configuration, $configs);
20
21
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
22
        $loader->load('services.yml');
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function prepend(ContainerBuilder $container)
29
    {
30
        $configs = $container->getExtensionConfig($this->getAlias());
31
        $configuration = $this->getConfiguration($configs, $container);
32
        $config = $this->processConfiguration($configuration, $configs);
0 ignored issues
show
Documentation introduced by
$configuration 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...
33
34
        $hwiOauthConfig = [
35
            'resource_owners' => []
36
        ];
37
38
//        $securityConfig = [
39
//            'firewalls' => [
40
//                'secured_area' => [
41
//                    'oauth' => [
42
//                        'resource_owners' => []
43
//                    ]
44
//                ]
45
//            ]
46
//        ];
47
48
//        if (isset($config['authentication']['oauth']['default_provider'])) {
49
//            $securityConfig['firewalls']['secured_area']['oauth']['login_path'] =
50
//                '/connect/' . $config['authentication']['oauth']['default_provider'];
51
//        } else {
52
//            $securityConfig['firewalls']['secured_area']['oauth']['login_path'] = '/login';
53
//        }
54
55
        $formLoginEnabled = true;
56
        if (isset($config['authentication']['form_login_enabled'])) {
57
            $formLoginEnabled = $config['authentication']['form_login_enabled'];
58
        }
59
        $twigConfig['globals']['ddr_gitki_form_login_enabled'] = $formLoginEnabled;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$twigConfig was never initialized. Although not strictly required by PHP, it is generally a good practice to add $twigConfig = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
60
61
        if (isset($config['authentication']['oauth']['providers']['github'])) {
62
            $githubConfig = $config['authentication']['oauth']['providers']['github'];
63
            $hwiOauthConfig['fosub']['properties']['github'] = 'githubId';
64
            $hwiOauthConfig['resource_owners']['github'] = [
65
                'type'          => 'github',
66
                'client_id'     => $githubConfig['client_id'],
67
                'client_secret' => $githubConfig['secret'],
68
                'scope'         => 'user:email'
69
            ];
70
//          $securityConfig['firewalls']['secured_area']['oauth']['resource_owners']['github'] = '/login/check-github';
71
        }
72
73
        if (isset($config['authentication']['oauth']['providers']['google'])) {
74
            $googleConfig = $config['authentication']['oauth']['providers']['google'];
75
            $hwiOauthConfig['fosub']['properties']['google'] = 'googleId';
76
            $hwiOauthConfig['resource_owners']['google'] = [
77
                'type'          => 'google',
78
                'client_id'     => $googleConfig['client_id'],
79
                'client_secret' => $googleConfig['secret'],
80
                'scope'         => 'email profile',
81
                'options'       => [
82
                    'access_type'     => 'online',
83
                    'approval_prompt' => 'auto',
84
                    'display'         => 'page',
85
                    'login_hint'      => 'email address'
86
                ]
87
            ];
88
//          $securityConfig['firewalls']['secured_area']['oauth']['resource_owners']['google'] = '/login/check-google';
89
        }
90
91
//        $container->prependExtensionConfig('security', $securityConfig);
92
        $container->prependExtensionConfig('hwi_oauth', $hwiOauthConfig);
93
        $container->prependExtensionConfig('twig', $twigConfig);
94
    }
95
}
96