AbstractRunner   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 76
Duplicated Lines 18.42 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 15
lcom 2
cbo 2
dl 14
loc 76
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A runTest() 0 11 2
A pushRule() 0 8 3
A getReport() 0 4 1
B combineReport() 14 22 8
acceptRule() 0 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
 * ShouldPHP
4
 *
5
 * @author  Gabriel Jacinto <[email protected]>
6
 * @status  dev
7
 * @link    https://github.com/GabrielJMJ/ShouldPHP
8
 * @license MIT
9
 */
10
 
11
namespace Gabrieljmj\Should\Runner;
12
13
use Gabrieljmj\Should\Runner\RunnerInterface;
14
use Gabrieljmj\Should\Runner\Rule\RuleInterface;
15
use Gabrieljmj\Should\Ambient\AmbientInterface;
16
use Gabrieljmj\Should\Report\Report;
17
18
abstract class AbstractRunner implements RunnerInterface
19
{
20
    /**
21
     * @var \Gabrieljmj\Should\Report\Report
22
     */
23
    protected $report;
24
25
    /**
26
     * @var array
27
     */
28
    protected $rules = [];
29
30
    public function __construct()
31
    {
32
        $this->report = new Report('test');
33
    }
34
35
    /**
36
     * @param \Gabrieljmj\Should\AmbientInterface $ambient
37
     */
38
    protected function runTest(AmbientInterface $ambient)
39
    {
40
        $ambient->run();
41
        $cReport = $ambient->getReport();
42
43
        if ($this->report === null) {
44
            $this->report = new Report('test');
45
        }
46
47
        $this->combineReport($cReport);
48
    }
49
50
    public function pushRule(RuleInterface $rule)
51
    {
52
        if ($this->acceptRule($rule)) {
53
            if (!in_array($rule, $this->rules)) {
54
                $this->rules[] = $rule;
55
            }
56
        }
57
    }
58
59
    /**
60
     * Returns the test report
61
     *
62
     * @return \Gabrieljmj\Should\Report\Report
63
     */
64
    public function getReport()
65
    {
66
        return $this->report;
67
    }
68
69
    protected function combineReport(Report $report)
70
    {
71
        $assertList = $report->getAssertList();
72
73
        foreach ($assertList as $testType => $value) {
74 View Code Duplication
            if (isset($assertList[$testType]['fail'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
75
                foreach ($assertList[$testType]['fail'] as $element => $fails) {
76
                    foreach ($fails as $fail) {
77
                        $this->report->addAssert($fail);
78
                    }
79
                }
80
            }
81
82 View Code Duplication
            if (isset($assertList[$testType]['success'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
83
                foreach ($assertList[$testType]['success'] as $element => $successes) {
84
                    foreach ($successes as $success) {
85
                        $this->report->addAssert($success);
86
                    }
87
                }
88
            }
89
        }
90
    }
91
92
    abstract protected function acceptRule(RuleInterface $rule);
93
}