SudokuPuzzle::afterMaking()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\PuzzleSolver\Puzzle\Sudoku;
4
5
use Stratadox\PuzzleSolver\Move;
6
use Stratadox\PuzzleSolver\Puzzle;
7
use Stratadox\PuzzleSolver\Moves;
8
9
final class SudokuPuzzle implements Puzzle
10
{
11
    /** @var Sudoku */
12
    private $sudoku;
13
    /** @var Moves */
14
    private $entries;
15
16
    private function __construct(Sudoku $sudoku, Moves $entries)
17
    {
18
        $this->sudoku = $sudoku;
19
        $this->entries = $entries;
20
    }
21
22
    public static function fromArrays(array ...$arrays): Puzzle
23
    {
24
        return new self(new Sudoku(...$arrays), Moves::none());
25
    }
26
27
    public function isSolved(): bool
28
    {
29
        return $this->sudoku->isFull();
30
    }
31
32
    public function movesSoFar(): Moves
33
    {
34
        return $this->entries;
35
    }
36
37
    public function representation(): string
38
    {
39
        return (string) $this->sudoku;
40
    }
41
42
    public function possibleMoves(): Moves
43
    {
44
        return $this->sudoku->possibilitiesForNextEmptyPosition();
45
    }
46
47
    public function afterMaking(Move ...$entries): Puzzle
48
    {
49
        $new = clone $this;
50
        $new->sudoku = $new->sudoku->withFilledIn(...$entries);
51
        $new->entries = $new->entries->add(...$entries);
52
        return $new;
53
    }
54
}
55