Completed
Pull Request — master (#1)
by Jorge
05:04
created

AbstractDriver::assignStamps()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
namespace FeiMx\Pac\Drivers;
4
5
use FeiMx\Pac\Contracts\PacDriverInterface;
6
use GuzzleHttp\Client;
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 string
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 array
39
     */
40
    protected $factory;
41
42
    /**
43
     * Create a new driver instance.
44
     *
45
     * @param string $username
46
     * @param string $clientSecret
0 ignored issues
show
Bug introduced by
There is no parameter named $clientSecret. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
47
     * @param string $sandbox
48
     */
49
    public function __construct($username, $password, $sandbox = true)
50
    {
51
        $this->username = $username;
52
        $this->password = $password;
53
        $this->sandbox = $sandbox;
0 ignored issues
show
Documentation Bug introduced by
It seems like $sandbox can also be of type boolean. However, the property $sandbox is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
54
        $this->factory = new SoapFactory();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Meng\AsyncSoap\Guzzle\Factory() of type object<Meng\AsyncSoap\Guzzle\Factory> is incompatible with the declared type array of property $factory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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)
0 ignored issues
show
Bug introduced by
The method create cannot be called on $this->factory (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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