Completed
Push — admin-api-bundle ( ac2d6a )
by Kamil
22:14
created

SyliusAdminApiExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 9 1
A prepend() 0 21 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\AdminApiBundle\DependencyInjection;
13
14
use Sylius\Bundle\AdminApiBundle\Controller\TokenController;
15
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
20
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
21
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
22
use Symfony\Component\DependencyInjection\Reference;
23
24
/**
25
 * @author Paweł Jędrzejewski <[email protected]>
26
 */
27
final class SyliusAdminApiExtension extends AbstractResourceExtension implements PrependExtensionInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function load(array $config, ContainerBuilder $container)
33
    {
34
        $config = $this->processConfiguration($this->getConfiguration([], $container), $config);
0 ignored issues
show
Documentation introduced by
$this->getConfiguration(array(), $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...
35
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
36
37
        $this->registerResources('sylius', $config['driver'], $config['resources'], $container);
38
39
        $loader->load('services.xml');
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     *
45
     * @throws ServiceNotFoundException
46
     */
47
    public function prepend(ContainerBuilder $container)
48
    {
49
        if (!$container->hasExtension('fos_oauth_server')) {
50
            throw new ServiceNotFoundException('FOSOAuthServerBundle must be registered in kernel.');
51
        }
52
53
        $config = $this->processConfiguration(new Configuration(), $container->getExtensionConfig($this->getAlias()));
54
        $resourcesConfig = $config['resources'];
55
56
        $container->prependExtensionConfig('fos_oauth_server', [
57
            'db_driver' => 'orm',
58
            'client_class' => $resourcesConfig['api_client']['classes']['model'],
59
            'access_token_class' => $resourcesConfig['api_access_token']['classes']['model'],
60
            'refresh_token_class' => $resourcesConfig['api_refresh_token']['classes']['model'],
61
            'auth_code_class' => $resourcesConfig['api_auth_code']['classes']['model'],
62
            'service' => [
63
                'user_provider' => 'sylius.admin_user_provider.email_or_name_based',
64
                'client_manager' => 'sylius.oauth_server.client_manager',
65
            ],
66
        ]);
67
    }
68
}
69