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

ShowAddressBookAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Controller\AddressBook;
4
5
use FOS\RestBundle\View\View;
6
use FOS\RestBundle\View\ViewHandlerInterface;
7
use Sylius\Component\Core\Model\Customer;
8
use Sylius\Component\Core\Model\ShopUserInterface;
9
use Sylius\ShopApiPlugin\Factory\AddressBookViewFactoryInterface;
10
use Sylius\ShopApiPlugin\Factory\AddressViewFactory;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
14
use Webmozart\Assert\Assert;
15
16
class ShowAddressBookAction
17
{
18
    /**
19
     * @var ViewHandlerInterface
20
     */
21
    private $viewHandler;
22
23
    /**
24
     * @var TokenStorageInterface
25
     */
26
    private $tokenStorage;
27
28
    /**
29
     * @var AddressViewFactory
30
     */
31
    private $addressBookViewFactory;
32
33
    /**
34
     * @param ViewHandlerInterface $viewHandler
35
     * @param TokenStorageInterface $tokenStorage
36
     * @param AddressBookViewFactoryInterface $addressBookViewFactory
37
     */
38
    public function __construct(
39
        ViewHandlerInterface $viewHandler,
40
        TokenStorageInterface $tokenStorage,
41
        AddressBookViewFactoryInterface $addressBookViewFactory
42
    )
43
    {
44
        $this->viewHandler = $viewHandler;
45
        $this->tokenStorage = $tokenStorage;
46
        $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...
47
    }
48
49
    public function __invoke(Request $request): Response
50
    {
51
        /** @var ShopUserInterface $user */
52
        $user = $this->tokenStorage->getToken()->getUser();
53
54
        Assert::isInstanceOf($user, ShopUserInterface::class);
55
56
        /** @var Customer $customer */
57
        $customer = $user->getCustomer();
58
        $addresses = $customer->getAddresses();
59
60
        $addressViews = [];
61
        foreach ($addresses as $address) {
62
            $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...
63
        }
64
65
        return $this->viewHandler->handle(View::create($addressViews, Response::HTTP_OK));
66
    }
67
}