IncidentHookControllerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 17.54 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 2
dl 10
loc 57
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B testGetActionOK() 0 24 1
A assertIncidentJsonResValid() 10 10 1
A assertStatusOk() 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
namespace IncidentBundle\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
/**
8
 * Class IncidentHookControllerTest
9
 */
10
class IncidentHookControllerTest extends WebTestCase
11
{
12
    /**
13
     * test webhook get action ok
14
     */
15
    public function testGetActionOK()
16
    {
17
        $client = static::createClient();
18
19
        $incidentIdent = 'proc.7.email.check.'.random_bytes(10);
20
21
        $crawler = $client->request(
22
            'GET',
23
            '/webhook/incident/dnnlpwo2cj287189282bbcnjskshewk/'.$incidentIdent
24
        );
25
26
        $responseObj = $this->assertIncidentJsonResValid($client, $crawler);
27
28
        $this->assertStatusOk($responseObj);
29
30
        $crawler = $client->request(
31
            'GET',
32
            '/webhook/incident/dnnlpwo2cj287189282bbcnjskshewk/'.$incidentIdent
33
        );
34
35
        $responseObj = $this->assertIncidentJsonResValid($client, $crawler);
36
37
        $this->assertStatusOk($responseObj);
38
    }
39
40
    /**
41
     * @param $client
42
     * @param $crawler
43
     *
44
     * @return mixed
45
     */
46 View Code Duplication
    protected function assertIncidentJsonResValid($client, $crawler)
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...
47
    {
48
        $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'HTTP STATUS CODE FAIL:');
49
50
        $this->assertJson($crawler->text());
51
52
        $responseObj = json_decode($crawler->text());
53
54
        return $responseObj;
55
    }
56
57
    /**
58
     * @param $responseObj
59
     */
60
    protected function assertStatusOk($responseObj)
61
    {
62
        $this->assertObjectHasAttribute('status', $responseObj);
63
64
        $this->assertEquals('ok', $responseObj->status);
65
    }
66
}
67