Completed
Push — master ( 8f7d6a...a27e32 )
by Hannes
02:14
created

AgeGrade::setTableData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $performance can also be of type integer or string. However, the property $Performance 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...
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);
0 ignored issues
show
Documentation Bug introduced by
It seems like round($ageStandard) of type double is incompatible with the declared type null|integer of property $AgeStandard.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
77 3
        $this->OpenStandard = round($ageStandard * $ageFactor);
0 ignored issues
show
Documentation Bug introduced by
It seems like round($ageStandard * $ageFactor) of type double is incompatible with the declared type null|integer of property $OpenStandard.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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