Analytics   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 38.1 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 16
loc 42
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A forLeafNode() 8 8 1
A forInternalNode() 8 8 1
A add() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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