Completed
Push — master ( 39a0bd...0a53a0 )
by Fabian
02:26
created

OrderBookRequest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 59
loc 59
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequestData() 8 8 2
A __construct() 4 4 1
A getMethod() 3 3 1
A getVisibility() 3 3 1
A getResponseClassName() 3 3 1

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
namespace HanischIt\KrakenApi\Call\OrderBook;
4
5
use HanischIt\KrakenApi\Call\OrderBook\Model\OrderBookResponse;
6
use HanischIt\KrakenApi\Enum\VisibilityEnum;
7
use HanischIt\KrakenApi\Model\RequestInterface;
8
9
/**
10
 * Class OrderBookRequest
11
 * @package HanischIt\KrakenApi\Call\OrderBook
12
 */
13 View Code Duplication
class OrderBookRequest implements RequestInterface
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /**
16
     * @var
17
     */
18
    private $assetPair;
19
    /**
20
     * @var null
21
     */
22
    private $count;
23
24
    /**
25
     * OrderBookRequest constructor.
26
     * @param $assetPair
27
     * @param null|int $count
28
     */
29 2
    public function __construct($assetPair, $count = null)
30
    {
31 2
        $this->assetPair = $assetPair;
32 2
        $this->count = $count;
0 ignored issues
show
Documentation Bug introduced by
It seems like $count can also be of type integer. However, the property $count is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
33 2
    }
34
35
    /**
36
     * Returns the api request name
37
     *
38
     * @return string
39
     */
40 1
    public function getMethod()
41
    {
42 1
        return 'Depth';
43
    }
44
45
    /**
46
     * @return string
47
     */
48 1
    public function getVisibility()
49
    {
50 1
        return VisibilityEnum::VISIBILITY_PUBLIC;
51
    }
52
53
    /**
54
     * @return array
55
     */
56 1
    public function getRequestData()
57
    {
58 1
        $arr = [];
59 1
        $arr["pair"] = $this->assetPair;
60 1
        if ($this->count) {
61 1
            $arr["count"] = $this->count;
62 1
        }
63 1
        return $arr;
64
    }
65
66
    /**
67
     * @return string
68
     */
69 1
    public function getResponseClassName()
70
    {
71 1
        return OrderBookResponse::class;
72
    }
73
}
74