BestFirstStrategyFactory::begin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\PuzzleSolver\SearchStrategy;
4
5
use Stratadox\PuzzleSolver\Heuristic;
6
use Stratadox\PuzzleSolver\Puzzle;
7
8
/**
9
 * Factory for @see BestFirstStrategy
10
 *
11
 * @author Stratadox
12
 */
13
final class BestFirstStrategyFactory implements SearchStrategyFactory
14
{
15
    /** @var Heuristic */
16
    private $heuristic;
17
18
    private function __construct(Heuristic $heuristic)
19
    {
20
        $this->heuristic = $heuristic;
21
    }
22
23
    public static function noHeuristic(): SearchStrategyFactory
24
    {
25
        return new self(new NullHeuristic());
26
    }
27
28
    public static function withHeuristic(Heuristic $heuristic): SearchStrategyFactory
29
    {
30
        return new self($heuristic);
31
    }
32
33
    public function begin(Puzzle $puzzle): SearchStrategy
34
    {
35
        return BestFirstStrategy::withHeuristic($this->heuristic, $puzzle);
36
    }
37
}
38