Term::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Ctefan\Kiwi;
5
6
class Term
7
{
8
    /**
9
     * @var Variable
10
     */
11
    protected $variable;
12
13
    /**
14
     * @var float
15
     */
16
    protected $coefficient;
17
18
    /**
19
     * Term constructor.
20
     *
21
     * @param Variable $variable
22
     * @param float $coefficient
23
     */
24 21
    public function __construct(Variable $variable, float $coefficient = 1.0)
25
    {
26 21
        $this->variable = $variable;
27 21
        $this->coefficient = $coefficient;
28 21
    }
29
30
    /**
31
     * @return float
32
     */
33
    public function getValue(): float
34
    {
35
        return $this->coefficient * $this->variable->getValue();
36
    }
37
38
    /**
39
     * @return Variable
40
     */
41 21
    public function getVariable(): Variable
42
    {
43 21
        return $this->variable;
44
    }
45
46
    /**
47
     * @param Variable $variable
48
     */
49
    public function setVariable(Variable $variable): void
50
    {
51
        $this->variable = $variable;
52
    }
53
54
    /**
55
     * @return float
56
     */
57 21
    public function getCoefficient(): float
58
    {
59 21
        return $this->coefficient;
60
    }
61
62
    /**
63
     * @param float $coefficient
64
     */
65
    public function setCoefficient(float $coefficient): void
66
    {
67
        $this->coefficient = $coefficient;
68
    }
69
}