Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
GeneratorSoapClient
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
6 / 6
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 initSoapClient
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getSoapClientOptions
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
 setSoapClient
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getSoapClient
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSoapClientStreamContextOptions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace WsdlToPhp\PackageGenerator\Generator;
6
7use WsdlToPhp\PackageBase\SoapClientInterface;
8
9class GeneratorSoapClient extends AbstractGeneratorAware
10{
11    protected SoapClient $soapClient;
12
13    public function __construct(Generator $generator)
14    {
15        parent::__construct($generator);
16        $this->initSoapClient();
17    }
18
19    /**
20     * @throws \InvalidArgumentException
21     */
22    public function initSoapClient(): self
23    {
24        try {
25            $soapClient = new SoapClient($this->getSoapClientOptions(\SOAP_1_1));
26        } catch (\SoapFault $fault) {
27            try {
28                $soapClient = new SoapClient($this->getSoapClientOptions(\SOAP_1_2));
29            } catch (\SoapFault $fault) {
30                throw new \InvalidArgumentException(sprintf('Unable to load WSDL at "%s"!', $this->getGenerator()->getOptionOrigin()), __LINE__, $fault);
31            }
32        }
33
34        return $this->setSoapClient($soapClient);
35    }
36
37    public function getSoapClientOptions(int $soapVersion): array
38    {
39        return array_merge([
40            SoapClientInterface::WSDL_SOAP_VERSION => $soapVersion,
41            SoapClientInterface::WSDL_URL => $this->getGenerator()->getOptionOrigin(),
42            SoapClientInterface::WSDL_LOGIN => $this->getGenerator()->getOptionBasicLogin(),
43            SoapClientInterface::WSDL_PROXY_HOST => $this->getGenerator()->getOptionProxyHost(),
44            SoapClientInterface::WSDL_PROXY_PORT => $this->getGenerator()->getOptionProxyPort(),
45            SoapClientInterface::WSDL_PASSWORD => $this->getGenerator()->getOptionBasicPassword(),
46            SoapClientInterface::WSDL_PROXY_LOGIN => $this->getGenerator()->getOptionProxyLogin(),
47            SoapClientInterface::WSDL_PROXY_PASSWORD => $this->getGenerator()->getOptionProxyPassword(),
48        ], $this->getGenerator()->getOptionSoapOptions());
49    }
50
51    public function setSoapClient(SoapClient $soapClient): self
52    {
53        $this->soapClient = $soapClient;
54
55        return $this;
56    }
57
58    public function getSoapClient(): SoapClient
59    {
60        return $this->soapClient;
61    }
62
63    public function getSoapClientStreamContextOptions(): array
64    {
65        return $this->getSoapClient()->getStreamContextOptions();
66    }
67}