|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Sylius\ShopApiPlugin\Controller\Checkout; |
|
6
|
|
|
|
|
7
|
|
|
use FOS\RestBundle\View\View; |
|
8
|
|
|
use FOS\RestBundle\View\ViewHandlerInterface; |
|
9
|
|
|
use League\Tactician\CommandBus; |
|
10
|
|
|
use Sylius\Component\Core\Model\ShopUserInterface; |
|
11
|
|
|
use Sylius\ShopApiPlugin\Command\CompleteOrder; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
14
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
15
|
|
|
|
|
16
|
|
|
final class CompleteOrderAction |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var ViewHandlerInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
private $viewHandler; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var CommandBus |
|
25
|
|
|
*/ |
|
26
|
|
|
private $bus; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var TokenStorageInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $tokenStorage; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param ViewHandlerInterface $viewHandler |
|
35
|
|
|
* @param CommandBus $bus |
|
36
|
|
|
* @param TokenStorageInterface $tokenStorage |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(ViewHandlerInterface $viewHandler, CommandBus $bus, TokenStorageInterface $tokenStorage) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->viewHandler = $viewHandler; |
|
41
|
|
|
$this->bus = $bus; |
|
42
|
|
|
$this->tokenStorage = $tokenStorage; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param Request $request |
|
47
|
|
|
* |
|
48
|
|
|
* @return Response |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __invoke(Request $request) |
|
51
|
|
|
{ |
|
52
|
|
|
$email = $this->provideUserEmail($request); |
|
53
|
|
|
|
|
54
|
|
|
$this->bus->handle(new CompleteOrder( |
|
55
|
|
|
$request->attributes->get('token'), |
|
56
|
|
|
$email, |
|
57
|
|
|
$request->request->get('notes') |
|
58
|
|
|
)); |
|
59
|
|
|
|
|
60
|
|
|
return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param Request $request |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
private function provideUserEmail(Request $request) |
|
69
|
|
|
{ |
|
70
|
|
|
$user = $this->tokenStorage->getToken()->getUser(); |
|
71
|
|
|
|
|
72
|
|
|
if ($user instanceof ShopUserInterface) { |
|
|
|
|
|
|
73
|
|
|
return $user->getCustomer()->getEmail(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $request->request->get('email'); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.