Estimate::estimate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Pathfinder\Estimate;
4
5
use Stratadox\Pathfinder\Environment;
6
use Stratadox\Pathfinder\Heuristic;
7
use Stratadox\Pathfinder\Metric;
8
9
final class Estimate implements Heuristic
10
{
11
    private $environment;
12
    private $metric;
13
14
    private function __construct(
15
        Metric $metric,
16
        Environment $environment
17
    ) {
18
        $this->metric = $metric;
19
        $this->environment = $environment;
20
    }
21
22
    public static function costAs(
23
        Metric $metric,
24
        Environment $environment
25
    ): Heuristic {
26
        return new static($metric, $environment);
27
    }
28
29
    public function estimate(string $start, string $goal): float
30
    {
31
        return $this->metric->distanceBetween(
32
            $this->environment->positionOf($start),
33
            $this->environment->positionOf($goal)
34
        );
35
    }
36
37
    public function environment(): Environment
38
    {
39
        return $this->environment;
40
    }
41
}
42