Moves   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 3 1
A none() 0 3 1
A __construct() 0 3 1
A cost() 0 11 3
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\PuzzleSolver;
4
5
use Stratadox\ImmutableCollection\Appending;
6
use Stratadox\ImmutableCollection\Filtering;
7
use Stratadox\ImmutableCollection\ImmutableCollection;
8
9
/**
10
 * Collection of @see Move objects
11
 *
12
 * @author Stratadox
13
 */
14
final class Moves extends ImmutableCollection
15
{
16
    use Appending, Filtering;
17
18
    public function __construct(Move ...$moves)
19
    {
20
        parent::__construct(...$moves);
21
    }
22
23
    public function current(): Move
24
    {
25
        return parent::current();
26
    }
27
28
    public static function none(): self
29
    {
30
        return new self();
31
    }
32
33
    public function cost(): float
34
    {
35
        $cost = 0;
36
        foreach ($this as $move) {
37
            if ($move instanceof WeightedMove) {
38
                $cost += $move->cost();
39
            } else {
40
                ++$cost;
41
            }
42
        }
43
        return $cost;
44
    }
45
}
46