BestFirstStrategyFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A begin() 0 3 1
A noHeuristic() 0 3 1
A withHeuristic() 0 3 1
A __construct() 0 3 1
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