1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||||||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||||||
6 | */ |
||||||
7 | |||||||
8 | namespace Spryker\Glue\CustomersRestApi\Processor\Relationship; |
||||||
9 | |||||||
10 | use Generated\Shared\Transfer\CustomerTransfer; |
||||||
11 | use Generated\Shared\Transfer\RestCustomersResponseAttributesTransfer; |
||||||
12 | use Spryker\Glue\CustomersRestApi\Processor\Mapper\CustomerResourceMapperInterface; |
||||||
13 | use Spryker\Glue\CustomersRestApi\Processor\RestResponseBuilder\CustomerRestResponseBuilderInterface; |
||||||
14 | use Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface; |
||||||
15 | use Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface; |
||||||
16 | |||||||
17 | abstract class AbstractCustomerResourceRelationshipExpander implements CustomerResourceRelationshipExpanderInterface |
||||||
18 | { |
||||||
19 | /** |
||||||
20 | * @var \Spryker\Glue\CustomersRestApi\Processor\RestResponseBuilder\CustomerRestResponseBuilderInterface |
||||||
21 | */ |
||||||
22 | protected $customerRestResponseBuilder; |
||||||
23 | |||||||
24 | /** |
||||||
25 | * @var \Spryker\Glue\CustomersRestApi\Processor\Mapper\CustomerResourceMapperInterface |
||||||
26 | */ |
||||||
27 | protected $customerResourceMapper; |
||||||
28 | |||||||
29 | /** |
||||||
30 | * @param \Spryker\Glue\CustomersRestApi\Processor\RestResponseBuilder\CustomerRestResponseBuilderInterface $customerRestResponseBuilder |
||||||
31 | * @param \Spryker\Glue\CustomersRestApi\Processor\Mapper\CustomerResourceMapperInterface $customerResourceMapper |
||||||
32 | */ |
||||||
33 | public function __construct( |
||||||
34 | CustomerRestResponseBuilderInterface $customerRestResponseBuilder, |
||||||
35 | CustomerResourceMapperInterface $customerResourceMapper |
||||||
36 | ) { |
||||||
37 | $this->customerRestResponseBuilder = $customerRestResponseBuilder; |
||||||
38 | $this->customerResourceMapper = $customerResourceMapper; |
||||||
39 | } |
||||||
40 | |||||||
41 | /** |
||||||
42 | * @param array<\Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface> $resources |
||||||
43 | * @param \Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface $restRequest |
||||||
44 | * |
||||||
45 | * @return array<\Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface> |
||||||
46 | */ |
||||||
47 | public function addResourceRelationships(array $resources, RestRequestInterface $restRequest): array |
||||||
48 | { |
||||||
49 | foreach ($resources as $resource) { |
||||||
50 | $customerTransfer = $this->findCustomerTransferInPayload($resource); |
||||||
51 | if (!$customerTransfer) { |
||||||
52 | continue; |
||||||
53 | } |
||||||
54 | |||||||
55 | $restResource = $this->createCustomersRestResourceFromCustomerTransfer($customerTransfer); |
||||||
56 | |||||||
57 | $resource->addRelationship($restResource); |
||||||
58 | } |
||||||
59 | |||||||
60 | return $resources; |
||||||
61 | } |
||||||
62 | |||||||
63 | /** |
||||||
64 | * @param \Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface $restResource |
||||||
65 | * |
||||||
66 | * @return \Generated\Shared\Transfer\CustomerTransfer|null |
||||||
67 | */ |
||||||
68 | abstract protected function findCustomerTransferInPayload(RestResourceInterface $restResource): ?CustomerTransfer; |
||||||
69 | |||||||
70 | /** |
||||||
71 | * @param \Generated\Shared\Transfer\CustomerTransfer|null $customerTransfer |
||||||
72 | * |
||||||
73 | * @return \Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface |
||||||
74 | */ |
||||||
75 | protected function createCustomersRestResourceFromCustomerTransfer(?CustomerTransfer $customerTransfer): RestResourceInterface |
||||||
76 | { |
||||||
77 | $restCustomersResponseAttributesTransfer = $this->customerResourceMapper->mapCustomerTransferToRestCustomersResponseAttributesTransfer( |
||||||
78 | $customerTransfer, |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
79 | new RestCustomersResponseAttributesTransfer(), |
||||||
80 | ); |
||||||
81 | |||||||
82 | return $this->customerRestResponseBuilder->createCustomerRestResource( |
||||||
83 | $customerTransfer->getCustomerReference(), |
||||||
0 ignored issues
–
show
The method
getCustomerReference() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
84 | $restCustomersResponseAttributesTransfer, |
||||||
85 | $customerTransfer, |
||||||
86 | ); |
||||||
87 | } |
||||||
88 | } |
||||||
89 |