CollectorCollectionTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 30.77 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 24
loc 78
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testIncrement() 0 11 1
A testDecrement() 0 11 1
A testTiming() 12 12 1
A testMeasure() 12 12 1
A testFlush() 0 8 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
use Beberlei\Metrics\Collector\Collector;
4
use Flagbit\Bundle\MetricsBundle\Collector\CollectorCollection;
5
use PHPUnit\Framework\TestCase;
6
7
class CollectorCollectionTest extends TestCase
8
{
9
    /**
10
     * @var CollectorCollection
11
     */
12
    private $collectorCollection;
13
14
    /**
15
     * @var \PHPUnit_Framework_MockObject_MockObject
16
     */
17
    private $collector;
18
19
    protected function setUp()
20
    {
21
        $this->collector = $this->createMock(Collector::class);
22
        $this->collectorCollection = new CollectorCollection();
23
        $this->collectorCollection->addCollector($this->collector);
0 ignored issues
show
Documentation introduced by
$this->collector is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Beberlei\Metrics\Collector\Collector>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
    }
25
26
    public function testIncrement()
27
    {
28
        $metricName = 'foo';
29
30
        $this->collector
31
            ->expects($this->once())
32
            ->method('increment')
33
            ->with($metricName);
34
35
        $this->collectorCollection->increment($metricName);
36
    }
37
38
    public function testDecrement()
39
    {
40
        $metricName = 'foo';
41
42
        $this->collector
43
            ->expects($this->once())
44
            ->method('decrement')
45
            ->with($metricName);
46
47
        $this->collectorCollection->decrement($metricName);
48
    }
49
50 View Code Duplication
    public function testTiming()
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...
51
    {
52
        $metricName = 'foo';
53
        $metricValue = 'bar';
54
55
        $this->collector
56
            ->expects($this->once())
57
            ->method('timing')
58
            ->with($metricName, $metricValue);
59
60
        $this->collectorCollection->timing($metricName, $metricValue);
61
    }
62
63 View Code Duplication
    public function testMeasure()
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...
64
    {
65
        $metricName = 'foo';
66
        $metricValue = 'bar';
67
68
        $this->collector
69
            ->expects($this->once())
70
            ->method('measure')
71
            ->with($metricName, $metricValue);
72
73
        $this->collectorCollection->measure($metricName, $metricValue);
74
    }
75
76
    public function testFlush()
77
    {
78
        $this->collector
79
            ->expects($this->once())
80
            ->method('flush');
81
82
        $this->collectorCollection->flush();
83
    }
84
}
85