Completed
Push — master ( daeb2d...c5b39f )
by Shagiakhmetov
21:42
created

TopDiff::setFromValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
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 7
    protected $formatted_value;
27
    /** @var float */
28 7
    protected $percent;
29 7
30 7
    public function __construct(array $data)
31 7
    {
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
        $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 1
        $this->from_value = isset($data['from_value']) ? number_format((float)$data['from_value']) : '';
37
        $this->to_value = isset($data['to_value']) ? number_format((float)$data['to_value']) : '';
38 1
        $this->formatted_value = number_format($this->value);
39
        $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
    }
41 1
42
    public function getApp() : string
43 1
    {
44 1
        return $this->app;
45
    }
46
47 1
    public function setApp(string $app) : self
48
    {
49 1
        $this->app = $app;
50
        return $this;
51
    }
52 1
53
    public function getLabel() : string
54 1
    {
55 1
        return $this->label;
56
    }
57
58 1
    public function setLabel(string $label) : self
59
    {
60 1
        $this->label = $label;
61
        return $this;
62
    }
63 1
64
    public function getMethodId() : int
65 1
    {
66 1
        return $this->method_id;
67
    }
68
69 2
    public function setMethodId(int $method_id) : self
70
    {
71 2
        $this->method_id = $method_id;
72
        return $this;
73
    }
74 1
75
    public function getValue() : float
76 1
    {
77
        return $this->value;
78
    }
79 1
80
    public function getFormattedValue() : string
81 1
    {
82 1
        return $this->formatted_value;
83 1
    }
84
85
    public function setValue(float $value) : self
86 1
    {
87
        $this->value = $value;
88 1
        $this->formatted_value = number_format($this->value);
89
        return $this;
90
    }
91 1
92
    public function getFromValue() : string
93 1
    {
94 1
        return $this->from_value;
95
    }
96
97 1
    public function setFromValue(float $value) : self
98
    {
99 1
        $this->from_value = number_format($value);
100
        return $this;
101
    }
102 1
103
    public function getToValue() : string
104 1
    {
105 1
        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
    public function getPercent() : float
115
    {
116
        return $this->percent;
117
    }
118
119
    public function setPercent(float $percent) : self
120
    {
121
        $this->percent = $percent;
122
        return $this;
123
    }
124
125
    public function getMethodName() : string
126
    {
127
        return $this->method_name;
128
    }
129
130
    public function setMethodName(string $method_name) : self
131
    {
132
        $this->method_name = $method_name;
133
        return $this;
134
    }
135
}
136