Completed
Push — develop ( e322b0...461e3c )
by Barry
02:41
created

CCA   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

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