Passed
Push — ref ( 45b89b )
by Asmir
02:50
created

DevMetadataLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
namespace GoetasWebservices\SoapServices\Metadata\Loader;
4
5
use GoetasWebservices\SoapServices\Exception\MetadataException;
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...ption\MetadataException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use GoetasWebservices\SoapServices\Metadata\Generator\MetadataGenerator;
7
use GoetasWebservices\XML\SOAPReader\SoapReader;
8
use GoetasWebservices\XML\WSDLReader\DefinitionsReader;
9
10
/**
11
 * This class is here to be used only while developing, should not be used on production.
12
 */
13
class DevMetadataLoader implements MetadataLoaderInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    private $metadataCache = [];
19
    /**
20
     * @var MetadataGenerator
21
     */
22
    private $metadataGenerator;
23
    /**
24
     * @var DefinitionsReader
25
     */
26
    private $wsdlReader;
27
    /**
28
     * @var SoapReader
29
     */
30
    private $soapReader;
31
32
    public function __construct(MetadataGenerator $metadataGenerator, SoapReader $soapReader, DefinitionsReader $wsdlReader)
33
    {
34
        $this->metadataGenerator = $metadataGenerator;
35
        $this->wsdlReader = $wsdlReader;
36
        $this->soapReader = $soapReader;
37
    }
38
39
    public function load($wsdl)
40
    {
41
        if (!isset($this->metadataCache[$wsdl])) {
42
            $this->wsdlReader->readFile($wsdl);
43
            try {
44
                $this->metadataCache[$wsdl] = $this->metadataGenerator->generate($this->soapReader->getServices());
45
            } catch (\Exception $e) {
46
                throw new MetadataException(sprintf("Can not generate metadata information for %s", $wsdl), 0, $e);
47
            }
48
        }
49
50
        return $this->metadataCache[$wsdl];
51
    }
52
}
53