Completed
Pull Request — master (#3)
by Sullivan
04:18
created

NexyPayboxDirectExtension::processOptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 18
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
3
namespace Nexy\PayboxDirect\Bundle\DependencyInjection;
4
5
use Nexy\PayboxDirect\Paybox;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
11
/**
12
 * @author Sullivan Senechal <[email protected]>
13
 */
14
final class NexyPayboxDirectExtension extends Extension
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function load(array $configs, ContainerBuilder $container)
20
    {
21
        $configuration = new Configuration();
22
        $config = $this->processConfiguration($configuration, $configs);
23
24
        $this->processOptions($config, $container);
25
26
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
27
        $loader->load('sdk.xml');
28
29
        $this->processClient($config, $container);
0 ignored issues
show
Unused Code introduced by
The call to the method Nexy\PayboxDirect\Bundle...ension::processClient() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
30
    }
31
32
    /**
33
     * @param array            $config
34
     * @param ContainerBuilder $container
35
     */
36
    private function processOptions(array $config, ContainerBuilder $container)
37
    {
38
        // Start with client option
39
        $options = $config['client'];
40
41
        // Paybox version and devise special hack: Get the number.
42
        $options['paybox_version'] = Paybox::VERSIONS[$config['paybox']['version']];
43
        unset($config['paybox']['version']);
44
        $options['paybox_devise'] = Paybox::DEVISES[$config['paybox']['devise']];
45
        unset($config['paybox']['devise']);
46
47
        // Convert paybox option format
48
        foreach ($config['paybox'] as $key => $value) {
49
            $options['paybox_'.$key] = $value;
50
        }
51
52
        $container->setParameter('nexy_paybox_direct.options', $options);
53
    }
54
55
    /**
56
     * @param array            $config
57
     * @param ContainerBuilder $container
58
     */
59
    private function processClient(array $config, ContainerBuilder $container)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
        // Define http_client_* as private services and set the nexy_paybox_direct.http_client_default one
62
    }
63
}
64