Completed
Pull Request — master (#16)
by Asmir
28:55 queued 27:32
created

Generate::execute()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 55
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 0
cts 35
cp 0
rs 9.078
c 0
b 0
f 0
cc 4
eloc 30
nc 8
nop 2
crap 20

How to fix   Long Method   

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\Command;
4
5
use GoetasWebservices\SoapServices\SoapClient\Builder\SoapContainerBuilder;
6
use GoetasWebservices\XML\XSDReader\SchemaReader;
7
use GoetasWebservices\Xsd\XsdToPhp\AbstractConverter;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Logger\ConsoleLogger;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class Generate extends Command
16
{
17
    protected function configure()
18
    {
19
        parent::configure();
20
        $this->setName('generate');
21
        $this->setDescription("Convert create all the necessary PHP classes for a SOAP client");
22
        $this->setDefinition([
23
            new InputArgument('config', InputArgument::REQUIRED, 'Config file location'),
24
            new InputArgument('dest-dir', InputArgument::REQUIRED, 'Config file location'),
25
            new InputOption('dest-class', null, InputOption::VALUE_REQUIRED, 'Config file location'),
26
        ]);
27
    }
28
29
    /**
30
     * @param InputInterface $input
31
     * @param OutputInterface $output
32
     * @return int
33
     */
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $logger = new ConsoleLogger($output);
37
        $containerBuilder = new SoapContainerBuilder($input->getArgument('config'), $logger);
38
39
        if ($input->getOption('dest-class')) {
40
            $containerBuilder->setContainerClassName($input->getOption('dest-class'));
41
        }
42
43
        $debugContainer = $containerBuilder->getDebugContainer();
44
        //$debugContainer->set('logger', $logger);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
46
        $wsdlMetadata = $debugContainer->getParameter('goetas_webservices.soap_client.config')['metadata'];
47
48
        /**
49
         * @var $schemaReader SchemaReader
50
         */
51
        $schemaReader = $debugContainer->get('goetas_webservices.xsd2php.schema_reader');
52
        $schemaReader->addKnownSchemaLocation('http://schemas.xmlsoap.org/soap/encoding/', __DIR__ .'/../Resources/schemas/soap-enc.xsd');
53
54
        $schemas = [];
55
        $portTypes = [];
56
        $wsdlReader = $debugContainer->get('goetas_webservices.wsdl2php.wsdl_reader');
57
58
        foreach (array_keys($wsdlMetadata) as $src) {
59
            $definitions = $wsdlReader->readFile($src);
60
            $schemas[] = $definitions->getSchema();
61
            $portTypes = array_merge($portTypes, $definitions->getAllPortTypes());
62
        }
63
64
        $soapReader = $debugContainer->get('goetas_webservices.wsdl2php.soap_reader');
65
        $soapServices = $soapReader->getServices();
66
67
        foreach (['php', 'jms'] as $type) {
68
69
            $converter = $debugContainer->get('goetas_webservices.xsd2php.converter.' . $type);
70
            $wsdlConverter = $debugContainer->get('goetas_webservices.wsdl2php.converter.' . $type);
71
            $items = $wsdlConverter->visitServices($soapServices);
72
            $items = array_merge($items, $converter->convert($schemas));
73
74
            $writer = $debugContainer->get('goetas_webservices.xsd2php.writer.' . $type);
75
            $writer->write($items);
76
        }
77
78
        $containerBuilder->dumpContainerForProd($input->getArgument('dest-dir'), $debugContainer);
79
80
        /**
81
         * @var $clientStubGenerator \GoetasWebservices\SoapServices\SoapClient\StubGeneration\ClientStubGenerator
82
         */
83
        $clientStubGenerator = $debugContainer->get('goetas_webservices.soap_client.stub.client_generator');
84
85
        $classDefinitions = $clientStubGenerator->generate($portTypes);
86
        $classWriter = $debugContainer->get('goetas_webservices.xsd2php.class_writer.php');
87
        $classWriter->write($classDefinitions);
88
    }
89
}
90