GridFactory   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 19
dl 0
loc 48
c 0
b 0
f 0
ccs 23
cts 23
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setSeed() 0 3 1
A getCells() 0 13 3
A create() 0 9 1
A getNeighbors() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Barryvanveen\CCA\Factories;
6
7
use Barryvanveen\CCA\Cell;
8
use Barryvanveen\CCA\Config;
9
use Barryvanveen\CCA\Coordinate;
10
use Barryvanveen\CCA\Grid;
11
use Barryvanveen\CCA\Neighborhood;
12
13
class GridFactory
14
{
15 3
    public static function create(Config $config)
16
    {
17 3
        self::setSeed($config);
18
19 3
        $cells = self::getCells($config);
20
21 3
        $neighbors = self::getNeighbors($config);
22
23 3
        return new Grid($config, $cells, $neighbors);
24
    }
25
26 3
    protected static function setSeed(Config $config)
27
    {
28 3
        mt_srand($config->seed());
29 3
    }
30
31 3
    protected static function getCells(Config $config)
32
    {
33 3
        $cells = [];
34
35 3
        for ($row = 0; $row < $config->rows(); $row++) {
36 3
            for ($column = 0; $column < $config->columns(); $column++) {
37 3
                $coordinate = new Coordinate($row, $column, $config->columns());
38
39 3
                $cells[$coordinate->position()] = new Cell($config);
40
            }
41
        }
42
43 3
        return $cells;
44
    }
45
46 3
    protected static function getNeighbors(Config $config)
47
    {
48 3
        $neighbors = [];
49
50 3
        for ($row = 0; $row < $config->rows(); $row++) {
51 3
            for ($column = 0; $column < $config->columns(); $column++) {
52 3
                $coordinate = new Coordinate($row, $column, $config->columns());
53
54 3
                $neighborhood = new Neighborhood($config, $coordinate);
55
56 3
                $neighbors[$coordinate->position()] = $neighborhood->getNeighbors();
57
            }
58
        }
59
60 3
        return $neighbors;
61
    }
62
}
63