Completed
Pull Request — develop (#28)
by Evan
03:05
created

ProviderCsvApiClient::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 2
1
<?php
2
/*
3
 * This file is part of the PayBreak/basket package.
4
 *
5
 * (c) PayBreak <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace PayBreak\Sdk\ApiClient;
12
13
use Psr\Http\Message\ResponseInterface;
14
use WNowicki\Generic\ApiClient\ErrorResponseException;
15
use WNowicki\Generic\ApiClient\WrongResponseException;
16
use Psr\Log\LoggerInterface;
17
18
/**
19
 * Class ProviderCsvApiClient
20
 *
21
 * @author EA
22
 * @package PayBreak\Sdk\ApiClient
23
 */
24
class ProviderCsvApiClient extends ProviderApiClient
25
{
26
    /**
27
     * @author WN
28
     * @param string $baseUrl
29
     * @param string $token
30
     * @param LoggerInterface $logger
31
     * @return ProviderApiClient
32
     */
33 View Code Duplication
    public static function make($baseUrl, $token = '', LoggerInterface $logger = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $ar = [];
36
        $ar['base_uri'] = $baseUrl;
37
38
        if ($token != '') {
39
40
            $ar['headers'] = ['Authorization' => 'ApiToken token="' . $token . '"'];
41
        }
42
43
        return new self($ar, $logger);
44
    }
45
46
    /**
47
     * @author EA
48
     * @param ResponseInterface $response
49
     * @return array
50
     * @throws WrongResponseException
51
     */
52
    protected function processResponse(ResponseInterface $response)
53
    {
54
        if ($response->getStatusCode() == 204) {
55
            return null;
56
        }
57
58
        if (strpos($response->getHeaderLine('Content-Type'), 'text/csv') !== false) {
59
            return ['csv' => $response->getBody()->getContents()] ;
60
        }
61
62
        throw new WrongResponseException('Response body was malformed csv', $response->getStatusCode());
63
    }
64
65
    /**
66
     * @author EA
67
     * @param string $uri
68
     * @param array $body
69
     * @param array $query
70
     * @return array
71
     * @throws ErrorResponseException
72
     * @throws \Exception
73
     */
74
    public function get($uri, array $body = [], array $query = [])
75
    {
76
        return parent::get($uri . '.csv', $body, $query);
0 ignored issues
show
Unused Code introduced by
The call to ProviderApiClient::get() has too many arguments starting with $query.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
77
    }
78
}
79