IncidentRecordTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 27.27 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 9
loc 33
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSuppress() 0 13 1
A createIncident() 9 9 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
namespace Spiral\Tests\Snapshotter\AggregationHandler\Database;
4
5
use Spiral\Snapshotter\AggregationHandler\Database\Sources\IncidentSource;
6
use Spiral\Snapshotter\AggregationHandler\Database\IncidentRecord;
7
use Spiral\Snapshotter\AggregationHandler;
8
use Spiral\Tests\BaseTest;
9
10
class IncidentRecordTest extends BaseTest
11
{
12
    /**
13
     * Test suppression.
14
     */
15
    public function testSuppress()
16
    {
17
        /** @var IncidentSource $source */
18
        $source = $this->container->get(IncidentSource::class);
19
        $incident = $this->createIncident($source);
20
21
        $this->assertTrue($incident->status->isLast());
22
        $this->assertNotEmpty($incident->getExceptionSource());
23
24
        $incident->suppress();
25
        $this->assertTrue($incident->status->isSuppressed());
26
        $this->assertEmpty($incident->getExceptionSource());
27
    }
28
29
    /**
30
     * @param IncidentSource $source
31
     * @return IncidentRecord
32
     */
33 View Code Duplication
    private function createIncident(IncidentSource $source): IncidentRecord
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...
34
    {
35
        $snapshot = $this->makeSnapshot('custom error', 123);
36
        $incident = $source->createFromSnapshot($snapshot);
37
38
        $incident->save();
39
40
        return $incident;
41
    }
42
}