Completed
Push — develop ( 7062ee...12ee62 )
by Arkadiusz
02:50
created

Layer::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 2
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace Phpml\NeuralNetwork;
6
7
use Phpml\Exception\InvalidArgumentException;
8
use Phpml\NeuralNetwork\Node\Neuron;
9
10
class Layer
11
{
12
    /**
13
     * @var Node[]
14
     */
15
    private $nodes = [];
16
17
    /**
18
     * @param int    $nodesNumber
19
     * @param string $nodeClass
20
     *
21
     * @throws InvalidArgumentException
22
     */
23
    public function __construct(int $nodesNumber = 0, string $nodeClass = Neuron::class)
24
    {
25
        if (!in_array(Node::class, class_implements($nodeClass))) {
26
            throw InvalidArgumentException::invalidLayerNodeClass();
27
        }
28
29
        for ($i = 0; $i < $nodesNumber; ++$i) {
30
            $this->nodes[] = new $nodeClass();
31
        }
32
    }
33
34
    /**
35
     * @param Node $node
36
     */
37
    public function addNode(Node $node)
38
    {
39
        $this->nodes[] = $node;
40
    }
41
42
    /**
43
     * @return Node[]
44
     */
45
    public function getNodes()
46
    {
47
        return $this->nodes;
48
    }
49
}
50