Stat   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 64.15 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 34
loc 53
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 19 19 4
A total() 15 15 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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