Puzzle   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 13
dl 0
loc 43
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setGrid() 0 3 1
A initializePresetLocations() 0 7 4
A getPresetLocations() 0 3 1
A getGrid() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CoenMooij\Sudoku\Puzzle;
6
7
class Puzzle
8
{
9
    /**
10
     * @var Grid
11
     */
12
    private $grid;
13
14
    /**
15
     * @var Location[]
16
     */
17
    private $presetLocations;
18
19
    public function __construct(Grid $grid)
20
    {
21
        $this->grid = $grid;
22
        $this->initializePresetLocations();
23
    }
24
25
    public function getGrid(): Grid
26
    {
27
        return $this->grid;
28
    }
29
30
    public function setGrid(Grid $grid): void
31
    {
32
        $this->grid = $grid;
33
    }
34
35
    /**
36
     * @return Location[]
37
     */
38
    public function getPresetLocations(): array
39
    {
40
        return $this->presetLocations;
41
    }
42
43
    private function initializePresetLocations(): void
44
    {
45
        for ($row = 0; $row < Grid::NUMBER_OF_ROWS; $row++) {
46
            for ($column = 0; $column < Grid::NUMBER_OF_COLUMNS; $column++) {
47
                $location = new Location($row, $column);
48
                if (!$this->grid->isEmpty($location)) {
49
                    $this->presetLocations[] = $location;
50
                }
51
            }
52
        }
53
    }
54
}
55