Completed
Push — master ( c66919...af43e1 )
by Andreas
02:08
created

MergeResult::countChanged()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 3
nop 0
1
<?php
2
3
/**
4
 * Copyright (c) Andreas Heigl<[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 *
24
 * @author    Andreas Heigl<[email protected]>
25
 * @copyright Andreas Heigl
26
 * @license   http://www.opensource.org/licenses/mit-license.php MIT-License
27
 * @since     16.06.2016
28
 * @link      http://github.com/heiglandreas/org.heigl.junitdiff
29
 */
30
31
namespace Org_Heigl\JUnitDiff;
32
33
use Org_Heigl\IteratorTrait\IteratorTrait;
34
use Symfony\Component\Console\Style\StyleInterface;
35
36
class MergeResult implements \Iterator
37
{
38
    use IteratorTrait;
39
40
    protected $content = [];
41
42
    protected $style;
43
44
    public function __construct(StyleInterface $style)
45
    {
46
        $this->style = $style;
47
    }
48
    public function addBase($test, $result)
49
    {
50
        $this->content[$test]['base'] = $result;
51
    }
52
53
    public function addCurrent($test, $result)
54
    {
55
        $this->content[$test]['current'] = $result;
56
    }
57
58
    public function sort()
59
    {
60
        ksort($this->content);
61
    }
62
63
    /**
64
     * Get the array the iterator shall iterate over.
65
     *
66
     * @return array
67
     */
68
    protected function & getIterableElement()
69
    {
70
        return $this->content;
71
    }
72
73
    protected function &getIteratorArray()
74
    {
75
        return $this->content;
76
    }
77
78
    public function countTotal()
79
    {
80
        return count($this->content);
81
    }
82
83 View Code Duplication
    public function countBase()
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...
84
    {
85
        $counter = 0;
86
        foreach ($this->content as $value) {
87
            if (isset($value['base'])) {
88
                $counter++;
89
            }
90
        }
91
92
        return $counter;
93
    }
94
95 View Code Duplication
    public function countCurrent()
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...
96
    {
97
        $counter = 0;
98
        foreach ($this->content as $value) {
99
            if (isset($value['current'])) {
100
                $counter++;
101
            }
102
        }
103
104
        return $counter;
105
    }
106
107
    public function countNew()
108
    {
109
        $counter = 0;
110
        foreach ($this->content as $value) {
111
            if (isset($value['base'])) {
112
                continue;
113
            }
114
            $counter++;
115
        }
116
117
        return $counter;
118
    }
119
120
    public function countRemoved()
121
    {
122
        $counter = 0;
123
        foreach ($this->content as $value) {
124
            if (isset($value['current'])) {
125
                continue;
126
            }
127
            $counter++;
128
        }
129
130
        return $counter;
131
    }
132
133
    public function countChanged()
134
    {
135
        $counter = 0;
136
        foreach ($this->content as $value) {
137
            if (isset($value['base']) && isset($value['current']) && $value['base'] != $value['current']) {
138
                $counter++;
139
            }
140
        }
141
142
        return $counter;
143
    }
144
}
145