Passed
Push — master ( 25c2e9...26c6a8 )
by Petr
08:32
created

OrganizerController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 109
Duplicated Lines 12.84 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 14
loc 109
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A listAction() 0 4 1
A viewAction() 0 4 1
A createAction() 14 14 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 AppBundle\Controller;
4
5
use AppBundle\Controller\Infrastructure\RestController;
6
use AppBundle\Entity\Organizer;
7
use AppBundle\Form\Ambassador\OrganizerFormType;
8
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
/**
16
 * @author Vehsamrak
17
 * @Route("organizer")
18
 */
19
class OrganizerController extends RestController
20
{
21
22
    /**
23
     * List all registered organizers
24
     * @Route("s/{limit}/{offset}", name="organizers_list")
25
     * @Method("GET")
26
     * @ApiDoc(
27
     *     section="Organizer",
28
     *     requirements={
29
     *         {
30
     *             "name"="limit",
31
     *             "dataType"="int",
32
     *             "requirement"="false",
33
     *             "description"="limit number. Default is 50"
34
     *         },
35
     *         {
36
     *             "name"="offset",
37
     *             "dataType"="int",
38
     *             "requirement"="false",
39
     *             "description"="offset number. Default is 0"
40
     *         },
41
     *     },
42
     *     statusCodes={
43
     *         200="OK",
44
     *     }
45
     * )
46
     * @param int $limit Limit results. Default is 50
47
     * @param int $offset Starting serial number of result collection. Default is 0
48
     */
49 1
    public function listAction($limit = null, $offset = null): Response
50
    {
51 1
        return $this->listEntities($this->get('rockparade.organizer_repository'), $limit, $offset);
52
    }
53
54
    /**
55
     * View organizer by name
56
     * @Route("/{id}", name="organizer_view")
57
     * @Method("GET")
58
     * @ApiDoc(
59
     *     section="Organizer",
60
     *     requirements={
61
     *         {
62
     *             "name"="id",
63
     *             "dataType"="string",
64
     *             "requirement"="true",
65
     *             "description"="organizer name"
66
     *         },
67
     *     },
68
     *     statusCodes={
69
     *         200="Organizer was found",
70
     *         404="Organizer with given name was not found",
71
     *     }
72
     * )
73
     * @param string $id organizer name
74
     */
75 3
    public function viewAction(string $id): Response
76
    {
77 3
        return $this->viewEntity($this->get('rockparade.organizer_repository'), $id);
78
    }
79
80
    /**
81
     * Create new band
82
     * @Route("", name="organizer_create")
83
     * @Method("POST")
84
     * @Security("has_role('ROLE_USER')")
85
     * @ApiDoc(
86
     *     section="Organizer",
87
     *     requirements={
88
     *         {
89
     *             "name"="name",
90
     *             "dataType"="string",
91
     *             "requirement"="true",
92
     *             "description"="organization name"
93
     *         },
94
     *         {
95
     *             "name"="description",
96
     *             "dataType"="string",
97
     *             "requirement"="true",
98
     *             "description"="organization description"
99
     *         },
100
     *         {
101
     *             "name"="members",
102
     *             "dataType"="array",
103
     *             "requirement"="false",
104
     *             "description"="logins and short descriptions of organization members"
105
     *         },
106
     *     },
107
     *     statusCodes={
108
     *         201="New organizer was created. Link to new resource provided in header 'Location'",
109
     *         400="Validation error",
110
     *     }
111
     * )
112
     */
113 2 View Code Duplication
    public function createAction(Request $request): Response
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...
114
    {
115 2
        $form = $this->createAndProcessForm($request, OrganizerFormType::class);
116
117 2
        $apiResponseFactory = $this->get('rockparade.api_response_factory');
118 2
        $response = $apiResponseFactory->createResponse(
119 2
            $this->createApiOperation($request),
120
            $form,
121 2
            $this->getUser(),
122 2
            Organizer::class
123
        );
124
125 2
        return $this->respond($response);
126
    }
127
}
128