Stat::get()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 19
loc 19
ccs 0
cts 14
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 2
crap 20
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace FAPI\Boilerplate\Api;
11
12
use FAPI\Boilerplate\Exception;
13
use FAPI\Boilerplate\Exception\InvalidArgumentException;
14
use FAPI\Boilerplate\Model\Stat\Stat as StatModel;
15
use FAPI\Boilerplate\Model\Stat\Total;
16
use Psr\Http\Message\ResponseInterface;
17
18
/**
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
final class Stat extends HttpApi
22
{
23
    /**
24
     * @param string $username
25
     * @param array  $params
26
     *
27
     * @return StatModel|ResponseInterface
28
     *
29
     * @throws Exception
30
     */
31 View Code Duplication
    public function get(string $username, array $params = [])
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...
32
    {
33
        if (empty($username)) {
34
            throw new InvalidArgumentException('Username cannot be empty');
35
        }
36
37
        $response = $this->httpGet(sprintf('/v1/stats/%s', rawurlencode($username)), $params);
38
39
        if (!$this->hydrator) {
40
            return $response;
41
        }
42
43
        // Use any valid status code here
44
        if ($response->getStatusCode() !== 200) {
45
            $this->handleErrors($response);
46
        }
47
48
        return $this->hydrator->hydrate($response, StatModel::class);
49
    }
50
51
    /**
52
     * @param array $params
53
     *
54
     * @return Total|ResponseInterface
55
     *
56
     * @throws Exception
57
     */
58 View Code Duplication
    public function total(array $params = [])
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...
59
    {
60
        $response = $this->httpGet('/v1/stats', $params);
61
62
        if (!$this->hydrator) {
63
            return $response;
64
        }
65
66
        // Use any valid status code here
67
        if ($response->getStatusCode() !== 200) {
68
            $this->handleErrors($response);
69
        }
70
71
        return $this->hydrator->hydrate($response, Total::class);
72
    }
73
}
74