Passed
Push — master ( f78dc8...d3e9de )
by Carlos C
46s queued 12s
created

SoapFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 23.08%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 12
c 5
b 0
f 0
dl 0
loc 30
ccs 3
cts 13
cp 0.2308
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setLogger() 0 3 1
A createSoapClient() 0 7 1
A createSoapCaller() 0 5 1
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 28
    public function __construct(LoggerInterface $logger = null)
18
    {
19 28
        $this->logger = $logger ?? new NullLogger();
20 28
    }
21
22
    public function createSoapClient(string $wsdlLocation): SoapClient
23
    {
24
        return new SoapClient($wsdlLocation, [
25
            'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
26
            'cache_wsdl' => WSDL_CACHE_MEMORY,
27
            'exceptions' => true,
28
            'trace' => true,
29
        ]);
30
    }
31
32
    public function createSoapCaller(string $wsdlLocation, array $defaultOptions): SoapCaller
33
    {
34
        $caller = new SoapCaller($this->createSoapClient($wsdlLocation), $defaultOptions);
35
        $caller->setLogger($this->logger);
36
        return $caller;
37
    }
38
39
    public function setLogger(LoggerInterface $logger): void
40
    {
41
        $this->logger = $logger;
42
    }
43
}
44