Completed
Push — master ( c5b39f...a40a3f )
by Shagiakhmetov
15:28 queued 13:47
created

TopDiff::getFromValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * @maintainer Timur Shagiakhmetov <[email protected]>
5
 */
6
7
namespace Badoo\LiveProfilerUI\Entity;
8
9
class TopDiff
10
{
11
    /** @var string */
12
    protected $app = '';
13
    /** @var string */
14
    protected $label = '';
15
    /** @var int */
16
    protected $method_id = 0;
17
    /** @var string */
18
    protected $method_name = '';
19
    /** @var float */
20
    protected $value;
21
    /** @var string */
22
    protected $from_value;
23
    /** @var string */
24
    protected $to_value;
25
    /** @var string */
26
    protected $formatted_value;
27
    /** @var float */
28
    protected $percent;
29
30 7
    public function __construct(array $data)
31
    {
32 7
        $this->app = isset($data['app']) ? trim($data['app']) : '';
33 7
        $this->label = isset($data['label']) ? trim($data['label']) : '';
34 7
        $this->method_id = isset($data['method_id']) ? (int)$data['method_id'] : 0;
35 7
        $this->value = isset($data['value']) ? (float)$data['value'] : 0;
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($data['value']) ? ...ble) $data['value'] : 0 can also be of type integer. However, the property $value is declared as type double. 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...
36 7
        $this->from_value = isset($data['from_value']) ? number_format((float)$data['from_value']) : '';
37 7
        $this->to_value = isset($data['to_value']) ? number_format((float)$data['to_value']) : '';
38 7
        $this->formatted_value = number_format($this->value);
39 7
        $this->percent = isset($data['percent']) ? (float)$data['percent'] : 0;
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($data['percent']) ...e) $data['percent'] : 0 can also be of type integer. However, the property $percent is declared as type double. 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...
40 7
    }
41
42 1
    public function getApp() : string
43
    {
44 1
        return $this->app;
45
    }
46
47 1
    public function setApp(string $app) : self
48
    {
49 1
        $this->app = $app;
50 1
        return $this;
51
    }
52
53 1
    public function getLabel() : string
54
    {
55 1
        return $this->label;
56
    }
57
58 1
    public function setLabel(string $label) : self
59
    {
60 1
        $this->label = $label;
61 1
        return $this;
62
    }
63
64 1
    public function getMethodId() : int
65
    {
66 1
        return $this->method_id;
67
    }
68
69 1
    public function setMethodId(int $method_id) : self
70
    {
71 1
        $this->method_id = $method_id;
72 1
        return $this;
73
    }
74
75 2
    public function getValue() : float
76
    {
77 2
        return $this->value;
78
    }
79
80 1
    public function getFormattedValue() : string
81
    {
82 1
        return $this->formatted_value;
83
    }
84
85 1
    public function setValue(float $value) : self
86
    {
87 1
        $this->value = $value;
88 1
        $this->formatted_value = number_format($this->value);
89 1
        return $this;
90
    }
91
92
    public function getFromValue() : string
93
    {
94
        return $this->from_value;
95
    }
96
97
    public function setFromValue(float $value) : self
98
    {
99
        $this->from_value = number_format($value);
100
        return $this;
101
    }
102
103
    public function getToValue() : string
104
    {
105
        return $this->to_value;
106
    }
107
108
    public function setToValue(float $value) : self
109
    {
110
        $this->to_value = number_format($value);
111
        return $this;
112
    }
113
    
114 1
    public function getPercent() : float
115
    {
116 1
        return $this->percent;
117
    }
118
119 1
    public function setPercent(float $percent) : self
120
    {
121 1
        $this->percent = $percent;
122 1
        return $this;
123
    }
124
125 1
    public function getMethodName() : string
126
    {
127 1
        return $this->method_name;
128
    }
129
130 1
    public function setMethodName(string $method_name) : self
131
    {
132 1
        $this->method_name = $method_name;
133 1
        return $this;
134
    }
135
}
136