Vector2   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 70
ccs 19
cts 19
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getX() 0 4 1
A setX() 0 4 1
A getY() 0 4 1
A setY() 0 4 1
A validateIndex() 0 6 3
1
<?php
2
3
namespace PHP\Math\Vector;
4
5
use InvalidArgumentException;
6
7
class Vector2 extends Vector
8
{
9
    /**
10
     * Initializes a new instance of this class.
11
     *
12
     * @param float $x The X-component to set.
13
     * @param float $y The Y-component to set.
14
     */
15 10
    public function __construct($x, $y)
16
    {
17 10
        parent::__construct(array());
18
19 10
        $this->setX($x);
20 10
        $this->setY($y);
21 10
    }
22
23
    /**
24
     * Gets the X-component from this vector.
25
     *
26
     * @return float
27
     */
28 3
    public function getX()
29
    {
30 3
        return $this->getElement(0);
31
    }
32
33
    /**
34
     * Sets the X-component in this vector.
35
     *
36
     * @param float $x The X-component to set
37
     */
38 10
    public function setX($x)
39
    {
40 10
        $this->setElement(0, $x);
41 10
    }
42
43
    /**
44
     * Gets the Y-component from this vector.
45
     *
46
     * @return float
47
     */
48 3
    public function getY()
49
    {
50 3
        return $this->getElement(1);
51
    }
52
53
    /**
54
     * Sets the Y-component in this vector.
55
     *
56
     * @param float $y The Y-component to set
57
     */
58 10
    public function setY($y)
59
    {
60 10
        $this->setElement(1, $y);
61 10
    }
62
63
    /**
64
     * Validates the index.
65
     *
66
     * @param int $index The index to validate.
67
     * @param bool $indexShouldExists Whether or not the index should exists.
68
     * @throws InvalidArgumentException Thrown when the index is invalid.
69
     */
70 5
    protected function validateIndex($index, $indexShouldExists)
71
    {
72 5
        if ($index < 0 || $index >= 2) {
73 2
            throw new InvalidArgumentException(sprintf('The index %d is invalid.', $index));
74
        }
75 5
    }
76
}
77