Vector3   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A crossProduct() 0 13 1
A getZ() 0 4 1
A setZ() 0 4 1
A validateIndex() 0 6 3
1
<?php
2
3
namespace PHP\Math\Vector;
4
5
use InvalidArgumentException;
6
use PHP\Math\BigNumber\Utils as BigNumberUtils;
7
8
class Vector3 extends Vector2
9
{
10
    /**
11
     * Initializes a new instance of this class.
12
     *
13
     * @param float $x The X-component to set.
14
     * @param float $y The Y-component to set.
15
     * @param float $z The Z-component to set.
16
     */
17 5
    public function __construct($x, $y, $z)
18
    {
19 5
        parent::__construct($x, $y);
20
21 5
        $this->setZ($z);
22 5
    }
23
24
    /**
25
     * Calculates the cross product between this vector and the given vector.
26
     *
27
     * @param Vector3 $vector The vector to calculate with.
28
     * @return Vector3
29
     */
30 1
    public function crossProduct(Vector3 $vector)
31
    {
32 1
        $x = BigNumberUtils::multiply($this->getY(), $vector->getZ());
33 1
        $x->subtract(BigNumberUtils::multiply($this->getZ(), $vector->getY()));
34
35 1
        $y = BigNumberUtils::multiply($this->getZ(), $vector->getX());
36 1
        $y->subtract(BigNumberUtils::multiply($this->getX(), $vector->getZ()));
37
38 1
        $z = BigNumberUtils::multiply($this->getX(), $vector->getY());
39 1
        $z->subtract(BigNumberUtils::multiply($this->getY(), $vector->getX()));
40
41 1
        return new Vector3($x, $y, $z);
0 ignored issues
show
Documentation introduced by
$x is of type object<PHP\Math\BigNumber\BigNumber>, but the function expects a double.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$y is of type object<PHP\Math\BigNumber\BigNumber>, but the function expects a double.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$z is of type object<PHP\Math\BigNumber\BigNumber>, but the function expects a double.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
    }
43
44
    /**
45
     * Gets the X-component from this vector.
46
     *
47
     * @return float
48
     */
49 3
    public function getZ()
50
    {
51 3
        return $this->getElement(2);
52
    }
53
54
    /**
55
     * Sets the Z-component in this vector.
56
     *
57
     * @param float $z The Z-component to set
58
     */
59 5
    public function setZ($z)
60
    {
61 5
        $this->setElement(2, $z);
62 5
    }
63
64
    /**
65
     * Validates the index.
66
     *
67
     * @param int $index The index to validate.
68
     * @param bool $indexShouldExists Whether or not the index should exists.
69
     * @throws InvalidArgumentException Thrown when the index is invalid.
70
     */
71 5
    protected function validateIndex($index, $indexShouldExists)
72
    {
73 5
        if ($index < 0 || $index >= 3) {
74 2
            throw new InvalidArgumentException(sprintf('The index %d is invalid.', $index));
75
        }
76 5
    }
77
}
78