Passed
Push — master ( a8e753...d3e13e )
by Carlos C
05:06 queued 03:16
created

SoapFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\Finkok;
6
7
use Psr\Log\LoggerAwareInterface;
8
use Psr\Log\LoggerInterface;
9
use Psr\Log\NullLogger;
10
use SoapClient;
11
12
class SoapFactory implements LoggerAwareInterface
13
{
14
    /** @var LoggerInterface */
15
    private $logger;
16
17 90
    public function __construct(LoggerInterface $logger = null)
18
    {
19 90
        $this->logger = $logger ?? new NullLogger();
20 90
    }
21
22 56
    public function createSoapClient(string $wsdlLocation): SoapClient
23
    {
24 56
        return new SoapClient($wsdlLocation, [
25 56
            'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
26 56
            'cache_wsdl' => WSDL_CACHE_MEMORY,
27
            'exceptions' => true,
28
            'trace' => true,
29
        ]);
30
    }
31
32
    /**
33
     * @param string $wsdlLocation
34
     * @param array<mixed> $defaultOptions
35
     * @return SoapCaller
36
     */
37 56
    public function createSoapCaller(string $wsdlLocation, array $defaultOptions): SoapCaller
38
    {
39 56
        $caller = new SoapCaller($this->createSoapClient($wsdlLocation), $defaultOptions);
40 56
        $caller->setLogger($this->logger);
41 56
        return $caller;
42
    }
43
44
    public function setLogger(LoggerInterface $logger): void
45
    {
46
        $this->logger = $logger;
47
    }
48
}
49