Entry::allPossibilitiesFor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
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 2
dl 0
loc 7
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\Moves;
7
use function array_map;
8
use function sprintf;
9
10
final class Entry implements Move
11
{
12
    /** @var int */
13
    private $number;
14
    /** @var int */
15
    private $row;
16
    /** @var int */
17
    private $column;
18
19
    public function __construct(int $number, int $row, int $column)
20
    {
21
        $this->number = $number;
22
        $this->row = $row;
23
        $this->column = $column;
24
    }
25
26
    public static function allPossibilitiesFor(int $row, int $column): Moves
27
    {
28
        return new Moves(...array_map(
29
            static function (int $number) use ($row, $column): Entry {
30
                return new self($number, $row, $column);
31
            },
32
            range(1, 9)
33
        ));
34
    }
35
36
    public function number(): int
37
    {
38
        return $this->number;
39
    }
40
41
    public function column(): int
42
    {
43
        return $this->column;
44
    }
45
46
    public function row(): int
47
    {
48
        return $this->row;
49
    }
50
51
    public function __toString(): string
52
    {
53
        return sprintf(
54
            '%d at (%d, %d)',
55
            $this->number,
56
            $this->column,
57
            $this->row
58
        );
59
    }
60
}
61