|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MedianetDev\PConnector\Http\Base; |
|
4
|
|
|
|
|
5
|
|
|
use MedianetDev\PConnector\AuthManager; |
|
6
|
|
|
use MedianetDev\PConnector\Contracts\Http; |
|
7
|
|
|
|
|
8
|
|
|
abstract class BaseHttp implements Http |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var \MedianetDev\PConnector\AuthManager |
|
12
|
|
|
* |
|
13
|
|
|
* The auth manager instance |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $authManager; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct($withAuth = true) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->authManager = $withAuth ? new AuthManager() : null; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function send(string $url, $data, string $method, string $profile, bool $withAuth, array $headers = [], bool $withJson = false): array |
|
23
|
|
|
{ |
|
24
|
|
|
switch (strtoupper($method)) { |
|
25
|
|
|
case 'POST': |
|
26
|
|
|
return $this->post($url, $data, $profile, $withAuth, $headers); |
|
27
|
|
|
case 'GET': |
|
28
|
|
|
return $this->get($url, $data, $profile, $withAuth, $headers, $withJson); |
|
|
|
|
|
|
29
|
|
|
case 'PUT': |
|
30
|
|
|
return $this->put($url, $data, $profile, $withAuth, $headers); |
|
31
|
|
|
case 'PATCH': |
|
32
|
|
|
return $this->patch($url, $data, $profile, $withAuth, $headers); |
|
33
|
|
|
case 'DELETE': |
|
34
|
|
|
return $this->delete($url, $data, $profile, $withAuth, $headers); |
|
35
|
|
|
|
|
36
|
|
|
default: |
|
37
|
|
|
throw new \InvalidArgumentException('Unrecognized "'.strtoupper($method).'" method, |
|
38
|
|
|
supported methods are: "POST", "GET", "PUT" , "PATCH" and "DELETE"'); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Return the sent request data and the response with a status to indicate if the is an error or not. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $url |
|
46
|
|
|
* @param string $method |
|
47
|
|
|
* @param array $payload |
|
48
|
|
|
* @param mixed $response |
|
49
|
|
|
* @param bool $status |
|
50
|
|
|
* @param string $errorMessage |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
abstract protected function parser(string $url, string $method, array $payload, $response, bool $status = true, ?string $errorMessage = null): array; |
|
54
|
|
|
} |
|
55
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.