Completed
Push — master ( c4aed4...1d2e73 )
by Jorge
01:19
created

AbstractDriver   A

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