VectorValue::__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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace MachineLearning\Domain\Model\Value;
3
use MachineLearning\Domain\Model\ValueInterface;
4
5
class VectorValue implements ValueInterface
6
{
7
    /**
8
     * @var float[]
9
     */
10
    protected $value;
11
12
    /**
13
     * @param float[]|array<integer,array> $value
14
     */
15 4
    public function __construct($value)
16
    {
17 4
        $this->value = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value of type array<integer,double|array> is incompatible with the declared type array<integer,double> of property $value.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
18 4
    }
19
20
    /**
21
     * @return \float[]
22
     */
23 4
    public function getValue()
24
    {
25 4
        return $this->value;
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31 2
    public function scalar(ValueInterface $value)
32
    {
33 2
        $result = 0;
34 2
        $columns = count($this->value);
35 2
        for ($i=0; $i<$columns; $i++) {
36 2
            $result += $this->value[$i]*$value->getValue()[$i];
37 2
        }
38 2
        return $result;
39
    }
40
41
}
42