CCA   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 43
c 0
b 0
f 0
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getState() 0 3 1
A cycle() 0 13 2
A __construct() 0 5 1
A printCells() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Barryvanveen\CCA;
6
7
class CCA
8
{
9
    /** @var Config */
10
    protected $config;
11
12
    /** @var Grid */
13
    protected $grid;
14
15
    /** @var int */
16
    protected $generation = 0;
17
18 6
    public function __construct(Config $config, Grid $grid)
19
    {
20 6
        $this->config = $config;
21
22 6
        $this->grid = $grid;
23 6
    }
24
25 9
    public function cycle(int $cycles = 1): int
26
    {
27 9
        while ($cycles > 0) {
28 6
            $this->grid->computeNextState();
29
30 6
            $this->grid->setNextState();
31
32 6
            $this->generation++;
33
34 6
            $cycles--;
35
        }
36
37 9
        return $this->generation;
38
    }
39
40 3
    public function getState(): State
41
    {
42 3
        return new State($this->grid);
43
    }
44
45 3
    public function printCells()
46
    {
47 3
        printf("Cells at generation %d:\n", $this->generation);
48
49 3
        printf("%s", $this->grid);
50 3
    }
51
}
52