Completed
Push — master ( 030796...0c67b5 )
by Asmir
30:13
created

Generate   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 1
B execute() 0 49 5
1
<?php
2
namespace GoetasWebservices\SoapServices\SoapClient\Command;
3
4
use GoetasWebservices\SoapServices\SoapClient\Builder\SoapContainerBuilder;
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Zend\Code\Generator\FileGenerator;
11
12
class Generate extends Command
13
{
14
    protected function configure()
15
    {
16
        parent::configure();
17
        $this->setName('generate');
18
        $this->setDescription("Convert create all the necessary PHP classes for a SOAP client");
19
        $this->setDefinition([
20
            new InputArgument('config', InputArgument::REQUIRED, 'Config file location'),
21
            new InputArgument('dest-dir', InputArgument::REQUIRED, 'Config file location'),
22
            new InputOption('dest-class', null,  InputOption::VALUE_REQUIRED, 'Config file location'),
23
        ]);
24
    }
25
26
    /**
27
     * @param InputInterface $input
28
     * @param OutputInterface $output
29
     * @return int
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $containerBuilder = new SoapContainerBuilder($input->getArgument('config'));
34
35
        if ($input->getOption('dest-class')) {
36
            $containerBuilder->setContainerClassName($input->getOption('dest-class'));
37
        }
38
39
        $debugContainer = $containerBuilder->getDebugContainer();
40
41
        $wsdlMetadata = $debugContainer->getParameter('wsdl2php.config')['metadata'];
42
43
        $schemas = [];
44
        $portTypes = [];
45
        $wsdlReader = $debugContainer->get('goetas.wsdl2php.wsdl_reader');
46
47
        foreach (array_keys($wsdlMetadata) as $src) {
48
            $definitions = $wsdlReader->readFile($src);
49
            $schemas[] = $definitions->getSchema();
50
            $portTypes = array_merge($portTypes, $definitions->getPortTypes());
51
        }
52
53
        $soapReader = $debugContainer->get('goetas.wsdl2php.soap_reader');
54
55
56
        foreach (['php', 'jms'] as $type) {
57
            $converter = $debugContainer->get('goetas.xsd2php.converter.' . $type);
58
            $wsdlConverter = $debugContainer->get('goetas.wsdl2php.converter.' . $type);
59
            $items = $wsdlConverter->visitServices($soapReader->getServices());
60
            $items = array_merge($items, $converter->convert($schemas));
61
62
            $writer = $debugContainer->get('goetas.xsd2php.writer.' . $type);
63
            $writer->write($items);
64
        }
65
66
        /**
67
         * @var $clientStubGenerator \GoetasWebservices\SoapServices\SoapClient\StubGeneration\ClientStubGenerator
68
         */
69
        $clientStubGenerator = $debugContainer->get('goetas.wsdl2php.stub.client_generator');
70
71
        $classDefinitions = $clientStubGenerator->generate($portTypes);
72
        $classWriter = $debugContainer->get('goetas.xsd2php.class_writer.php');
73
        $classWriter->write($classDefinitions);
74
75
        $containerDumped = $containerBuilder->dumpContainerForProd($input->getArgument('dest-dir'), $debugContainer);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $containerDumped is correct as $containerBuilder->dumpC...dir'), $debugContainer) (which targets GoetasWebservices\SoapSe...:dumpContainerForProd()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
76
77
        return $containerDumped ? 0 : 255;
78
79
    }
80
}
81