Completed
Push — feature/issue-43 ( 7fc434 )
by Mikaël
02:48
created

GeneratorSoapClient   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 77
ccs 34
cts 34
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSoapClientStreamContextOptions() 0 9 2
A __construct() 0 5 1
A initSoapClient() 0 13 3
A getSoapClientOptions() 0 13 1
A setSoapClient() 0 5 1
A getSoapClient() 0 4 1
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\Generator;
4
5
class GeneratorSoapClient extends AbstractGeneratorAware
6
{
7
    /**
8
     * @var SoapClient
9
     */
10
    protected $soapClient;
11
    /**
12
     * @see \WsdlToPhp\PackageGenerator\Generator\AbstractGeneratorAware::__construct()
13
     */
14 420
    public function __construct(Generator $generator)
15
    {
16 420
        parent::__construct($generator);
17 420
        $this->initSoapClient();
18 416
    }
19
    /**
20
     * @throws \InvalidArgumentException
21
     * @return GeneratorSoapClient
22
     */
23 424
    public function initSoapClient()
24
    {
25
        try {
26 424
            $soapClient = new SoapClient($this->getSoapClientOptions(SOAP_1_1), true);
27 424
        } catch (\SoapFault $fault) {
28
            try {
29 4
                $soapClient = new SoapClient($this->getSoapClientOptions(SOAP_1_2), true);
30 4
            } catch (\SoapFault $fault) {
31 4
                throw new \InvalidArgumentException(sprintf('Unable to load WSDL at "%s"!', $this->getGenerator()->getOptionOrigin()), __LINE__, $fault);
32
            }
33
        }
34 420
        return $this->setSoapClient($soapClient);
35
    }
36
    /**
37
     * @param int $soapVersion
38
     * @return string[]
39
     */
40 424
    public function getSoapClientOptions($soapVersion)
41
    {
42 424
        return array_merge(array(
43 424
            SoapClient::WSDL_SOAP_VERSION => $soapVersion,
44 424
            SoapClient::WSDL_URL => $this->getGenerator()->getOptionOrigin(),
45 424
            SoapClient::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
46 424
            SoapClient::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
47 424
            SoapClient::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
48 424
            SoapClient::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
49 424
            SoapClient::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
50 424
            SoapClient::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
51 424
        ), $this->getGenerator()->getOptionSoapOptions());
52
    }
53
    /**
54
     * @param SoapClient $soapClient
55
     * @return GeneratorSoapClient
56
     */
57 420
    public function setSoapClient(SoapClient $soapClient)
58
    {
59 420
        $this->soapClient = $soapClient;
60 420
        return $this;
61
    }
62
    /**
63
     * @return SoapClient
64
     */
65 400
    public function getSoapClient()
66
    {
67 400
        return $this->soapClient;
68
    }
69
    /**
70
     * @return array
71
     */
72 12
    public function getSoapClientStreamContextOptions()
73
    {
74 12
        $options = array();
75 12
        $soapClient = $this->getSoapClient();
76 12
        if ($soapClient instanceof SoapClient) {
77 12
            $options = $soapClient->getStreamContextOptions();
0 ignored issues
show
Bug introduced by
The method getStreamContextOptions() does not seem to exist on object<WsdlToPhp\Package...r\Generator\SoapClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78 12
        }
79 12
        return $options;
80
    }
81
}
82