Issues (2551)

src/Impl/Cxf/Webservice/CxfWSDLImporter.php (9 issues)

1
<?php
2
3
namespace Jabe\Impl\Cxf\Webservice;
4
5
use Jabe\Impl\Bpmn\Data\SimpleStructureDefinition;
6
use Jabe\Impl\Bpmn\Parser\XMLImporterInterface;
7
use Sax\Element;
8
use Jabe\Impl\Webservice\{
9
    WSDLManager,
10
    WSOperation,
11
    WSService,
12
    WSDLServiceBuilder
13
};
14
use Jabe\Impl\Model\Wsdl\Instance\{
15
    ComplexTypeInterface,
16
    DefinitionsInterface,
17
    OperationInterface,
18
    ServiceInterface,
19
    TypesInterface
20
};
21
22
class CxfWSDLImporter implements XMLImporterInterface
23
{
24
    protected $wsServices = [];
25
    protected $wsOperations = [];
26
    protected $structures = [];
27
28
    protected $wsdlLocation;
29
    protected $namespace = "";
30
31
    public function importFrom($data): void
32
    {
33
        if ($data instanceof Element) {
34
            $this->namespace = $data->attribute("namespace") === null ? "" : $data->attribute("namespace") . ":";
35
            $this->importFrom($data->attribute("location"));
36
        } elseif (is_string($data)) {
37
            $url = $data;
38
39
            $this->wsServices = [];
40
            $this->wsOperations = [];
41
            $this->structures = [];
42
            $this->wsdlLocation = $url;
43
44
            $wsdlManager = new WSDLManager();
45
            $def = $wsdlManager->getDefinition($url);
46
            $builder = new WSDLServiceBuilder();
47
48
            $services = $builder->buildServices($def);
49
            foreach ($services as $service) {
50
                $wsService = $this->importService($service, $def);
51
                $this->wsServices[$this->namespace . $wsService->getName()] = $wsService;
52
            }
53
54
            if ($def !== null && $def->getTypes() !== null) {
0 ignored issues
show
The method getTypes() does not exist on Jabe\Impl\Model\Wsdl\Instance\DefinitionsInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Impl\Model\Wsdl\Instance\DefinitionsInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
            if ($def !== null && $def->/** @scrutinizer ignore-call */ getTypes() !== null) {
Loading history...
55
                $this->importTypes($def->getTypes());
56
            }
57
        }
58
    }
59
60
    protected function importService(ServiceInterface $service, DefinitionsInterface $def): WSService
61
    {
62
        $name = $service->getName();
0 ignored issues
show
The method getName() does not exist on Jabe\Impl\Model\Wsdl\Instance\ServiceInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Impl\Model\Wsdl\Instance\ServiceInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
        /** @scrutinizer ignore-call */ 
63
        $name = $service->getName();
Loading history...
63
        $location = $service->getEndpoint();
0 ignored issues
show
The method getEndpoint() does not exist on Jabe\Impl\Model\Wsdl\Instance\ServiceInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Impl\Model\Wsdl\Instance\ServiceInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        /** @scrutinizer ignore-call */ 
64
        $location = $service->getEndpoint();
Loading history...
64
65
        $serviceName = $service->getName();
66
        $arr = explode(':', $service->getBinding());
0 ignored issues
show
The method getBinding() does not exist on Jabe\Impl\Model\Wsdl\Instance\ServiceInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Impl\Model\Wsdl\Instance\ServiceInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        $arr = explode(':', $service->/** @scrutinizer ignore-call */ getBinding());
Loading history...
67
        $bindingName = end($arr);
68
        $bindings = $def->getBindings();
0 ignored issues
show
The method getBindings() does not exist on Jabe\Impl\Model\Wsdl\Instance\DefinitionsInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Impl\Model\Wsdl\Instance\DefinitionsInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        /** @scrutinizer ignore-call */ 
69
        $bindings = $def->getBindings();
Loading history...
69
        $binding = null;
0 ignored issues
show
The assignment to $binding is dead and can be removed.
Loading history...
70
        $wsService = new WSService($this->namespace . $name, $location, $this->wsdlLocation);
71
        foreach ($bindings as $testBinding) {
72
            $arr = explode(':', $testBinding->getType());
73
            $bindingType = end($arr);
74
            if ($serviceName == $bindingType && $bindingName == $testBinding->getName()) {
75
                $operations = $testBinding->getOperations();
76
                foreach ($operations as $operation) {
77
                    $wsOperation = $this->importOperation($operation, $wsService);
78
                    $wsService->addOperation($wsOperation);
79
                    $this->wsOperations[$this->namespace . $operation->getName()] = $wsOperation;
80
                }
81
            }
82
        }
83
84
        return $wsService;
85
    }
86
87
    protected function importOperation(OperationInterface $operation, WSService $service): WSOperation
88
    {
89
        $wsOperation = new WSOperation($this->namespace . $operation->getName(), $operation->getName(), $service);
90
        return $wsOperation;
91
    }
92
93
    protected function importTypes(TypesInterface $types): void
94
    {
95
        $impl = $types->getSchema();
0 ignored issues
show
The method getSchema() does not exist on Jabe\Impl\Model\Wsdl\Instance\TypesInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Impl\Model\Wsdl\Instance\TypesInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

95
        /** @scrutinizer ignore-call */ 
96
        $impl = $types->getSchema();
Loading history...
96
97
        $mappings = $impl->getElements();
98
99
        foreach ($mappings as $mapping) {
100
            $this->importStructure($mapping);
101
        }
102
    }
103
104
    protected function importStructure(ComplexTypeInterface $mapping): void
105
    {
106
        $structure = new SimpleStructureDefinition($this->namespace . $mapping->getName());
0 ignored issues
show
The method getName() does not exist on Jabe\Impl\Model\Wsdl\Instance\ComplexTypeInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Impl\Model\Wsdl\Instance\ComplexTypeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
        $structure = new SimpleStructureDefinition($this->namespace . $mapping->/** @scrutinizer ignore-call */ getName());
Loading history...
107
        $params = $mapping->getParameters();
0 ignored issues
show
The method getParameters() does not exist on Jabe\Impl\Model\Wsdl\Instance\ComplexTypeInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Impl\Model\Wsdl\Instance\ComplexTypeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
        /** @scrutinizer ignore-call */ 
108
        $params = $mapping->getParameters();
Loading history...
108
        foreach ($params as $param) {
109
            $fieldName = $param->getName();
110
            $arr = explode(":", $param->getType());
111
            $fieldClass = end($arr);
112
            $structure->setFieldName($fieldName, $fieldClass, null);
113
        }
114
        $this->structures[$structure->getId()] = $structure;
115
    }
116
117
    public function getStructures(): array
118
    {
119
        return $this->structures;
120
    }
121
122
    public function getServices(): array
123
    {
124
        return $this->wsServices;
125
    }
126
127
    public function getOperations(): array
128
    {
129
        return $this->wsOperations;
130
    }
131
}
132