CCA::printCells()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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