Completed
Push — master ( 3f4c76...893664 )
by Asmir
26s queued 11s
created

SoapClientExtension::load()   C

Complexity

Conditions 10
Paths 168

Size

Total Lines 71

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 46
CRAP Score 10

Importance

Changes 0
Metric Value
dl 0
loc 71
ccs 46
cts 46
cp 1
rs 6.3127
c 0
b 0
f 0
cc 10
nc 168
nop 2
crap 10

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace GoetasWebservices\SoapServices\SoapClient\DependencyInjection;
4
5
use Psr\Log\NullLogger;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\Alias;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Definition;
10
use Symfony\Component\DependencyInjection\Extension\Extension;
11
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
12
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
13
14
class SoapClientExtension extends Extension implements PrependExtensionInterface
15 2
{
16
    public function load(array $configs, ContainerBuilder $container)
17 2
    {
18 2
        $config = $this->processConfiguration(new Configuration(), $configs);
19 2
        foreach ($configs as $subConfig) {
20 2
            $config = array_merge($config, $subConfig);
21
        }
22 2
23 2
        $container->setParameter('goetas_webservices.soap_client.config', $config);
24
        $container->setParameter('goetas_webservices.soap_client.unwrap_returns', $config['unwrap_returns']);
25 2
26 2
        $xml = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
27
        $xml->load('services.xml');
28
29 2
30
        $container->setDefinition('logger', new Definition(NullLogger::class));
31 2
32 2
        $definition = $container->getDefinition('goetas_webservices.xsd2php.path_generator.jms.' . $config['path_generator']);
33
        $container->setDefinition('goetas_webservices.xsd2php.path_generator.jms', clone $definition);
34 2
35 2
        $definition = $container->getDefinition('goetas_webservices.xsd2php.path_generator.php.' . $config['path_generator']);
36
        $container->setDefinition('goetas_webservices.xsd2php.path_generator.php', clone $definition);
37
38 2
39 2
        $pathGenerator = $container->getDefinition('goetas_webservices.xsd2php.path_generator.jms');
40
        $pathGenerator->addMethodCall('setTargets', [$config['destinations_jms']]);
41 2
42 2
        $pathGenerator = $container->getDefinition('goetas_webservices.xsd2php.path_generator.php');
43
        $pathGenerator->addMethodCall('setTargets', [$config['destinations_php']]);
44
45 2
46 2
        foreach (['php', 'jms'] as $type) {
47 2
            $converter = $container->getDefinition('goetas_webservices.xsd2php.converter.' . $type);
48 2
            foreach ($config['namespaces'] as $xml => $php) {
49 2
                $converter->addMethodCall('addNamespace', [$xml, self::sanitizePhp($php)]);
50 2
            }
51 2
            foreach ($config['aliases'] as $xml => $data) {
52 2
                foreach ($data as $type => $php) {
53 2
                    $converter->addMethodCall('addAliasMapType', [$xml, $type, self::sanitizePhp($php)]);
54 2
                }
55 2
            }
56
        }
57
58 2
59 2
        $definition = $container->getDefinition('goetas_webservices.xsd2php.naming_convention.' . $config['naming_strategy']);
60
        $container->setDefinition('goetas_webservices.xsd2php.naming_convention', $definition);
61
62
//////////
63 2
64 2
        $metadataGenerator = $container->getDefinition('goetas_webservices.soap_client.metadata.generator');
65 2
        foreach ($config['alternative_endpoints'] as $service => $data) {
66 2
            foreach ($data as $port => $endPoint) {
67 2
                $metadataGenerator->addMethodCall('addAlternativeEndpoint', [$service, $port, $endPoint]);
68 2
            }
69 2
        }
70
        $keys = ['headers', 'parts', 'messages'];
0 ignored issues
show
Unused Code introduced by
$keys is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
71 2
        //$metadataGenerator->addMethodCall('setBaseNs', [array_intersect_key($config, array_combine($keys, $keys))]);
72 2
        $metadataGenerator->addMethodCall('setUnwrap', [$config['unwrap_returns']]);
73
        $metadataGenerator->replaceArgument(1, $config['namespaces']);
74 2
75 2
        $writer = $container->getDefinition('goetas_webservices.soap_client.stub.client_generator');
76
        $writer->addMethodCall('setUnwrap', [$config['unwrap_returns']]);
77
78 2
79
        $forProduction = !!$container->getParameter('goetas_webservices.soap_client.metadata');
80 2
81 2
        $readerName = 'goetas_webservices.soap_client.metadata_loader.' . ($forProduction ? 'array' : 'dev');
82
        $alias = $container->setAlias('goetas_webservices.soap_client.metadata_reader', $readerName);
83 2
        if ($alias instanceof Alias) {
84
            $alias->setPublic(true);
85 2
        }
86
    }
87 2
88
    protected static function sanitizePhp($ns)
89
    {
90 2
        return strtr($ns, '/', '\\');
91
    }
92 2
93
    public function getAlias()
94
    {
95
        return 'soap_client';
96
    }
97
98
    /**
99
     * Allow an extension to prepend the extension configurations.
100 2
     *
101
     * @param ContainerBuilder $container
102 2
     */
103 2
    public function prepend(ContainerBuilder $container)
104
    {
105
        $container->prependExtensionConfig('goetas_soap_client', []);
106
    }
107
}
108