AbstractDriver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 88
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
stamp() 0 1 ?
cancel() 0 1 ?
addUser() 0 1 ?
editUser() 0 1 ?
getUsers() 0 1 ?
getUser() 0 1 ?
assignStamps() 0 1 ?
url() 0 1 ?
A __construct() 0 7 1
A request() 0 13 2
A xml() 0 4 1
A user() 0 4 1
1
<?php
2
3
namespace FeiMx\Pac\Drivers;
4
5
use ArrayAccess;
6
use FeiMx\Pac\Contracts\PacDriverInterface;
7
use FeiMx\Pac\PacStamp;
8
use FeiMx\Pac\PacUser;
9
use GuzzleHttp\Client;
10
use Meng\AsyncSoap\Guzzle\Factory as SoapFactory;
11
12
abstract class AbstractDriver implements PacDriverInterface
13
{
14
    /**
15
     * The driver username.
16
     *
17
     * @var string
18
     */
19
    protected $username;
20
    /**
21
     * The driver password.
22
     *
23
     * @var string
24
     */
25
    protected $password;
26
    /**
27
     * The driver sandbox.
28
     *
29
     * @var bool
30
     */
31
    protected $sandbox;
32
    /**
33
     * The custom parameters to be sent with the request.
34
     *
35
     * @var array
36
     */
37
    protected $parameters = [];
38
    /**
39
     * The Guzzle Soap Factory.
40
     *
41
     * @var \Meng\AsyncSoap\Guzzle\Factory
42
     */
43
    protected $factory;
44
45
    /**
46
     * Create a new driver instance.
47
     *
48
     * @param string $username
49
     * @param string $password
50
     * @param bool   $sandbox
51
     */
52
    public function __construct($username, $password, $sandbox = true)
53
    {
54
        $this->username = $username;
55
        $this->password = $password;
56
        $this->sandbox = $sandbox;
57
        $this->factory = new SoapFactory();
58
    }
59
60
    abstract public function stamp($xml): PacStamp;
61
62
    abstract public function cancel(array $uuids, $rfc, $cer, $key);
63
64
    abstract public function addUser($rfc, $params = []): PacUser;
65
66
    abstract public function editUser($rfc, $params = []);
67
68
    abstract public function getUsers(): ArrayAccess;
69
70
    abstract public function getUser($rfc = null): PacUser;
71
72
    abstract public function assignStamps($rfc = null, $credit = 0);
73
74
    abstract protected function url($wsdl = null);
75
76
    public function request($url = null, $method = null, $params = [])
77
    {
78
        $url = $url ?? $this->url();
79
80
        try {
81
            $response = $this->factory->create(new Client(), $url)
82
                        ->{$method}($params);
83
84
            return $response->wait();
85
        } catch (\SoapFault $e) {
86
            return $e;
87
        }
88
    }
89
90
    public function xml()
91
    {
92
        throw new \Exception('Method xml() is not implemented.');
93
    }
94
95
    public function user()
96
    {
97
        throw new \Exception('Method user() is not implemented.');
98
    }
99
}
100