|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Runalyze Age Grade. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) RUNALYZE <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Runalyze\AgeGrade; |
|
13
|
|
|
|
|
14
|
|
|
class AgeGrade |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var float */ |
|
17
|
|
|
protected $Performance; |
|
18
|
|
|
|
|
19
|
|
|
/** @var null|float [km] */ |
|
20
|
|
|
protected $OriginalDistance = null; |
|
21
|
|
|
|
|
22
|
|
|
/** @var null|int [s] */ |
|
23
|
|
|
protected $OriginalTimeInSeconds = null; |
|
24
|
|
|
|
|
25
|
|
|
/** @var null|int [s] */ |
|
26
|
|
|
protected $AgeStandard = null; |
|
27
|
|
|
|
|
28
|
|
|
/** @var null|int [s] */ |
|
29
|
|
|
protected $OpenStandard = null; |
|
30
|
|
|
|
|
31
|
|
|
/** @var null|float */ |
|
32
|
|
|
protected $AgeFactor = null; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param float $performance |
|
36
|
|
|
* |
|
37
|
|
|
* @throws \InvalidArgumentException |
|
38
|
|
|
*/ |
|
39
|
6 |
|
public function __construct($performance) |
|
40
|
|
|
{ |
|
41
|
6 |
|
if (!is_numeric($performance)) { |
|
42
|
1 |
|
throw new \InvalidArgumentException('Provided performance must be numerical.'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
5 |
|
$this->Performance = $performance; |
|
|
|
|
|
|
46
|
5 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return string age grade performance with 4 decimals precision |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function __toString() |
|
52
|
|
|
{ |
|
53
|
1 |
|
return number_format($this->Performance, 4); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param float $distance [km] |
|
58
|
|
|
* @param int $timeInSeconds [s] |
|
59
|
|
|
* @return $this |
|
60
|
|
|
*/ |
|
61
|
3 |
|
public function setOriginalResult($distance, $timeInSeconds) |
|
62
|
|
|
{ |
|
63
|
3 |
|
$this->OriginalDistance = $distance; |
|
64
|
3 |
|
$this->OriginalTimeInSeconds = $timeInSeconds; |
|
65
|
|
|
|
|
66
|
3 |
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param int $ageStandard [s] |
|
71
|
|
|
* @param float $ageFactor |
|
72
|
|
|
* @return $this |
|
73
|
|
|
*/ |
|
74
|
3 |
|
public function setTableData($ageStandard, $ageFactor) |
|
75
|
|
|
{ |
|
76
|
3 |
|
$this->AgeStandard = round($ageStandard); |
|
|
|
|
|
|
77
|
3 |
|
$this->OpenStandard = round($ageStandard * $ageFactor); |
|
|
|
|
|
|
78
|
3 |
|
$this->AgeFactor = $ageFactor; |
|
79
|
|
|
|
|
80
|
3 |
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return float |
|
85
|
|
|
*/ |
|
86
|
3 |
|
public function getPerformance() |
|
87
|
|
|
{ |
|
88
|
3 |
|
return $this->Performance; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return float|null [km] |
|
93
|
|
|
*/ |
|
94
|
3 |
|
public function getOriginalDistance() |
|
95
|
|
|
{ |
|
96
|
3 |
|
return $this->OriginalDistance; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return int|null [s] |
|
101
|
|
|
*/ |
|
102
|
3 |
|
public function getOriginalTimeInSeconds() |
|
103
|
|
|
{ |
|
104
|
3 |
|
return $this->OriginalTimeInSeconds; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return int|null [s] |
|
109
|
|
|
*/ |
|
110
|
3 |
|
public function getAgeStandard() |
|
111
|
|
|
{ |
|
112
|
3 |
|
return $this->AgeStandard; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return int|null [s] |
|
117
|
|
|
*/ |
|
118
|
3 |
|
public function getOpenStandard() |
|
119
|
|
|
{ |
|
120
|
3 |
|
return $this->OpenStandard; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @return float|null |
|
125
|
|
|
*/ |
|
126
|
3 |
|
public function getAgeFactor() |
|
127
|
|
|
{ |
|
128
|
3 |
|
return $this->AgeFactor; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return Level |
|
133
|
|
|
*/ |
|
134
|
1 |
|
public function getLevel() |
|
135
|
|
|
{ |
|
136
|
1 |
|
return new Level($this->Performance); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
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
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. 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.