Passed
Push — master ( 14728e...fb3e58 )
by Thijs
40s
created

Analytics::forInternalNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 8
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
namespace lucidtaz\minimax\engine;
4
5
/**
6
 * Analytics holder
7
 *
8
 * This gives some insight in the evaluations done by the program.
9
 *
10
 * It is a result of tree traversal. Therefore this class knows how to aggregate
11
 * sub-results.
12
 */
13
class Analytics
14
{
15
    /**
16
     * @var int
17
     */
18
    public $nodesEvaluated;
19
20
    /**
21
     * @var int
22
     */
23
    public $leafNodesEvaluated;
24
25
    /**
26
     * @var int
27
     */
28
    public $internalNodesEvaluated;
29
30 13 View Code Duplication
    public static function forLeafNode(): Analytics
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32 13
        $result = new Analytics();
33 13
        $result->nodesEvaluated = 1;
34 13
        $result->leafNodesEvaluated = 1;
35 13
        $result->internalNodesEvaluated = 0;
36 13
        return $result;
37
    }
38
39 13 View Code Duplication
    public static function forInternalNode(): Analytics
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41 13
        $result = new Analytics();
42 13
        $result->nodesEvaluated = 1;
43 13
        $result->leafNodesEvaluated = 0;
44 13
        $result->internalNodesEvaluated = 1;
45 13
        return $result;
46
    }
47
48 13
    public function add(Analytics $that)
49
    {
50 13
        $this->nodesEvaluated += $that->nodesEvaluated;
51 13
        $this->leafNodesEvaluated += $that->leafNodesEvaluated;
52 13
        $this->internalNodesEvaluated += $that->internalNodesEvaluated;
53 13
    }
54
}
55