Completed
Push — master ( ee0bf4...f89977 )
by Hannes
03:46 queued 02:03
created

Item::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 4
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace byrokrat\billing;
6
7
use byrokrat\amount\Amount;
8
9
/**
10
 * Basic billable implementation
11
 */
12
class Item implements Billable
13
{
14
    /**
15
     * @var string
16
     */
17
    private $description;
18
19
    /**
20
     * @var Amount
21
     */
22
    private $unitCost;
23
24
    /**
25
     * @var int
26
     */
27
    private $units;
28
29
    /**
30
     * @var float
31
     */
32
    private $vat;
33
34
    /**
35
     * Set immutable data at construct
36
     *
37
     * Note that a VAT of 25% is represented as 25
38
     */
39 6
    public function __construct(string $description, Amount $unitCost, int $units = 1, float $vat = 25)
40
    {
41 6
        $this->description = $description;
42 6
        $this->unitCost = $unitCost;
43 6
        $this->units = $units;
44 6
        $this->vat = $vat;
0 ignored issues
show
Documentation Bug introduced by
It seems like $vat can also be of type integer. However, the property $vat 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...
45 6
    }
46
47 3
    public function getBillingDescription(): string
48
    {
49 3
        return $this->description;
50
    }
51
52 3
    public function getCostPerUnit(): Amount
53
    {
54 3
        return $this->unitCost;
55
    }
56
57 3
    public function getNrOfUnits(): int
58
    {
59 3
        return $this->units;
60
    }
61
62 3
    public function getVatRate(): float
63
    {
64 3
        return $this->vat;
65
    }
66
}
67