Completed
Push — feature/issue-40 ( b26607...6e6d1c )
by Mikaël
22:12
created

getSoapClientStreamContextOptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
cc 2
eloc 6
nc 2
nop 0
crap 2
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 408
    public function __construct(Generator $generator)
15
    {
16 408
        parent::__construct($generator);
17 408
        $this->initSoapClient();
18 404
    }
19
    /**
20
     * @throws \InvalidArgumentException
21
     * @return GeneratorSoapClient
22
     */
23 416
    public function initSoapClient()
24
    {
25
        try {
26 416
            $soapClient = new SoapClient($this->getSoapClientOptions(SOAP_1_1), true);
27 313
        } 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 412
        return $this->setSoapClient($soapClient);
35
    }
36
    /**
37
     * @param int SOAP_1_1|SOAP_1_2
38
     * @return string[]
39
     */
40 416
    public function getSoapClientOptions($soapVersion)
41
    {
42 416
        return array_merge(array(
43 416
            SoapClient::WSDL_SOAP_VERSION => $soapVersion,
44 416
            SoapClient::WSDL_URL => $this->getGenerator()->getOptionOrigin(),
45 416
            SoapClient::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
46 416
            SoapClient::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
47 416
            SoapClient::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
48 416
            SoapClient::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
49 416
            SoapClient::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
50 416
            SoapClient::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
51 416
        ), $this->getGenerator()->getOptionSoapOptions());
52
    }
53
    /**
54
     * @param SoapClient $soapClient
55
     * @return GeneratorSoapClient
56
     */
57 412
    public function setSoapClient(SoapClient $soapClient)
58
    {
59 412
        $this->soapClient = $soapClient;
60 412
        return $this;
61
    }
62
    /**
63
     * @return SoapClient
64
     */
65 392
    public function getSoapClient()
66
    {
67 392
        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 9
        }
79 12
        return $options;
80
    }
81
}
82