GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 65d67e...988c58 )
by
unknown
08:37
created

VendorController::updatePositionsAction()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 7
eloc 15
nc 4
nop 1
dl 0
loc 28
rs 8.8333
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusVendorPlugin\Controller;
6
7
use Odiseo\SyliusVendorPlugin\Entity\VendorInterface;
8
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
9
use Sylius\Component\Resource\ResourceActions;
10
use Symfony\Component\HttpFoundation\JsonResponse;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\HttpKernel\Exception\HttpException;
14
15
class VendorController extends ResourceController
16
{
17
    /**
18
     * @param Request $request
19
     * @return Response
20
     */
21
    public function updatePositionsAction(Request $request): Response
22
    {
23
        $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
24
        $this->isGrantedOr403($configuration, ResourceActions::UPDATE);
25
        $vendorsToUpdate = $request->get('vendors');
26
27
        if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid('update-vendor-position', $request->request->get('_csrf_token'))) {
28
            throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.');
29
        }
30
31
        if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'], true) && null !== $vendorsToUpdate) {
32
            /** @var array $vendorToUpdate */
33
            foreach ($vendorsToUpdate as $vendorToUpdate) {
34
                if (!is_numeric($vendorToUpdate['position'])) {
35
                    throw new HttpException(
36
                        Response::HTTP_NOT_ACCEPTABLE,
37
                        sprintf('The vendor position "%s" is invalid.', $vendorToUpdate['position'])
38
                    );
39
                }
40
41
                /** @var VendorInterface $vendor */
42
                $vendor = $this->repository->findOneBy(['id' => $vendorToUpdate['id']]);
43
                $vendor->setPosition((int) $vendorToUpdate['position']);
44
                $this->manager->flush();
45
            }
46
        }
47
48
        return new JsonResponse();
49
    }
50
}
51