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

Level   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 58
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setFromAgeGrade() 0 11 3
A getClass() 0 4 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 Level
15
{
16
    /** @var int */
17
    const UNCLASSIFIED = 0;
18
19
    /** @var int */
20
    const LOCAL_CLASS = 1;
21
22
    /** @var int */
23
    const REGIONAL_CLASS = 2;
24
25
    /** @var int */
26
    const NATIONAL_CLASS = 3;
27
28
    /** @var int */
29
    const WORLD_CLASS = 4;
30
31
    /** @var int */
32
    const WORLD_RECORD_CLASS = 5;
33
34
    /** @var array */
35
    protected $Limits = [0.0, 0.6, 0.7, 0.8, 0.9, 1.0];
36
37
    /** @var int */
38
    protected $Class = 0;
39
40
    /**
41
     * @param float $ageGrade
42
     */
43 4
    public function __construct($ageGrade = 0.0)
44
    {
45 4
        $this->setFromAgeGrade($ageGrade);
46 4
    }
47
48
    /**
49
     * @param  float $ageGrade in [0.0 .. 1.0]
50
     * @return int
51
     */
52 4
    public function setFromAgeGrade($ageGrade)
53
    {
54 4
        foreach (array_reverse($this->Limits, true) as $class => $lowerLimit) {
55 4
            if ($ageGrade >= $lowerLimit) {
56 4
                $this->Class = $class;
0 ignored issues
show
Documentation Bug introduced by
It seems like $class can also be of type string. However, the property $Class is declared as type integer. 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...
57 4
                break;
58
            }
59 4
        }
60
61 4
        return $this->Class;
62
    }
63
64
    /**
65
     * @return int
66
     */
67 3
    public function getClass()
68
    {
69 3
        return $this->Class;
70
    }
71
}
72