Failed Conditions
Pull Request — master (#229)
by
unknown
02:57
created

RemoveAddressAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 64
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A __invoke() 0 14 2
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Controller\AddressBook;
4
5
use FOS\RestBundle\View\View;
6
use FOS\RestBundle\View\ViewHandlerInterface;
7
use League\Tactician\CommandBus;
8
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactory;
9
use Sylius\ShopApiPlugin\Request\RemoveAddressRequest;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
13
use Symfony\Component\Validator\Validator\ValidatorInterface;
14
15
class RemoveAddressAction
16
{
17
    /**
18
     * @var ViewHandlerInterface
19
     */
20
    private $viewHandler;
21
22
    /**
23
     * @var ValidatorInterface
24
     */
25
    private $validator;
26
27
    /**
28
     * @var ValidationErrorViewFactory
29
     */
30
    private $validationErrorViewFactory;
31
32
    /**
33
     * @var CommandBus
34
     */
35
    private $bus;
36
37
    /**
38
     * @var TokenStorageInterface
39
     */
40
    private $tokenStorage;
41
42
    /**
43
     * @param ViewHandlerInterface $viewHandler
44
     * @param ValidatorInterface $validator
45
     * @param ValidationErrorViewFactory $validationErrorViewFactory
46
     * @param CommandBus $bus
47
     * @param TokenStorageInterface $tokenStorage
48
     */
49
    public function __construct(
50
        ViewHandlerInterface $viewHandler,
51
        ValidatorInterface $validator,
52
        ValidationErrorViewFactory $validationErrorViewFactory,
53
        CommandBus $bus,
54
        TokenStorageInterface $tokenStorage
55
    )
56
    {
57
        $this->viewHandler = $viewHandler;
58
        $this->validator = $validator;
59
        $this->validationErrorViewFactory = $validationErrorViewFactory;
60
        $this->bus = $bus;
61
        $this->tokenStorage = $tokenStorage;
62
    }
63
64
    public function __invoke(Request $request): Response
65
    {
66
        $removeAddressRequest = new RemoveAddressRequest($request, $this->tokenStorage->getToken()->getUser());
67
68
        $validationResults = $this->validator->validate($removeAddressRequest);
69
70
        if (0 !== count($validationResults)) {
71
            return $this->viewHandler->handle(View::create($this->validationErrorViewFactory->create($validationResults), Response::HTTP_BAD_REQUEST));
72
        }
73
74
        $this->bus->handle($removeAddressRequest->getCommand());
75
76
        return $this->viewHandler->handle(View::create("", Response::HTTP_NO_CONTENT));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
77
    }
78
}