Score   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 0
dl 0
loc 147
rs 10
c 0
b 0
f 0
ccs 0
cts 39
cp 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A withScaled() 0 7 1
A withRaw() 0 7 1
A withMin() 0 7 1
A withMax() 0 7 1
A getScaled() 0 4 1
A getRaw() 0 4 1
A getMin() 0 4 1
A getMax() 0 4 1
B equals() 0 36 9
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Model;
13
14
/**
15
 * The outcome of an {@link Activity} achieved by an {@link Agent}.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
final class Score
20
{
21
    private $scaled;
22
    private $raw;
23
    private $min;
24
    private $max;
25
26
    /**
27
     * @param float|int|null $scaled
28
     * @param float|int|null $raw
29
     * @param float|int|null $min
30
     * @param float|int|null $max
31
     */
32
    public function __construct($scaled = null, $raw = null, $min = null, $max = null)
33
    {
34
        $this->scaled = $scaled;
35
        $this->raw = $raw;
36
        $this->min = $min;
37
        $this->max = $max;
38
    }
39
40
    /**
41
     * @param float|int|null $scaled
42
     */
43
    public function withScaled($scaled): self
44
    {
45
        $score = clone $this;
46
        $score->scaled = $scaled;
47
48
        return $score;
49
    }
50
51
    /**
52
     * @param float|int|null $raw
53
     */
54
    public function withRaw($raw): self
55
    {
56
        $score = clone $this;
57
        $score->raw = $raw;
58
59
        return $score;
60
    }
61
62
    /**
63
     * @param float|int|null $min
64
     */
65
    public function withMin($min): self
66
    {
67
        $score = clone $this;
68
        $score->min = $min;
69
70
        return $score;
71
    }
72
73
    /**
74
     * @param float|int|null $max
75
     */
76
    public function withMax($max): self
77
    {
78
        $score = clone $this;
79
        $score->max = $max;
80
81
        return $score;
82
    }
83
84
    /**
85
     * Returns the Agent's scaled score (a number between -1 and 1).
86
     *
87
     * @return float|int|null The scaled score
88
     */
89
    public function getScaled()
90
    {
91
        return $this->scaled;
92
    }
93
94
    /**
95
     * Returns the Agent's score (a number between min and max).
96
     *
97
     * @return float|int|null The score
98
     */
99
    public function getRaw()
100
    {
101
        return $this->raw;
102
    }
103
104
    /**
105
     * Returns the lowest possible score.
106
     *
107
     * @return float|int|null The lowest possible score
108
     */
109
    public function getMin()
110
    {
111
        return $this->min;
112
    }
113
114
    /**
115
     * Returns the highest possible score.
116
     *
117
     * @return float|int|null The highest possible score
118
     */
119
    public function getMax()
120
    {
121
        return $this->max;
122
    }
123
124
    /**
125
     * Checks if another score is equal.
126
     *
127
     * Two scores are equal if and only if all of their properties are equal.
128
     */
129
    public function equals(Score $score): bool
130
    {
131
        if (null !== $this->scaled xor null !== $score->scaled) {
132
            return false;
133
        }
134
135
        if ((float) $this->scaled !== (float) $score->scaled) {
136
            return false;
137
        }
138
139
        if (null !== $this->raw xor null !== $score->raw) {
140
            return false;
141
        }
142
143
        if ((float) $this->raw !== (float) $score->raw) {
144
            return false;
145
        }
146
147
        if (null !== $this->min xor null !== $score->min) {
148
            return false;
149
        }
150
151
        if ((float) $this->min !== (float) $score->min) {
152
            return false;
153
        }
154
155
        if (null !== $this->max xor null !== $score->max) {
156
            return false;
157
        }
158
159
        if ((float) $this->max !== (float) $score->max) {
160
            return false;
161
        }
162
163
        return true;
164
    }
165
}
166