BaseHttp   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 16
c 1
b 0
f 0
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A send() 0 16 6
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);
0 ignored issues
show
Unused Code introduced by
The call to MedianetDev\PConnector\Contracts\Http::get() has too many arguments starting with $withJson. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
                return $this->/** @scrutinizer ignore-call */ get($url, $data, $profile, $withAuth, $headers, $withJson);

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.

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