These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sylius package. |
||
5 | * |
||
6 | * (c) Paweł Jędrzejewski |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace Sylius\Bundle\CoreBundle\Context; |
||
15 | |||
16 | use Sylius\Component\Channel\Context\ChannelContextInterface; |
||
17 | use Sylius\Component\Channel\Context\ChannelNotFoundException; |
||
18 | use Sylius\Component\Core\Repository\OrderRepositoryInterface; |
||
19 | use Sylius\Component\Customer\Context\CustomerContextInterface; |
||
20 | use Sylius\Component\Order\Context\CartContextInterface; |
||
21 | use Sylius\Component\Order\Context\CartNotFoundException; |
||
22 | use Sylius\Component\Order\Model\OrderInterface; |
||
23 | |||
24 | final class CustomerAndChannelBasedCartContext implements CartContextInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var CustomerContextInterface |
||
28 | */ |
||
29 | private $customerContext; |
||
30 | |||
31 | /** |
||
32 | * @var ChannelContextInterface |
||
33 | */ |
||
34 | private $channelContext; |
||
35 | |||
36 | /** |
||
37 | * @var OrderRepositoryInterface |
||
38 | */ |
||
39 | private $orderRepository; |
||
40 | |||
41 | /** |
||
42 | * @param CustomerContextInterface $customerContext |
||
43 | * @param ChannelContextInterface $channelContext |
||
44 | * @param OrderRepositoryInterface $orderRepository |
||
45 | */ |
||
46 | public function __construct( |
||
47 | CustomerContextInterface $customerContext, |
||
48 | ChannelContextInterface $channelContext, |
||
49 | OrderRepositoryInterface $orderRepository |
||
50 | ) { |
||
51 | $this->customerContext = $customerContext; |
||
52 | $this->channelContext = $channelContext; |
||
53 | $this->orderRepository = $orderRepository; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function getCart(): OrderInterface |
||
60 | { |
||
61 | try { |
||
62 | $channel = $this->channelContext->getChannel(); |
||
63 | } catch (ChannelNotFoundException $exception) { |
||
64 | throw new CartNotFoundException('Sylius was not able to find the cart, as there is no current channel.'); |
||
65 | } |
||
66 | |||
67 | $customer = $this->customerContext->getCustomer(); |
||
68 | if (null === $customer) { |
||
69 | throw new CartNotFoundException('Sylius was not able to find the cart, as there is no logged in user.'); |
||
70 | } |
||
71 | |||
72 | $cart = $this->orderRepository->findLatestCartByChannelAndCustomer($channel, $customer); |
||
0 ignored issues
–
show
$customer of type object<Sylius\Component\...odel\CustomerInterface> is not a sub-type of object<Sylius\Component\...odel\CustomerInterface> . It seems like you assume a child interface of the interface Sylius\Component\Customer\Model\CustomerInterface to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.
Loading history...
|
|||
73 | if (null === $cart) { |
||
74 | throw new CartNotFoundException('Sylius was not able to find the cart for currently logged in user.'); |
||
75 | } |
||
76 | |||
77 | return $cart; |
||
78 | } |
||
79 | } |
||
80 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.