Passed
Push — main ( 4a4379...b8ec9e )
by Jesse
10:31
created

SlidingPuzzle   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 54
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A withPieces() 0 3 1
A goalState() 0 3 1
A __construct() 0 4 1
A isSolved() 0 3 1
A currentState() 0 3 1
A representation() 0 3 1
A possibleMoves() 0 3 1
A afterMaking() 0 5 1
A movesSoFar() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\PuzzleSolver\Puzzle\SlidingPuzzle;
4
5
use Stratadox\PuzzleSolver\Move;
6
use Stratadox\PuzzleSolver\Puzzle;
7
use Stratadox\PuzzleSolver\Moves;
8
9
final class SlidingPuzzle implements Puzzle
10
{
11
    /** @var Board */
12
    private $board;
13
    /** @var Moves */
14
    private $moves;
15
16
    private function __construct(Board $board, Moves $moves)
17
    {
18
        $this->board = $board;
19
        $this->moves = $moves;
20
    }
21
22
    public static function withPieces(array ...$pieces): Puzzle
23
    {
24
        return new self(new Board(...$pieces), Moves::none());
25
    }
26
27
    public function goalState(): string
28
    {
29
        return $this->board->goalState();
30
    }
31
32
    public function currentState(): string
33
    {
34
        return $this->board->currentState();
35
    }
36
37
    public function representation(): string
38
    {
39
        return (string) $this->board;
40
    }
41
42
    public function afterMaking(Move ...$moves): Puzzle
43
    {
44
        return new self(
45
            $this->board->afterSliding(...$moves),
46
            $this->moves->add(...$moves)
47
        );
48
    }
49
50
    public function isSolved(): bool
51
    {
52
        return $this->board->isSolved();
53
    }
54
55
    public function movesSoFar(): Moves
56
    {
57
        return $this->moves;
58
    }
59
60
    public function possibleMoves(): Moves
61
    {
62
        return new Moves(...$this->board->possibleSlides());
63
    }
64
}
65