NumbersCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A total() 0 3 1
A all() 0 3 1
A get() 0 7 2
A add() 0 3 1
1
<?php
2
3
namespace Hotrush\AngularSweep;
4
5
class NumbersCollection
6
{
7
    /**
8
     * @var ComplexNumber[]
9
     */
10
    private $numbers = [];
11
12
    /**
13
     * @param ComplexNumber $number
14
     */
15
    public function add(ComplexNumber $number)
16
    {
17
        $this->numbers[] = $number;
18
    }
19
20
    /**
21
     * @return ComplexNumber[]
22
     */
23
    public function all()
24
    {
25
        return $this->numbers;
26
    }
27
28
    /**
29
     * @param $key
30
     * @return ComplexNumber
31
     */
32
    public function get($key)
33
    {
34
        if (!isset($this->numbers[$key])) {
35
            throw new \InvalidArgumentException('Number with this key doesn\'t exist');
36
        }
37
38
        return $this->numbers[$key];
39
    }
40
41
    /**
42
     * @return int
43
     */
44
    public function total()
45
    {
46
        return count($this->numbers);
47
    }
48
}