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

Lookup::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 2
crap 3
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
use Runalyze\AgeGrade\Table\TableInterface;
15
16
class Lookup
17
{
18
    /** @var TableInterface */
19
    protected $Table;
20
21
    /** @var int [years] */
22
    protected $Age;
23
24
    /**
25
     * @param TableInterface $table
26
     * @param int            $age   [years]
27
     *
28
     * @throws \InvalidArgumentException
29
     */
30 4
    public function __construct(TableInterface $table, $age)
31
    {
32 4
        if (!is_numeric($age) || $age <= 0) {
33 1
            throw new \InvalidArgumentException('Provided age must be numerical and positive.');
34
        }
35
36 3
        $this->Table = $table;
37 3
        $this->Age = $age;
0 ignored issues
show
Documentation Bug introduced by
It seems like $age can also be of type double or string. However, the property $Age 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...
38 3
    }
39
40
    /**
41
     * @param  float $distance      [km]
42
     * @param  int   $timeInSeconds [s]
43
     * @return float
44
     */
45 3
    public function getAgePerformance($distance, $timeInSeconds)
46
    {
47 3
        return $this->Table->getAgePerformance($this->Age, $distance, $timeInSeconds);
48
    }
49
50
    /**
51
     * @param  float    $distance      [km]
52
     * @param  int      $timeInSeconds [s]
53
     * @return AgeGrade
54
     */
55 1
    public function getAgeGrade($distance, $timeInSeconds)
56
    {
57 1
        return $this->Table->getAgeGrade($this->Age, $distance, $timeInSeconds);
58
    }
59
}
60