SecurityTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 44.59 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testFirewall() 0 8 1
A testPonthubStats() 17 17 1
A testRoleJardinier() 0 10 1
A testRoleAdmissible() 16 16 1
A testRoleExterieur() 0 15 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
namespace Tests\KI\PonthubBundle;
3
4
use Tests\KI\CoreBundle\WebTestCase;
5
6
class SecurityTest extends WebTestCase
7
{
8
    // Vérifie que les routes non firewallées sont utilisables
9
    public function testFirewall()
10
    {
11
        $this->client = static::createClient();
12
        $routes = [
13
            [401, 'GET', '/series/how-i-met-your-mother/episodes/pilot/download'],
14
        ];
15
        $this->checkRoutes($routes);
16
    }
17
18 View Code Duplication
    public function testPonthubStats()
19
    {
20
        // On se présente comme un trouffion de base
21
        $this->connect('muzardt', 'password');
22
        // On teste que n'importe qui ne puisse pas récupérer les statistiques perso
23
        $this->client->request('GET', '/ponthub/statistics/muzardt');
24
        $response = $this->client->getResponse();
25
        $this->assertJsonResponse($response, 200);
26
        $infos = json_decode($response->getContent(), true);
27
        $this->assertTrue(empty($infos['error']));
28
29
        $this->client->request('GET', '/ponthub/statistics/dziris');
30
        $response = $this->client->getResponse();
31
        $this->assertJsonResponse($response, 200);
32
        $infos = json_decode($response->getContent(), true);
33
        $this->assertFalse(empty($infos['error']));
34
    }
35
36
    public function testRoleJardinier()
37
    {
38
        // On se présente comme un jardinier
39
        $this->connect('vessairc', 'password');
40
        $routes = [
41
            [204, 'PATCH', '/series/how-i-met-your-mother', ['duration' => 10]],
42
            [204, 'PATCH', '/movies/pumping-iron', ['duration' => 10]]
43
        ];
44
        $this->checkRoutes($routes);
45
    }
46
47 View Code Duplication
    public function testRoleAdmissible()
48
    {
49
        // On se présente comme un admissible
50
        $this->connect('admissibles', 'password');
51
        $routes = [
52
            [404, 'GET', '/clbs/sddsdqs'],
53
            [200, 'GET', '/series/how-i-met-your-mother/episodes/pilot'],
54
            [200, 'GET', '/series/how-i-met-your-mother/episodes/pilot/comments'],
55
            [200, 'GET', '/movies/pumping-iron'],
56
            [200, 'GET', '/games'],
57
            [403, 'POST', '/movies/pumping-iron/like'],
58
            [403, 'DELETE', '/movies/pumping-iron/like'],
59
            [403, 'POST', '/movies/pumping-iron/comments']
60
        ];
61
        $this->checkRoutes($routes);
62
    }
63
64
    public function testRoleExterieur()
65
    {
66
        // On se présente comme un extérieur de l'administration
67
        $this->connect('gcc', 'password');
68
        $routes = [
69
            [403, 'GET', '/series/how-i-met-your-mother/episodes/pilot'],
70
            [403, 'GET', '/movies/pumping-iron'],
71
            [403, 'GET', '/games'],
72
            [403, 'POST', '/movies/pumping-iron/like'],
73
            [403, 'DELETE', '/movies/pumping-iron/like'],
74
            [403, 'POST', '/movies/pumping-iron/comments'],
75
            [403, 'GET', '/series/how-i-met-your-mother/episodes/pilot/comments'],
76
        ];
77
        $this->checkRoutes($routes);
78
    }
79
}
80