Completed
Pull Request — master (#7)
by Thijs
02:24
created

TraversalResult::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace lucidtaz\minimax\engine;
4
5
use lucidtaz\minimax\game\GameState;
6
7
/**
8
 * An value type to hold an evaluation result and possibly a move
9
 * For tree traversal, technically only the evaluation result is needed.
10
 * However, at the root of the tree we need to know which move was selected to
11
 * produce that result, because that's the final answer that the caller is
12
 * interested in.
13
 */
14
class TraversalResult
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
15
{
16
    /**
17
     * @var ?GameState Empty if the traversed node was a leaf node
18
     */
19
    public $move;
20
21
    /**
22
     * @var EvaluationResult
23
     */
24
    public $evaluation;
25
26 12
    private function __construct(EvaluationResult $evaluation, GameState $move = null)
27
    {
28 12
        $this->move = $move;
29 12
        $this->evaluation = $evaluation;
30 12
    }
31
32 12
    public static function create(GameState $move, EvaluationResult $evaluation): TraversalResult
33
    {
34 12
        return new static($evaluation, $move);
35
    }
36
37 12
    public static function onlyEvaluation(EvaluationResult $evaluation): TraversalResult
38
    {
39 12
        return new static($evaluation);
40
    }
41
}
42