Estimate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A environment() 0 3 1
A __construct() 0 6 1
A costAs() 0 5 1
A estimate() 0 5 1
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