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\Behat\Context\Transform; |
||
15 | |||
16 | use Behat\Behat\Context\Context; |
||
17 | use Sylius\Component\Core\Repository\CustomerRepositoryInterface; |
||
18 | use Sylius\Component\Core\Repository\OrderRepositoryInterface; |
||
19 | use Webmozart\Assert\Assert; |
||
20 | |||
21 | final class OrderContext implements Context |
||
22 | { |
||
23 | /** |
||
24 | * @var CustomerRepositoryInterface |
||
25 | */ |
||
26 | private $customerRepository; |
||
27 | |||
28 | /** |
||
29 | * @var OrderRepositoryInterface |
||
30 | */ |
||
31 | private $orderRepository; |
||
32 | |||
33 | /** |
||
34 | * @param CustomerRepositoryInterface $customerRepository |
||
35 | * @param OrderRepositoryInterface $orderRepository |
||
36 | */ |
||
37 | public function __construct( |
||
38 | CustomerRepositoryInterface $customerRepository, |
||
39 | OrderRepositoryInterface $orderRepository |
||
40 | ) { |
||
41 | $this->customerRepository = $customerRepository; |
||
42 | $this->orderRepository = $orderRepository; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @Transform :order |
||
47 | */ |
||
48 | public function getOrderByNumber($orderNumber) |
||
49 | { |
||
50 | $orderNumber = $this->getOrderNumber($orderNumber); |
||
51 | $order = $this->orderRepository->findOneBy(['number' => $orderNumber]); |
||
52 | |||
53 | Assert::notNull($order, sprintf('Cannot find order with number %s', $orderNumber)); |
||
54 | |||
55 | return $order; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @Transform /^this order made by "([^"]+)"$/ |
||
60 | * @Transform /^order placed by "([^"]+)"$/ |
||
61 | * @Transform /^the order of "([^"]+)"$/ |
||
62 | */ |
||
63 | public function getOrderByCustomer($email) |
||
64 | { |
||
65 | $customer = $this->customerRepository->findOneBy(['email' => $email]); |
||
66 | Assert::notNull($customer, sprintf('Cannot find customer with email %s.', $email)); |
||
67 | |||
68 | $orders = $this->orderRepository->findByCustomer($customer); |
||
0 ignored issues
–
show
|
|||
69 | Assert::notEmpty($orders); |
||
70 | |||
71 | return end($orders); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @Transform :orderNumber |
||
76 | * @Transform /^an order "([^"]+)"$/ |
||
77 | * @Transform /^the order "([^"]+)"$/ |
||
78 | */ |
||
79 | public function getOrderNumber($orderNumber) |
||
80 | { |
||
81 | return str_replace('#', '', $orderNumber); |
||
82 | } |
||
83 | } |
||
84 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: