Issues (27)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/ApiBundle/Controller/BeerController.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace ApiBundle\Controller;
4
5
use FOS\RestBundle\Controller\Annotations\QueryParam;
6
use FOS\RestBundle\Controller\Annotations\RouteResource;
7
use FOS\RestBundle\Controller\FOSRestController;
8
use FOS\RestBundle\Request\ParamFetcher;
9
use Maxpou\BeerBundle\Entity\Beer;
10
use Maxpou\BeerBundle\Form\Type\BeerApiType;
11
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
use Symfony\Component\HttpKernel\Exception\HttpException;
15
16
/**
17
 * Beer controller.
18
 *
19
 * @RouteResource("beer")
20
 */
21
class BeerController extends FOSRestController
22
{
23
    /**
24
     * Get all Beers entities.
25
     *
26
     * @ApiDoc(
27
     *  statusCodes={
28
     *      200="Returned when successful"
29
     * })
30
     * @QueryParam(name="offset", requirements="\d+", nullable=true,
31
     *     description="Offset from which to start listing breweries.")
32
     * @QueryParam(name="limit", requirements="\d+", nullable=true,
33
     *     description="How many breweries to return.")
34
     *
35
     * @param UUID $breweryId Brewery Id
36
     */
37
    public function cgetAction($breweryId, ParamFetcher $paramFetcher)
38
    {
39
        $offset = $paramFetcher->get('offset');
40
        $limit = $paramFetcher->get('limit');
41
42
        $em = $this->getDoctrine()->getManager();
43
        $beers = $em->getRepository('MaxpouBeerBundle:Beer')
44
                     ->findBy(
45
                         ['brewery' => $breweryId],
46
                         ['name' => 'ASC'],
47
                         $limit,
48
                         $offset
49
                     );
50
51
        return $beers;
52
    }
53
54
    /**
55
     * Get a Beer entity.
56
     *
57
     * @ApiDoc(
58
     *  statusCodes={
59
     *      200="Returned when successful",
60
     *      404="Returned when not found"
61
     * })
62
     *
63
     * @param UUID $breweryId Brewery Id
64
     * @param UUID $beerId    Beer Id
65
     */
66 View Code Duplication
    public function getAction($breweryId, $beerId)
0 ignored issues
show
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...
67
    {
68
        $brewery = $this->getDoctrine()->getManager()
69
                        ->getRepository('MaxpouBeerBundle:Brewery')
70
                        ->find($breweryId);
71
72
        if (!$brewery) {
73
            throw new HttpException(404, 'Unable to find this Brewery entity');
74
        }
75
76
        $beer = $this->getDoctrine()->getManager()
77
                        ->getRepository('MaxpouBeerBundle:Beer')
78
                        ->find($beerId);
79
80
        if (!$beer) {
81
            throw new HttpException(404, 'Unable to find this Beer entity');
82
        }
83
84
        return $beer;
85
    }
86
87
    /**
88
     * Add a Beer.
89
     *
90
     * @ApiDoc(
91
     *  statusCodes={
92
     *       201="Returned when successful",
93
     *       400="Returned when parameter is wrong"
94
     *  },
95
     *  input = {
96
     *      "class" = "Maxpou\BeerBundle\Form\Type\BeerApiType",
97
     *      "name"  = ""
98
     * })
99
     *
100
     * @param UUID $breweryId Brewery Id
101
     */
102
    public function postAction($breweryId, Request $request)
103
    {
104
        $brewery = $this->getDoctrine()->getManager()
105
                        ->getRepository('MaxpouBeerBundle:Brewery')
106
                        ->find($breweryId);
107
108
        if (!$brewery) {
109
            throw new HttpException(404, 'Unable to find this Brewery entity');
110
        }
111
112
        $beer = new Beer();
113
        $beer->setBrewery($brewery);
114
115
        $form = $this->createForm(BeerApiType::class, $beer);
116
        $form->handleRequest($request);
117
118
        if ($form->isValid()) {
119
            $em = $this->getDoctrine()->getManager();
120
            $em->persist($beer);
121
            $em->flush();
122
123
            $view = $this->view($beer, 201);
124
        } else {
125
            $view = $this->view($form, 400);
126
        }
127
128
        return $this->handleView($view);
129
    }
130
131
    /**
132
     * Update an existing Beer (cannot create here, sorry).
133
     *
134
     * @ApiDoc(
135
     *  statusCodes={
136
     *      204="Returned when successful",
137
     *      404="Returned when not found",
138
     *      400="Returned when parameter is wrong"
139
     * },
140
     * input = {
141
     *     "class" = "Maxpou\BeerBundle\Form\Type\BeerApiType",
142
     *     "name"  = ""
143
     * })
144
     *
145
     * @param UUID $breweryId Brewery Id
146
     * @param UUID $beerId    Beer Id
147
     */
148 View Code Duplication
    public function putAction($breweryId, Request $request, $beerId)
0 ignored issues
show
The parameter $breweryId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
149
    {
150
        $beer = $this->getDoctrine()->getManager()
151
                     ->getRepository('MaxpouBeerBundle:Beer')
152
                     ->find($beerId);
153
154
        if (!$beer) {
155
            throw new HttpException(404, 'Unable to find this Beer entity');
156
        }
157
158
        $form = $this->createForm(BeerApiType::class, $beer);
159
        $form->submit($request->request->all());
160
161
        if ($form->isValid()) {
162
            $em = $this->getDoctrine()->getManager();
163
            $em->persist($beer);
164
            $em->flush();
165
166
            $view = $this->view(null, 204);
167
168
            return $this->handleView($view);
169
        } else {
170
            $view = $this->view($form, 400);
171
        }
172
173
        return $view;
174
    }
175
176
    /**
177
     * Delete brewery.
178
     *
179
     * @ApiDoc(
180
     *  statusCodes={
181
     *      204="Returned when successful"
182
     * })
183
     *
184
     * @param UUID $breweryId Brewery Id
185
     * @param UUID $beerId    Beer Id
186
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
187
     */
188
    public function deleteAction($breweryId, $beerId)
0 ignored issues
show
The parameter $breweryId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
189
    {
190
        $beer = $this->getDoctrine()->getManager()
191
                     ->getRepository('MaxpouBeerBundle:Beer')
192
                     ->find($beerId);
193
194
        if ($beer) {
195
            $em = $this->getDoctrine()->getManager();
196
            $em->remove($beer);
197
            $em->flush();
198
        }
199
200
        return $this->view(null, 204);
201
    }
202
203
    /**
204
     * Delete all beers from an existing brewery entity.
205
     *
206
     * @ApiDoc(
207
     *  statusCodes={
208
     *      204="Returned when successful"
209
     * })
210
     *
211
     * @param UUID $breweryId Brewery Id
212
     */
213 View Code Duplication
    public function cdeleteAction($breweryId)
0 ignored issues
show
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...
214
    {
215
        $em = $this->getDoctrine()->getManager();
216
        $brewery = $em->getRepository('MaxpouBeerBundle:Brewery')
217
                      ->find($breweryId);
218
219
        if (!$brewery) {
220
            throw new HttpException(404, 'Unable to find this Brewery entity');
221
        }
222
223
        $em->getRepository('MaxpouBeerBundle:Beer')
224
           ->deleteAll($brewery);
225
226
        return $this->view(null, 204);
227
    }
228
229
    /**
230
     * Options.
231
     *
232
     * @ApiDoc(
233
     *  statusCodes={
234
     *      200="Returned when successful"
235
     * })
236
     *
237
     * @param UUID $breweryId Brewery Id
238
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
239
     */
240
    public function coptionsAction($breweryId)
0 ignored issues
show
The parameter $breweryId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
241
    {
242
        $response = new Response();
243
        $response->headers->set('Allow', 'OPTIONS, GET, POST, DELETE');
244
245
        return $response;
246
    }
247
}
248