Indexed   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A estimate() 0 3 1
A heuristic() 0 5 1
A environment() 0 3 1
A __construct() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Pathfinder\Estimate;
4
5
use const INF;
6
use Stratadox\Pathfinder\Environment;
7
use Stratadox\Pathfinder\Heuristic;
8
9
final class Indexed implements Heuristic
10
{
11
    private $cache;
12
    private $environment;
13
14
    private function __construct(array $cache, Environment $environment)
15
    {
16
        $this->cache = $cache;
17
        $this->environment = $environment;
18
    }
19
20
    public static function heuristic(
21
        array $cache,
22
        Environment $environment
23
    ): Heuristic {
24
        return new self($cache, $environment);
25
    }
26
27
    public function estimate(string $start, string $goal): float
28
    {
29
        return $this->cache[$start][$goal] ?? INF;
30
    }
31
32
    public function environment(): Environment
33
    {
34
        return $this->environment;
35
    }
36
}
37