Analytics::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace lucidtaz\minimax\engine;
6
7
/**
8
 * Analytics holder
9
 *
10
 * This gives some insight in the evaluations done by the program.
11
 *
12
 * It is a result of tree traversal. Therefore this class knows how to aggregate
13
 * sub-results.
14
 */
15
class Analytics
16
{
17
    /**
18
     * @var int
19
     */
20
    public $nodesEvaluated;
21
22
    /**
23
     * @var int
24
     */
25
    public $leafNodesEvaluated;
26
27
    /**
28
     * @var int
29
     */
30
    public $internalNodesEvaluated;
31
32 14 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...
33
    {
34 14
        $result = new Analytics();
35 14
        $result->nodesEvaluated = 1;
36 14
        $result->leafNodesEvaluated = 1;
37 14
        $result->internalNodesEvaluated = 0;
38 14
        return $result;
39
    }
40
41 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...
42
    {
43 13
        $result = new Analytics();
44 13
        $result->nodesEvaluated = 1;
45 13
        $result->leafNodesEvaluated = 0;
46 13
        $result->internalNodesEvaluated = 1;
47 13
        return $result;
48
    }
49
50 13
    public function add(Analytics $that): void
51
    {
52 13
        $this->nodesEvaluated += $that->nodesEvaluated;
53 13
        $this->leafNodesEvaluated += $that->leafNodesEvaluated;
54 13
        $this->internalNodesEvaluated += $that->internalNodesEvaluated;
55 13
    }
56
}
57