Completed
Push — master ( ac8e10...d5ebee )
by Jean C.
02:30
created

Moip::transfers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Moip;
4
5
use Moip\Resource\Customer;
6
use Moip\Resource\Entry;
7
use Moip\Resource\Multiorders;
8
use Moip\Resource\Orders;
9
use Moip\Resource\Payment;
10
use Moip\Resource\Transfers;
11
use Requests_Session;
12
13
/**
14
 * Class Moip.
15
 */
16
class Moip
17
{
18
    /**
19
     * endpoint of production.
20
     *
21
     * @const string
22
     */
23
    const ENDPOINT_PRODUCTION = 'https://api.moip.com.br';
24
25
    /**
26
     * endpoint of sandbox.
27
     *
28
     * @const string
29
     */
30
    const ENDPOINT_SANDBOX = 'https://sandbox.moip.com.br';
31
32
    /**
33
     * Client name.
34
     *
35
     * @const string
36
     **/
37
    const CLIENT = 'Moip SDK';
38
39
    /**
40
     * Authentication that will be added to the header of request.
41
     *
42
     * @var \Moip\MoipAuthentication
43
     */
44
    private $moipAuthentication;
45
46
    /**
47
     * Endpoint of request.
48
     *
49
     * @var \Moip\Moip::ENDPOINT_PRODUCTION|\Moip\Moip::ENDPOINT_SANDBOX
50
     */
51
    private $endpoint;
52
53
    /**
54
     * @var Requests_Session HTTP session configured to use the moip API.
55
     */
56
    private $session;
57
58
    /**
59
     * Create a new aurhentication with the endpoint.
60
     *
61
     * @param \Moip\MoipAuthentication                                            $moipAuthentication
62
     * @param string|\Moip\Moip::ENDPOINT_PRODUCTION|\Moip\Moip::ENDPOINT_SANDBOX $endpoint
63
     */
64
    public function __construct(MoipAuthentication $moipAuthentication, $endpoint = self::ENDPOINT_PRODUCTION)
65
    {
66
        $this->moipAuthentication = $moipAuthentication;
67
        $this->endpoint = $endpoint;
0 ignored issues
show
Documentation Bug introduced by
It seems like $endpoint can also be of type string. However, the property $endpoint is declared as type object<Moip\Moip::ENDPOI...Moip::ENDPOINT_SANDBOX>. 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...
68
        $this->createNewSession();
69
    }
70
71
    /**
72
     * Creates a new Request_Session with all the default values.
73
     * A Session is created at construction.
74
     *
75
     * @param float $timeout         How long should we wait for a response?(seconds with a millisecond precision, default: 30, example: 0.01).
76
     * @param float $connect_timeout How long should we wait while trying to connect? (seconds with a millisecond precision, default: 10, example: 0.01)
77
     */
78
    public function createNewSession($timeout = 30.0, $connect_timeout = 30.0)
79
    {
80
        if (function_exists('posix_uname')) {
81
            $uname = posix_uname();
82
            $user_agent = sprintf('Mozilla/4.0 (compatible; %s; PHP/%s %s; %s; %s)',
83
                self::CLIENT, PHP_SAPI, PHP_VERSION, $uname['sysname'], $uname['machine']);
84
        } else {
85
            $user_agent = sprintf('Mozilla/4.0 (compatible; %s; PHP/%s %s; %s)',
86
                self::CLIENT, PHP_SAPI, PHP_VERSION, PHP_OS);
87
        }
88
        $sess = new Requests_Session($this->endpoint);
89
        $sess->options['auth'] = $this->moipAuthentication;
90
        $sess->options['timeout'] = $timeout;
91
        $sess->options['connect_timeout'] = $connect_timeout;
92
        $sess->options['useragent'] = $user_agent;
93
        $this->session = $sess;
94
    }
95
96
    /**
97
     * Returns the http session created.
98
     *
99
     * @return Requests_Session
100
     */
101
    public function getSession()
102
    {
103
        return $this->session;
104
    }
105
106
    /**
107
     * Replace the http session by a custom one.
108
     *
109
     * @param Requests_Session $session
110
     */
111
    public function setSession($session)
112
    {
113
        $this->session = $session;
114
    }
115
116
    /**
117
     * Create a new Customer instance.
118
     *
119
     * @return \Moip\Resource\Customer
120
     */
121
    public function customers()
122
    {
123
        return new Customer($this);
124
    }
125
126
    /**
127
     * Create a new Entry instance.
128
     *
129
     * @return \Moip\Resource\Entry
130
     */
131
    public function entries()
132
    {
133
        return new Entry($this);
134
    }
135
136
    /**
137
     * Create a new Orders instance.
138
     *
139
     * @return \Moip\Resource\Orders
140
     */
141
    public function orders()
142
    {
143
        return new Orders($this);
144
    }
145
146
    /**
147
     * Create a new Payment instance.
148
     *
149
     * @return \Moip\Resource\Payment
150
     */
151
    public function payments()
152
    {
153
        return new Payment($this);
154
    }
155
156
    /**
157
     * Create a new Multiorders instance.
158
     *
159
     * @return \Moip\Resource\Multiorders
160
     */
161
    public function multiorders()
162
    {
163
        return new Multiorders($this);
164
    }
165
166
    /**
167
     * Create a new Transfers.
168
     *
169
     * @return \Moip\Resource\Transfers
170
     */
171
172
    /**
173
     * Create a new Transfers instance.
174
     *
175
     * @return Transfers
176
     */
177
    public function transfers()
178
    {
179
        return new transfers($this);
180
    }
181
182
    /**
183
     * Get the endpoint.
184
     *
185
     * @return \Moip\Moip::ENDPOINT_PRODUCTION|\Moip\Moip::ENDPOINT_SANDBOX
186
     */
187
    public function getEndpoint()
188
    {
189
        return $this->endpoint;
190
    }
191
}
192