GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( e5b8eb...47d764 )
by Igor
01:54 queued 12s
created
src/Route4Me/V5/AddressBook/ResponseCluster.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -15,33 +15,33 @@
 block discarded – undo
15 15
  */
16 16
 class ResponseCluster extends Common
17 17
 {
18
-    /**
19
-     * Cluster of addresses
20
-     */
21
-    public ?Cluster $cluster = null;
18
+	/**
19
+	 * Cluster of addresses
20
+	 */
21
+	public ?Cluster $cluster = null;
22 22
 
23
-    /**
24
-     * A number of the returned addresses.
25
-     * @example 1
26
-     */
27
-    public ?int $address_count = null;
23
+	/**
24
+	 * A number of the returned addresses.
25
+	 * @example 1
26
+	 */
27
+	public ?int $address_count = null;
28 28
 
29
-    public function __construct(?array $params = null)
30
-    {
31
-        if ($params !== null) {
32
-            foreach ($this as $key => $value) {
33
-                if (isset($params[$key])) {
34
-                    if ($key === 'cluster') {
35
-                        if (is_array($params[$key])) {
36
-                            $this->{$key} = new Cluster($params[$key]);
37
-                        } elseif (is_object($params[$key]) && $params[$key] instanceof Cluster) {
38
-                            $this->{$key} = $params[$key];
39
-                        }
40
-                    } else {
41
-                        $this->{$key} = $params[$key];
42
-                    }
43
-                }
44
-            }
45
-        }
46
-    }
29
+	public function __construct(?array $params = null)
30
+	{
31
+		if ($params !== null) {
32
+			foreach ($this as $key => $value) {
33
+				if (isset($params[$key])) {
34
+					if ($key === 'cluster') {
35
+						if (is_array($params[$key])) {
36
+							$this->{$key} = new Cluster($params[$key]);
37
+						} elseif (is_object($params[$key]) && $params[$key] instanceof Cluster) {
38
+							$this->{$key} = $params[$key];
39
+						}
40
+					} else {
41
+						$this->{$key} = $params[$key];
42
+					}
43
+				}
44
+			}
45
+		}
46
+	}
47 47
 }
Please login to merge, or discard this patch.
src/Route4Me/V5/AddressBook/Cluster.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -13,35 +13,35 @@
 block discarded – undo
13 13
  */
14 14
 class Cluster extends Common
15 15
 {
16
-    /**
17
-     * Geohash
18
-     * @example 1mr8h4r9
19
-     */
20
-    public ?string $geohash = null;
16
+	/**
17
+	 * Geohash
18
+	 * @example 1mr8h4r9
19
+	 */
20
+	public ?string $geohash = null;
21 21
 
22
-    /**
23
-     * Latitude
24
-     * @example -60.456132888793945
25
-     */
26
-    public ?float $lat = null;
22
+	/**
23
+	 * Latitude
24
+	 * @example -60.456132888793945
25
+	 */
26
+	public ?float $lat = null;
27 27
 
28
-    /**
29
-     * Longitude
30
-     * @example -60.456132888793945
31
-     */
32
-    public ?float $lng = null;
28
+	/**
29
+	 * Longitude
30
+	 * @example -60.456132888793945
31
+	 */
32
+	public ?float $lng = null;
33 33
 
34
-    /**
35
-     * Boundary box, array of pairs of floats.
36
-     * @var float[][]
37
-     * @example [[52.294921875, 5.2294921875], [52.3388671875, 5.2734375]]
38
-     */
39
-    public ?array $bbox = null;
34
+	/**
35
+	 * Boundary box, array of pairs of floats.
36
+	 * @var float[][]
37
+	 * @example [[52.294921875, 5.2294921875], [52.3388671875, 5.2734375]]
38
+	 */
39
+	public ?array $bbox = null;
40 40
 
41
-    public function __construct(?array $params = null)
42
-    {
43
-        if ($params !== null) {
44
-            $this->fillFromArray($params);
45
-        }
46
-    }
41
+	public function __construct(?array $params = null)
42
+	{
43
+		if ($params !== null) {
44
+			$this->fillFromArray($params);
45
+		}
46
+	}
47 47
 }
Please login to merge, or discard this patch.
src/Route4Me/V5/AddressBook/ScheduleItem.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -13,27 +13,27 @@
 block discarded – undo
13 13
  */
14 14
 class ScheduleItem extends Common
15 15
 {
16
-    /**
17
-     * If true, the schedule is enabled.
18
-     */
19
-    public ?bool $enable = null;
16
+	/**
17
+	 * If true, the schedule is enabled.
18
+	 */
19
+	public ?bool $enable = null;
20 20
 
21
-    /**
22
-     * Schedule mode.
23
-     * @example 'monthly'
24
-     */
25
-    public ?string $mode = null;
21
+	/**
22
+	 * Schedule mode.
23
+	 * @example 'monthly'
24
+	 */
25
+	public ?string $mode = null;
26 26
 
27
-    /**
28
-     * Monthly properties.
29
-     * @example ['every' => 1]
30
-     */
31
-    public ?array $monthly = null;
27
+	/**
28
+	 * Monthly properties.
29
+	 * @example ['every' => 1]
30
+	 */
31
+	public ?array $monthly = null;
32 32
 
33
-    public function __construct(?array $params = null)
34
-    {
35
-        if ($params !== null) {
36
-            $this->fillFromArray($params);
37
-        }
38
-    }
33
+	public function __construct(?array $params = null)
34
+	{
35
+		if ($params !== null) {
36
+			$this->fillFromArray($params);
37
+		}
38
+	}
39 39
 }
Please login to merge, or discard this patch.
src/Route4Me/V5/AddressBook/Address.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -14,34 +14,34 @@
 block discarded – undo
14 14
  */
15 15
 class Address extends ResponseAddress
16 16
 {
17
-    /**
18
-     * @param array|string $params_or_address_1  - The route Address Line 1 or array of Address's values.
19
-     * @param float        $cached_lat           - A latitude of the contact's cached position.
20
-     * @param float        $cached_lng           - A longitude of the contact's cached position.
21
-     * @param string       $address_stop_type    - The contact's stop type. available types:
22
-     *                                             'DELIVERY', 'PICKUP', 'BREAK', 'MEETUP',
23
-     *                                             'SERVICE', 'VISIT', 'DRIVEBY'
24
-     */
25
-    public function __construct(
26
-        $params_or_address_1,
27
-        ?float $cached_lat = null,
28
-        ?float $cached_lng = null,
29
-        ?string $address_stop_type = null
30
-    ) {
31
-        if (is_array($params_or_address_1) && isset($params_or_address_1['address_1'])
32
-            && isset($params_or_address_1['cached_lat']) && isset($params_or_address_1['cached_lng'])
33
-            && isset($params_or_address_1['address_stop_type'])
34
-        ) {
35
-            parent::__construct($params_or_address_1);
36
-        } elseif (is_string($params_or_address_1) && $params_or_address_1 != ""
37
-            && !is_null($cached_lat) && !is_null($cached_lng) && !is_null($address_stop_type)
38
-        ) {
39
-            $this->address_1 = $params_or_address_1;
40
-            $this->cached_lat = $cached_lat;
41
-            $this->cached_lng = $cached_lng;
42
-            $this->address_stop_type = $address_stop_type;
43
-        } else {
44
-            throw new ApiError('The fields address_1, cached_lat, cached_lng, address_stop_type are required.');
45
-        }
46
-    }
17
+	/**
18
+	 * @param array|string $params_or_address_1  - The route Address Line 1 or array of Address's values.
19
+	 * @param float        $cached_lat           - A latitude of the contact's cached position.
20
+	 * @param float        $cached_lng           - A longitude of the contact's cached position.
21
+	 * @param string       $address_stop_type    - The contact's stop type. available types:
22
+	 *                                             'DELIVERY', 'PICKUP', 'BREAK', 'MEETUP',
23
+	 *                                             'SERVICE', 'VISIT', 'DRIVEBY'
24
+	 */
25
+	public function __construct(
26
+		$params_or_address_1,
27
+		?float $cached_lat = null,
28
+		?float $cached_lng = null,
29
+		?string $address_stop_type = null
30
+	) {
31
+		if (is_array($params_or_address_1) && isset($params_or_address_1['address_1'])
32
+			&& isset($params_or_address_1['cached_lat']) && isset($params_or_address_1['cached_lng'])
33
+			&& isset($params_or_address_1['address_stop_type'])
34
+		) {
35
+			parent::__construct($params_or_address_1);
36
+		} elseif (is_string($params_or_address_1) && $params_or_address_1 != ""
37
+			&& !is_null($cached_lat) && !is_null($cached_lng) && !is_null($address_stop_type)
38
+		) {
39
+			$this->address_1 = $params_or_address_1;
40
+			$this->cached_lat = $cached_lat;
41
+			$this->cached_lng = $cached_lng;
42
+			$this->address_stop_type = $address_stop_type;
43
+		} else {
44
+			throw new ApiError('The fields address_1, cached_lat, cached_lng, address_stop_type are required.');
45
+		}
46
+	}
47 47
 }
Please login to merge, or discard this patch.
src/Route4Me/V5/AddressBook/StatusChecker.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -13,37 +13,37 @@
 block discarded – undo
13 13
  */
14 14
 class StatusChecker extends Common
15 15
 {
16
-    /**
17
-     * HTTP code.
18
-     * @example 200, 202
19
-     */
20
-    public ?int $code = null;
21
-
22
-    /**
23
-     * Requested data if request was handled synchronously.
24
-     * @example ['status' => 1] - Successful operation
25
-     */
26
-    public ?array $data = null;
27
-
28
-    /**
29
-     * Path to the status checker if request was handled asynchronously.
30
-     */
31
-    public ?string $location = null;
32
-
33
-    /**
34
-     * Job Id to check status if request was handled asynchronously.
35
-     */
36
-    public ?string $x_job_id = null;
37
-
38
-    /**
39
-     * Job running time in seconds.
40
-     */
41
-    public ?string $x_r4m_async_job_running_time = null;
42
-
43
-    public function __construct(?array $params = null)
44
-    {
45
-        if ($params !== null) {
46
-            $this->fillFromArray($params);
47
-        }
48
-    }
16
+	/**
17
+	 * HTTP code.
18
+	 * @example 200, 202
19
+	 */
20
+	public ?int $code = null;
21
+
22
+	/**
23
+	 * Requested data if request was handled synchronously.
24
+	 * @example ['status' => 1] - Successful operation
25
+	 */
26
+	public ?array $data = null;
27
+
28
+	/**
29
+	 * Path to the status checker if request was handled asynchronously.
30
+	 */
31
+	public ?string $location = null;
32
+
33
+	/**
34
+	 * Job Id to check status if request was handled asynchronously.
35
+	 */
36
+	public ?string $x_job_id = null;
37
+
38
+	/**
39
+	 * Job running time in seconds.
40
+	 */
41
+	public ?string $x_r4m_async_job_running_time = null;
42
+
43
+	public function __construct(?array $params = null)
44
+	{
45
+		if ($params !== null) {
46
+			$this->fillFromArray($params);
47
+		}
48
+	}
49 49
 }
Please login to merge, or discard this patch.
src/Route4Me/V5/AddressBook/ResponseAll.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -14,43 +14,43 @@
 block discarded – undo
14 14
  */
15 15
 class ResponseAll extends Common
16 16
 {
17
-    /**
18
-     * Array of ResponceAddresses.
19
-     * @var ResponceAddress[]
20
-     */
21
-    public ?array $results = null;
17
+	/**
18
+	 * Array of ResponceAddresses.
19
+	 * @var ResponceAddress[]
20
+	 */
21
+	public ?array $results = null;
22 22
 
23
-    /**
24
-     * Total quantity of ResponceAddresses that match the query.
25
-     * @example 1
26
-     */
27
-    public ?int $total = null;
23
+	/**
24
+	 * Total quantity of ResponceAddresses that match the query.
25
+	 * @example 1
26
+	 */
27
+	public ?int $total = null;
28 28
 
29
-    /**
30
-     * An array of valid fields name in results array.
31
-     * @var string[]
32
-     */
33
-    public ?array $fields = null;
29
+	/**
30
+	 * An array of valid fields name in results array.
31
+	 * @var string[]
32
+	 */
33
+	public ?array $fields = null;
34 34
 
35
-    public function __construct(?array $params = null)
36
-    {
37
-        if ($params !== null) {
38
-            foreach ($this as $key => $value) {
39
-                if (isset($params[$key])) {
40
-                    if ($key === 'results') {
41
-                        $this->{$key} = array();
42
-                        foreach ($params[$key] as $ra_key => $ra_value) {
43
-                            if (is_array($ra_value)) {
44
-                                array_push($this->{$key}, new ResponseAddress($ra_value));
45
-                            } elseif (is_object($ra_value) && $ra_value instanceof ResponseAddress) {
46
-                                array_push($this->{$key}, $ra_value);
47
-                            }
48
-                        }
49
-                    } else {
50
-                        $this->{$key} = $params[$key];
51
-                    }
52
-                }
53
-            }
54
-        }
55
-    }
35
+	public function __construct(?array $params = null)
36
+	{
37
+		if ($params !== null) {
38
+			foreach ($this as $key => $value) {
39
+				if (isset($params[$key])) {
40
+					if ($key === 'results') {
41
+						$this->{$key} = array();
42
+						foreach ($params[$key] as $ra_key => $ra_value) {
43
+							if (is_array($ra_value)) {
44
+								array_push($this->{$key}, new ResponseAddress($ra_value));
45
+							} elseif (is_object($ra_value) && $ra_value instanceof ResponseAddress) {
46
+								array_push($this->{$key}, $ra_value);
47
+							}
48
+						}
49
+					} else {
50
+						$this->{$key} = $params[$key];
51
+					}
52
+				}
53
+			}
54
+		}
55
+	}
56 56
 }
Please login to merge, or discard this patch.
src/Route4Me/Route4Me.php 1 patch
Indentation   +363 added lines, -363 removed lines patch added patch discarded remove patch
@@ -7,367 +7,367 @@
 block discarded – undo
7 7
 
8 8
 class Route4Me
9 9
 {
10
-    public static $apiKey;
11
-    public static $baseUrl = Endpoint::BASE_URL;
12
-
13
-    public static function setApiKey($apiKey)
14
-    {
15
-        self::$apiKey = $apiKey;
16
-    }
17
-
18
-    public static function getApiKey()
19
-    {
20
-        return self::$apiKey;
21
-    }
22
-
23
-    public static function setBaseUrl($baseUrl)
24
-    {
25
-        self::$baseUrl = $baseUrl;
26
-    }
27
-
28
-    public static function getBaseUrl()
29
-    {
30
-        return self::$baseUrl;
31
-    }
32
-
33
-    /**
34
-     * Make request with CURL
35
-     *
36
-     * @since 1.2.3 changed error handling
37
-     * @since 1.2.8 added $options['return_headers']
38
-     *
39
-     * @param array  $options
40
-     *   string url                        - HTTP URL.
41
-     *   string method                     - HTTP method.
42
-     *   string api_key                    - API key to access to route4me server.
43
-     *   array  query                      - Array of query parameters.
44
-     *   array  body                       - Array of body parameters.
45
-     *   string HTTPHEADER                 - Content type of body e.g.
46
-     *                                       'Content-Type: application/json'
47
-     *                                       'Content-Type: multipart/form-data'
48
-     *   array  HTTPHEADERS                - Array of headers.
49
-     *   string FILE                       - Path to uploading file.
50
-     *   array  return_headers             - Array of response headers to return as a result.
51
-     * @throws Exception\ApiError
52
-     */
53
-    public static function makeRequst($options)
54
-    {
55
-        $method = isset($options['method']) ? $options['method'] : 'GET';
56
-        $query = isset($options['query'])
57
-            ? array_filter($options['query'], function ($x) {
58
-                return !is_null($x);
59
-            }) : [];
60
-
61
-        $body = isset($options['body']) ? $options['body'] : null;
62
-        $file = isset($options['FILE']) ? $options['FILE'] : null;
63
-        $headers = [
64
-            'User-Agent: Route4Me php-sdk',
65
-        ];
66
-
67
-        $return_headers = (isset($options['return_headers']) ? $options['return_headers'] : null);
68
-
69
-        if (isset($options['HTTPHEADER'])) {
70
-            $headers[] = $options['HTTPHEADER'];
71
-        }
72
-
73
-        if (isset($options['HTTPHEADERS'])) {
74
-            foreach ($options['HTTPHEADERS'] as $header) {
75
-                $headers[] = $header;
76
-            }
77
-        }
78
-
79
-        $ch = curl_init();
80
-
81
-        $url = isset($options['url'])
82
-            ? $options['url'] . '?' . http_build_query(array_merge(
83
-                $query,
84
-                ['api_key' => self::getApiKey()]
85
-            )) : '';
86
-
87
-        $baseUrl = self::getBaseUrl();
88
-
89
-        $curlOpts = [
90
-            CURLOPT_URL             => $baseUrl.$url,
91
-            CURLOPT_RETURNTRANSFER  => true,
92
-            CURLOPT_TIMEOUT         => 120,
93
-            CURLOPT_FOLLOWLOCATION  => true,
94
-            CURLOPT_SSL_VERIFYHOST  => false,
95
-            CURLOPT_SSL_VERIFYPEER  => false,
96
-            CURLOPT_HTTPHEADER      => $headers,
97
-        ];
98
-
99
-        curl_setopt_array($ch, $curlOpts);
100
-
101
-        // read response headers if need
102
-        $response_headers = [];
103
-        if ($return_headers) {
104
-            curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$response_headers) {
105
-                $len = strlen($header);
106
-                $header = explode(':', $header, 2);
107
-                if (count($header) >= 2) {
108
-                    $response_headers[strtolower(trim($header[0]))] = trim($header[1]);
109
-                }
110
-                return $len;
111
-            });
112
-        }
113
-
114
-        if (null != $file) {
115
-            $cfile = new \CURLFile($file, '', '');
116
-            $body['strFilename']=$cfile;
117
-            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
118
-            curl_setopt($ch, CURLOPT_POST, true);
119
-            curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
120
-        } else {
121
-            switch ($method) {
122
-                case 'DELETE':
123
-                    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
124
-                    break;
125
-                case 'DELETEARRAY':
126
-                    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
127
-                    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query));
128
-                    break;
129
-                case 'PUT':
130
-                    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
131
-                    break;
132
-                case 'POST':
133
-                    if (isset($body)) {
134
-                        $bodyData = json_encode($body);
135
-                        if (isset($options['HTTPHEADER'])) {
136
-                            if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) {
137
-                                $bodyData = $body;
138
-                            }
139
-                        }
140
-                        curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData);
141
-                    }
142
-                    break;
143
-                case 'ADD':
144
-                    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query));
145
-                    break;
146
-                case 'PATCH':
147
-                    if (isset($body)) {
148
-                        $bodyData = json_encode($body);
149
-                        if (isset($options['HTTPHEADER'])) {
150
-                            if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) {
151
-                                $bodyData = $body;
152
-                            }
153
-                        }
154
-                        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
155
-                        curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData);
156
-                    }
157
-                    break;
158
-            }
159
-
160
-            if (is_numeric(array_search($method, ['DELETE', 'PUT']))) {
161
-                if (isset($body)) {
162
-                    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
163
-                }
164
-            }
165
-        }
166
-
167
-        $result = curl_exec($ch);
168
-        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
169
-        curl_close($ch);
170
-
171
-        $json = null;
172
-        if (strpos($result, '<?xml') > -1) {
173
-            $xml = simplexml_load_string($result);
174
-            $json = self::object2array($xml);
175
-        } else {
176
-            $json = json_decode($result, true);
177
-        }
178
-        if (200 == $code || 201 == $code || 202 == $code) {
179
-            if (isset($json['errors'])) {
180
-                throw new ApiError(implode(', ', $json['errors']), $code, $result);
181
-            } else {
182
-                // return response headers if they were asked for
183
-                if (count($response_headers) !== 0) {
184
-                    $res = [
185
-                        'code' => $code,
186
-                        'data' => $json
187
-                    ];
188
-                    foreach ($return_headers as $key => $value) {
189
-                        // most headers has char '-' but it is forbidden in PHP names replace it with '_'
190
-                        $res[strtolower(str_replace('-', '_', $value))] =
191
-                            (isset($response_headers[$value]) ? $response_headers[$value] : null);
192
-                    }
193
-                    return $res;
194
-                }
195
-                return $json;
196
-            }
197
-        } elseif (isset($code) && (!isset($result) || !$result)) {
198
-            throw new ApiError('', $code, $result);
199
-        } else {
200
-            if (isset($json['messages'])) {
201
-                $msg = '';
202
-                foreach ($json['messages'] as $key => $value) {
203
-                    if ($msg !== '') {
204
-                        $msg .= PHP_EOL;
205
-                    }
206
-                    $msg .= $key . ': ' . implode(', ', $value);
207
-                }
208
-                throw new ApiError($msg, $code, $result);
209
-            } elseif (isset($json['errors'])) {
210
-                $msg = '';
211
-                foreach ($json['errors'] as $key => $value) {
212
-                    if ($msg !== '') {
213
-                        $msg .= PHP_EOL;
214
-                    }
215
-                    $msg .= $value;
216
-                }
217
-                throw new ApiError($msg, $code, $result);
218
-            } else {
219
-                throw new ApiError($result, $code, $result);
220
-            }
221
-        }
222
-    }
223
-
224
-    /**
225
-     * @param $object: JSON object
226
-     */
227
-    public static function object2array($object)
228
-    {
229
-        return @json_decode(@json_encode($object), 1);
230
-    }
231
-
232
-    /**
233
-     * Prints on the screen main keys and values of the array.
234
-     *
235
-     * @param $results: object to be printed on the screen
236
-     * @param $deepPrinting: if true, object will be printed recursively
237
-     */
238
-    public static function simplePrint($results, $deepPrinting = null)
239
-    {
240
-        if (isset($results)) {
241
-            if (is_array($results)) {
242
-                foreach ($results as $key => $result) {
243
-                    if (is_array($result)) {
244
-                        foreach ($result as $key1 => $result1) {
245
-                            if (is_array($result1)) {
246
-                                if ($deepPrinting) {
247
-                                    echo "<br>$key1 ------><br>";
248
-                                    self::simplePrint($result1, true);
249
-                                    echo '------<br>';
250
-                                } else {
251
-                                    echo $key1.' --> '.'Array() <br>';
252
-                                }
253
-                            } else {
254
-                                if (is_object($result1)) {
255
-                                    if ($deepPrinting) {
256
-                                        echo "<br>$key1 ------><br>";
257
-                                        $oarray = (array) $result1;
258
-                                        self::simplePrint($oarray, true);
259
-                                        echo '------<br>';
260
-                                    } else {
261
-                                        echo $key1.' --> '.'Object <br>';
262
-                                    }
263
-                                } else {
264
-                                    if (!is_null($result1)) {
265
-                                        echo $key1.' --> '.$result1.'<br>';
266
-                                    }
267
-                                }
268
-                            }
269
-                        }
270
-                    } else {
271
-                        if (is_object($result)) {
272
-                            if ($deepPrinting) {
273
-                                echo "<br>$key ------><br>";
274
-                                $oarray = (array) $result;
275
-                                self::simplePrint($oarray, true);
276
-                                echo '------<br>';
277
-                            } else {
278
-                                echo $key.' --> '.'Object <br>';
279
-                            }
280
-                        } else {
281
-                            if (!is_null($result)) {
282
-                                echo $key.' --> '.$result.'<br>';
283
-                            }
284
-                        }
285
-                    }
286
-                    //echo "<br>";
287
-                }
288
-            }
289
-        }
290
-    }
291
-
292
-    /**
293
-     * Generates query or body parameters.
294
-     *
295
-     * @param $allFields: all known fields could be used for parameters generation
296
-     * @param $params: input parameters (array or object)
297
-     */
298
-    public static function generateRequestParameters($allFields, $params)
299
-    {
300
-        $generatedParams = [];
301
-
302
-        if (is_array($params)) {
303
-            foreach ($allFields as $field) {
304
-                if (isset($params[$field])) {
305
-                    $generatedParams[$field] = $params[$field];
306
-                }
307
-            }
308
-        } elseif (is_object($params)) {
309
-            foreach ($allFields as $field) {
310
-                if (isset($params->{$field})) {
311
-                    $generatedParams[$field] = $params->{$field};
312
-                }
313
-            }
314
-        }
315
-
316
-        return $generatedParams;
317
-    }
318
-
319
-    /**
320
-     * Returns an array of the object properties.
321
-     *
322
-     * @param $object: An object
323
-     * @param $exclude: array of the object parameters to be excluded from the returned array
324
-     */
325
-    public static function getObjectProperties($object, $exclude)
326
-    {
327
-        $objectParameters = [];
328
-
329
-        foreach (get_object_vars($object) as $key => $value) {
330
-            if (property_exists($object, $key)) {
331
-                if (!is_numeric(array_search($key, $exclude))) {
332
-                    array_push($objectParameters, $key);
333
-                }
334
-            }
335
-        }
336
-
337
-        return $objectParameters;
338
-    }
339
-
340
-    /**
341
-     * Returns url path generated from the array of the fields and parameters.
342
-     *
343
-     * @param $allFields; array of the paossible fields (parameter names)
344
-     * @param $params: input parameters (array or object)
345
-     */
346
-    public static function generateUrlPath($allFields, $params)
347
-    {
348
-        $generatedPath = '';
349
-
350
-        if (is_array($params)) {
351
-            foreach ($allFields as $field) {
352
-                if (isset($params[$field])) {
353
-                    $generatedPath .= $params[$field].'/';
354
-                }
355
-            }
356
-        } elseif (is_object($params)) {
357
-            foreach ($allFields as $field) {
358
-                if (isset($params->{$field})) {
359
-                    $generatedPath .= $params->{$field}.'/';
360
-                }
361
-            }
362
-        }
363
-
364
-        return $generatedPath;
365
-    }
366
-
367
-    public static function getFileRealPath($fileName)
368
-    {
369
-        $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName);
370
-
371
-        return $rpath;
372
-    }
10
+	public static $apiKey;
11
+	public static $baseUrl = Endpoint::BASE_URL;
12
+
13
+	public static function setApiKey($apiKey)
14
+	{
15
+		self::$apiKey = $apiKey;
16
+	}
17
+
18
+	public static function getApiKey()
19
+	{
20
+		return self::$apiKey;
21
+	}
22
+
23
+	public static function setBaseUrl($baseUrl)
24
+	{
25
+		self::$baseUrl = $baseUrl;
26
+	}
27
+
28
+	public static function getBaseUrl()
29
+	{
30
+		return self::$baseUrl;
31
+	}
32
+
33
+	/**
34
+	 * Make request with CURL
35
+	 *
36
+	 * @since 1.2.3 changed error handling
37
+	 * @since 1.2.8 added $options['return_headers']
38
+	 *
39
+	 * @param array  $options
40
+	 *   string url                        - HTTP URL.
41
+	 *   string method                     - HTTP method.
42
+	 *   string api_key                    - API key to access to route4me server.
43
+	 *   array  query                      - Array of query parameters.
44
+	 *   array  body                       - Array of body parameters.
45
+	 *   string HTTPHEADER                 - Content type of body e.g.
46
+	 *                                       'Content-Type: application/json'
47
+	 *                                       'Content-Type: multipart/form-data'
48
+	 *   array  HTTPHEADERS                - Array of headers.
49
+	 *   string FILE                       - Path to uploading file.
50
+	 *   array  return_headers             - Array of response headers to return as a result.
51
+	 * @throws Exception\ApiError
52
+	 */
53
+	public static function makeRequst($options)
54
+	{
55
+		$method = isset($options['method']) ? $options['method'] : 'GET';
56
+		$query = isset($options['query'])
57
+			? array_filter($options['query'], function ($x) {
58
+				return !is_null($x);
59
+			}) : [];
60
+
61
+		$body = isset($options['body']) ? $options['body'] : null;
62
+		$file = isset($options['FILE']) ? $options['FILE'] : null;
63
+		$headers = [
64
+			'User-Agent: Route4Me php-sdk',
65
+		];
66
+
67
+		$return_headers = (isset($options['return_headers']) ? $options['return_headers'] : null);
68
+
69
+		if (isset($options['HTTPHEADER'])) {
70
+			$headers[] = $options['HTTPHEADER'];
71
+		}
72
+
73
+		if (isset($options['HTTPHEADERS'])) {
74
+			foreach ($options['HTTPHEADERS'] as $header) {
75
+				$headers[] = $header;
76
+			}
77
+		}
78
+
79
+		$ch = curl_init();
80
+
81
+		$url = isset($options['url'])
82
+			? $options['url'] . '?' . http_build_query(array_merge(
83
+				$query,
84
+				['api_key' => self::getApiKey()]
85
+			)) : '';
86
+
87
+		$baseUrl = self::getBaseUrl();
88
+
89
+		$curlOpts = [
90
+			CURLOPT_URL             => $baseUrl.$url,
91
+			CURLOPT_RETURNTRANSFER  => true,
92
+			CURLOPT_TIMEOUT         => 120,
93
+			CURLOPT_FOLLOWLOCATION  => true,
94
+			CURLOPT_SSL_VERIFYHOST  => false,
95
+			CURLOPT_SSL_VERIFYPEER  => false,
96
+			CURLOPT_HTTPHEADER      => $headers,
97
+		];
98
+
99
+		curl_setopt_array($ch, $curlOpts);
100
+
101
+		// read response headers if need
102
+		$response_headers = [];
103
+		if ($return_headers) {
104
+			curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$response_headers) {
105
+				$len = strlen($header);
106
+				$header = explode(':', $header, 2);
107
+				if (count($header) >= 2) {
108
+					$response_headers[strtolower(trim($header[0]))] = trim($header[1]);
109
+				}
110
+				return $len;
111
+			});
112
+		}
113
+
114
+		if (null != $file) {
115
+			$cfile = new \CURLFile($file, '', '');
116
+			$body['strFilename']=$cfile;
117
+			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
118
+			curl_setopt($ch, CURLOPT_POST, true);
119
+			curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
120
+		} else {
121
+			switch ($method) {
122
+				case 'DELETE':
123
+					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
124
+					break;
125
+				case 'DELETEARRAY':
126
+					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
127
+					curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query));
128
+					break;
129
+				case 'PUT':
130
+					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
131
+					break;
132
+				case 'POST':
133
+					if (isset($body)) {
134
+						$bodyData = json_encode($body);
135
+						if (isset($options['HTTPHEADER'])) {
136
+							if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) {
137
+								$bodyData = $body;
138
+							}
139
+						}
140
+						curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData);
141
+					}
142
+					break;
143
+				case 'ADD':
144
+					curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query));
145
+					break;
146
+				case 'PATCH':
147
+					if (isset($body)) {
148
+						$bodyData = json_encode($body);
149
+						if (isset($options['HTTPHEADER'])) {
150
+							if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) {
151
+								$bodyData = $body;
152
+							}
153
+						}
154
+						curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
155
+						curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData);
156
+					}
157
+					break;
158
+			}
159
+
160
+			if (is_numeric(array_search($method, ['DELETE', 'PUT']))) {
161
+				if (isset($body)) {
162
+					curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
163
+				}
164
+			}
165
+		}
166
+
167
+		$result = curl_exec($ch);
168
+		$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
169
+		curl_close($ch);
170
+
171
+		$json = null;
172
+		if (strpos($result, '<?xml') > -1) {
173
+			$xml = simplexml_load_string($result);
174
+			$json = self::object2array($xml);
175
+		} else {
176
+			$json = json_decode($result, true);
177
+		}
178
+		if (200 == $code || 201 == $code || 202 == $code) {
179
+			if (isset($json['errors'])) {
180
+				throw new ApiError(implode(', ', $json['errors']), $code, $result);
181
+			} else {
182
+				// return response headers if they were asked for
183
+				if (count($response_headers) !== 0) {
184
+					$res = [
185
+						'code' => $code,
186
+						'data' => $json
187
+					];
188
+					foreach ($return_headers as $key => $value) {
189
+						// most headers has char '-' but it is forbidden in PHP names replace it with '_'
190
+						$res[strtolower(str_replace('-', '_', $value))] =
191
+							(isset($response_headers[$value]) ? $response_headers[$value] : null);
192
+					}
193
+					return $res;
194
+				}
195
+				return $json;
196
+			}
197
+		} elseif (isset($code) && (!isset($result) || !$result)) {
198
+			throw new ApiError('', $code, $result);
199
+		} else {
200
+			if (isset($json['messages'])) {
201
+				$msg = '';
202
+				foreach ($json['messages'] as $key => $value) {
203
+					if ($msg !== '') {
204
+						$msg .= PHP_EOL;
205
+					}
206
+					$msg .= $key . ': ' . implode(', ', $value);
207
+				}
208
+				throw new ApiError($msg, $code, $result);
209
+			} elseif (isset($json['errors'])) {
210
+				$msg = '';
211
+				foreach ($json['errors'] as $key => $value) {
212
+					if ($msg !== '') {
213
+						$msg .= PHP_EOL;
214
+					}
215
+					$msg .= $value;
216
+				}
217
+				throw new ApiError($msg, $code, $result);
218
+			} else {
219
+				throw new ApiError($result, $code, $result);
220
+			}
221
+		}
222
+	}
223
+
224
+	/**
225
+	 * @param $object: JSON object
226
+	 */
227
+	public static function object2array($object)
228
+	{
229
+		return @json_decode(@json_encode($object), 1);
230
+	}
231
+
232
+	/**
233
+	 * Prints on the screen main keys and values of the array.
234
+	 *
235
+	 * @param $results: object to be printed on the screen
236
+	 * @param $deepPrinting: if true, object will be printed recursively
237
+	 */
238
+	public static function simplePrint($results, $deepPrinting = null)
239
+	{
240
+		if (isset($results)) {
241
+			if (is_array($results)) {
242
+				foreach ($results as $key => $result) {
243
+					if (is_array($result)) {
244
+						foreach ($result as $key1 => $result1) {
245
+							if (is_array($result1)) {
246
+								if ($deepPrinting) {
247
+									echo "<br>$key1 ------><br>";
248
+									self::simplePrint($result1, true);
249
+									echo '------<br>';
250
+								} else {
251
+									echo $key1.' --> '.'Array() <br>';
252
+								}
253
+							} else {
254
+								if (is_object($result1)) {
255
+									if ($deepPrinting) {
256
+										echo "<br>$key1 ------><br>";
257
+										$oarray = (array) $result1;
258
+										self::simplePrint($oarray, true);
259
+										echo '------<br>';
260
+									} else {
261
+										echo $key1.' --> '.'Object <br>';
262
+									}
263
+								} else {
264
+									if (!is_null($result1)) {
265
+										echo $key1.' --> '.$result1.'<br>';
266
+									}
267
+								}
268
+							}
269
+						}
270
+					} else {
271
+						if (is_object($result)) {
272
+							if ($deepPrinting) {
273
+								echo "<br>$key ------><br>";
274
+								$oarray = (array) $result;
275
+								self::simplePrint($oarray, true);
276
+								echo '------<br>';
277
+							} else {
278
+								echo $key.' --> '.'Object <br>';
279
+							}
280
+						} else {
281
+							if (!is_null($result)) {
282
+								echo $key.' --> '.$result.'<br>';
283
+							}
284
+						}
285
+					}
286
+					//echo "<br>";
287
+				}
288
+			}
289
+		}
290
+	}
291
+
292
+	/**
293
+	 * Generates query or body parameters.
294
+	 *
295
+	 * @param $allFields: all known fields could be used for parameters generation
296
+	 * @param $params: input parameters (array or object)
297
+	 */
298
+	public static function generateRequestParameters($allFields, $params)
299
+	{
300
+		$generatedParams = [];
301
+
302
+		if (is_array($params)) {
303
+			foreach ($allFields as $field) {
304
+				if (isset($params[$field])) {
305
+					$generatedParams[$field] = $params[$field];
306
+				}
307
+			}
308
+		} elseif (is_object($params)) {
309
+			foreach ($allFields as $field) {
310
+				if (isset($params->{$field})) {
311
+					$generatedParams[$field] = $params->{$field};
312
+				}
313
+			}
314
+		}
315
+
316
+		return $generatedParams;
317
+	}
318
+
319
+	/**
320
+	 * Returns an array of the object properties.
321
+	 *
322
+	 * @param $object: An object
323
+	 * @param $exclude: array of the object parameters to be excluded from the returned array
324
+	 */
325
+	public static function getObjectProperties($object, $exclude)
326
+	{
327
+		$objectParameters = [];
328
+
329
+		foreach (get_object_vars($object) as $key => $value) {
330
+			if (property_exists($object, $key)) {
331
+				if (!is_numeric(array_search($key, $exclude))) {
332
+					array_push($objectParameters, $key);
333
+				}
334
+			}
335
+		}
336
+
337
+		return $objectParameters;
338
+	}
339
+
340
+	/**
341
+	 * Returns url path generated from the array of the fields and parameters.
342
+	 *
343
+	 * @param $allFields; array of the paossible fields (parameter names)
344
+	 * @param $params: input parameters (array or object)
345
+	 */
346
+	public static function generateUrlPath($allFields, $params)
347
+	{
348
+		$generatedPath = '';
349
+
350
+		if (is_array($params)) {
351
+			foreach ($allFields as $field) {
352
+				if (isset($params[$field])) {
353
+					$generatedPath .= $params[$field].'/';
354
+				}
355
+			}
356
+		} elseif (is_object($params)) {
357
+			foreach ($allFields as $field) {
358
+				if (isset($params->{$field})) {
359
+					$generatedPath .= $params->{$field}.'/';
360
+				}
361
+			}
362
+		}
363
+
364
+		return $generatedPath;
365
+	}
366
+
367
+	public static function getFileRealPath($fileName)
368
+	{
369
+		$rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName);
370
+
371
+		return $rpath;
372
+	}
373 373
 }
Please login to merge, or discard this patch.