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

ShowAddressBookAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A __invoke() 0 18 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Controller\AddressBook;
6
7
use FOS\RestBundle\View\View;
8
use FOS\RestBundle\View\ViewHandlerInterface;
9
use Sylius\Component\Core\Model\Customer;
10
use Sylius\Component\Core\Model\ShopUserInterface;
11
use Sylius\ShopApiPlugin\Factory\AddressBookViewFactoryInterface;
12
use Sylius\ShopApiPlugin\Factory\AddressViewFactory;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpFoundation\Response;
15
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
16
use Webmozart\Assert\Assert;
17
18
class ShowAddressBookAction
19
{
20
    /**
21
     * @var ViewHandlerInterface
22
     */
23
    private $viewHandler;
24
25
    /**
26
     * @var TokenStorageInterface
27
     */
28
    private $tokenStorage;
29
30
    /**
31
     * @var AddressViewFactory
32
     */
33
    private $addressBookViewFactory;
34
35
    /**
36
     * @param ViewHandlerInterface $viewHandler
37
     * @param TokenStorageInterface $tokenStorage
38
     * @param AddressBookViewFactoryInterface $addressBookViewFactory
39
     */
40
    public function __construct(
41
        ViewHandlerInterface $viewHandler,
42
        TokenStorageInterface $tokenStorage,
43
        AddressBookViewFactoryInterface $addressBookViewFactory
44
    ) {
45
        $this->viewHandler = $viewHandler;
46
        $this->tokenStorage = $tokenStorage;
47
        $this->addressBookViewFactory = $addressBookViewFactory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $addressBookViewFactory of type object<Sylius\ShopApiPlu...okViewFactoryInterface> is incompatible with the declared type object<Sylius\ShopApiPlu...ory\AddressViewFactory> of property $addressBookViewFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
    }
49
50
    public function __invoke(Request $request): Response
51
    {
52
        /** @var ShopUserInterface $user */
53
        $user = $this->tokenStorage->getToken()->getUser();
54
55
        Assert::isInstanceOf($user, ShopUserInterface::class);
56
57
        /** @var Customer $customer */
58
        $customer = $user->getCustomer();
59
        $addresses = $customer->getAddresses();
60
61
        $addressViews = [];
62
        foreach ($addresses as $address) {
63
            $addressViews[] = $this->addressBookViewFactory->create($address, $customer);
0 ignored issues
show
Unused Code introduced by
The call to AddressViewFactory::create() has too many arguments starting with $customer.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
64
        }
65
66
        return $this->viewHandler->handle(View::create($addressViews, Response::HTTP_OK));
67
    }
68
}
69