GamesController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 120
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 5 5 1
A getGamesAction() 4 4 1
A getGameAction() 6 6 1
A patchGameAction() 6 6 1
A deleteGameAction() 6 6 1
A downloadGameAction() 5 5 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 KI\PonthubBundle\Controller;
4
5
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 View Code Duplication
class GamesController extends PonthubFileController
11
{
12
    public function setContainer(ContainerInterface $container = null)
13
    {
14
        parent::setContainer($container);
15
        $this->initialize('Game', 'Ponthub');
16
    }
17
18
    /**
19
     * @ApiDoc(
20
     *  resource=true,
21
     *  description="Liste les jeux",
22
     *  output="KI\PonthubBundle\Entity\Game",
23
     *  statusCodes={
24
     *   200="Requête traitée avec succès",
25
     *   401="Une authentification est nécessaire pour effectuer cette action",
26
     *   403="Pas les droits suffisants pour effectuer cette action",
27
     *   503="Service temporairement indisponible ou en maintenance",
28
     *  },
29
     *  section="Ponthub"
30
     * )
31
     * @Route("/games")
32
     * @Method("GET")
33
     */
34
    public function getGamesAction()
35
    {
36
        return $this->getAll();
37
    }
38
39
    /**
40
     * @ApiDoc(
41
     *  description="Retourne un jeu",
42
     *  output="KI\PonthubBundle\Entity\Game",
43
     *  statusCodes={
44
     *   200="Requête traitée avec succès",
45
     *   401="Une authentification est nécessaire pour effectuer cette action",
46
     *   403="Pas les droits suffisants pour effectuer cette action",
47
     *   404="Ressource non trouvée",
48
     *   503="Service temporairement indisponible ou en maintenance",
49
     *  },
50
     *  section="Ponthub"
51
     * )
52
     * @Route("/games/{slug}")
53
     * @Method("GET")
54
     */
55
    public function getGameAction($slug)
56
    {
57
        $game = $this->getOne($slug);
58
59
        return $this->json($game);
60
    }
61
62
    /**
63
     * @ApiDoc(
64
     *  description="Modifie un jeu",
65
     *  input="KI\PonthubBundle\Form\GameType",
66
     *  statusCodes={
67
     *   204="Requête traitée avec succès mais pas d’information à renvoyer",
68
     *   400="La syntaxe de la requête est erronée",
69
     *   401="Une authentification est nécessaire pour effectuer cette action",
70
     *   403="Pas les droits suffisants pour effectuer cette action",
71
     *   404="Ressource non trouvée",
72
     *   503="Service temporairement indisponible ou en maintenance",
73
     *  },
74
     *  section="Ponthub"
75
     * )
76
     * @Route("/games/{slug}")
77
     * @Method("PATCH")
78
     */
79
    public function patchGameAction($slug)
80
    {
81
        $data = $this->patch($slug, $this->is('JARDINIER'));
82
83
        return $this->formJson($data);
84
    }
85
86
87
    /**
88
     * @ApiDoc(
89
     *  description="Supprime un jeux",
90
     *  statusCodes={
91
     *   204="Requête traitée avec succès mais pas d’information à renvoyer",
92
     *   401="Une authentification est nécessaire pour effectuer cette action",
93
     *   403="Pas les droits suffisants pour effectuer cette action",
94
     *   404="Ressource non trouvée",
95
     *   503="Service temporairement indisponible ou en maintenance",
96
     *  },
97
     *  section="Publications"
98
     * )
99
     * @Route("/games/{slug}")
100
     * @Method("DELETE")
101
     */
102
    public function deleteGameAction($slug)
103
    {
104
        $this->delete($slug, $this->is('JARDINIER'));
105
106
        return $this->json(null, 204);
107
    }
108
109
    /**
110
     * @ApiDoc(
111
     *  description="Télécharge un fichier sur Ponthub, et log le téléchargement",
112
     *  statusCodes={
113
     *   200="Requête traitée avec succès mais pas d’information à renvoyer",
114
     *   401="Une authentification est nécessaire pour effectuer cette action",
115
     *   403="Pas les droits suffisants pour effectuer cette action",
116
     *   404="Ressource non trouvée",
117
     *   503="Service temporairement indisponible ou en maintenance",
118
     *  },
119
     *  section="Ponthub"
120
     * )
121
     * @Route("/games/{slug}/download")
122
     * @Method("GET")
123
     */
124
    public function downloadGameAction($slug)
125
    {
126
        $item =  $this->getOne($slug, !$this->is('EXTERIEUR'));
127
        return $this->download($item);
128
    }
129
}
130