1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Spryker Marketplace License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace Spryker\Zed\ProductMerchantPortalGui\Communication\Extractor; |
||
9 | |||
10 | use ArrayObject; |
||
11 | use Generated\Shared\Transfer\LocaleTransfer; |
||
12 | use Generated\Shared\Transfer\LocalizedAttributesTransfer; |
||
13 | use Generated\Shared\Transfer\ProductManagementAttributeFilterTransfer; |
||
14 | use Spryker\Zed\ProductMerchantPortalGui\Dependency\Facade\ProductMerchantPortalGuiToProductAttributeFacadeInterface; |
||
15 | |||
16 | class LocalizedAttributesExtractor implements LocalizedAttributesExtractorInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var \Spryker\Zed\ProductMerchantPortalGui\Dependency\Facade\ProductMerchantPortalGuiToProductAttributeFacadeInterface |
||
20 | */ |
||
21 | protected ProductMerchantPortalGuiToProductAttributeFacadeInterface $productAttributeFacade; |
||
22 | |||
23 | /** |
||
24 | * @param \Spryker\Zed\ProductMerchantPortalGui\Dependency\Facade\ProductMerchantPortalGuiToProductAttributeFacadeInterface $productAttributeFacade |
||
25 | */ |
||
26 | public function __construct(ProductMerchantPortalGuiToProductAttributeFacadeInterface $productAttributeFacade) |
||
27 | { |
||
28 | $this->productAttributeFacade = $productAttributeFacade; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @param \ArrayObject<int, \Generated\Shared\Transfer\LocalizedAttributesTransfer> $localizedAttributeTransfers |
||
33 | * @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer |
||
34 | * |
||
35 | * @return \Generated\Shared\Transfer\LocalizedAttributesTransfer|null |
||
36 | */ |
||
37 | public function extractLocalizedAttributes( |
||
38 | ArrayObject $localizedAttributeTransfers, |
||
39 | LocaleTransfer $localeTransfer |
||
40 | ): ?LocalizedAttributesTransfer { |
||
41 | foreach ($localizedAttributeTransfers as $localizedAttributesTransfer) { |
||
42 | $localeFromLocalizedAttributes = $localizedAttributesTransfer->getLocale(); |
||
43 | if (!$localeFromLocalizedAttributes) { |
||
44 | continue; |
||
45 | } |
||
46 | |||
47 | if ($localeFromLocalizedAttributes->getIdLocale() === $localeTransfer->getIdLocale()) { |
||
48 | return $localizedAttributesTransfer; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | return null; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param array<string> $attributes |
||
57 | * @param \ArrayObject<int, \Generated\Shared\Transfer\LocalizedAttributesTransfer> $localizedAttributeTransfers |
||
58 | * @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer |
||
59 | * |
||
60 | * @return array<string> |
||
61 | */ |
||
62 | public function extractSuperAttributes( |
||
63 | array $attributes, |
||
64 | ArrayObject $localizedAttributeTransfers, |
||
65 | LocaleTransfer $localeTransfer |
||
66 | ): array { |
||
67 | $localizedAttributesTransfer = $this->extractLocalizedAttributes($localizedAttributeTransfers, $localeTransfer); |
||
0 ignored issues
–
show
|
|||
68 | $localizedAttributes = $localizedAttributesTransfer ? $localizedAttributesTransfer->getAttributes() : []; |
||
0 ignored issues
–
show
|
|||
69 | $attributes = array_merge($attributes, $localizedAttributes); |
||
70 | $productManagementAttributeTransfers = $this->productAttributeFacade->getProductManagementAttributes( |
||
71 | (new ProductManagementAttributeFilterTransfer())->setKeys(array_keys($attributes)), |
||
72 | )->getProductManagementAttributes(); |
||
73 | |||
74 | $superAttributes = []; |
||
75 | foreach ($productManagementAttributeTransfers as $productManagementAttributeTransfer) { |
||
76 | $attributeKey = $productManagementAttributeTransfer->getKeyOrFail(); |
||
77 | |||
78 | if ($productManagementAttributeTransfer->getIsSuperOrFail() && isset($attributes[$attributeKey])) { |
||
79 | $superAttributes[$attributeKey] = $attributes[$attributeKey]; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | return $superAttributes; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param array<string> $attributes |
||
88 | * @param \ArrayObject<int, \Generated\Shared\Transfer\LocalizedAttributesTransfer> $localizedAttributeTransfers |
||
89 | * @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer |
||
90 | * |
||
91 | * @return array<string> |
||
92 | */ |
||
93 | public function extractCombinedSuperAttributeNames( |
||
94 | array $attributes, |
||
95 | ArrayObject $localizedAttributeTransfers, |
||
96 | LocaleTransfer $localeTransfer |
||
97 | ): array { |
||
98 | $superAttributes = $this->extractSuperAttributes($attributes, $localizedAttributeTransfers, $localeTransfer); |
||
99 | $combinedSuperAttributeNames = []; |
||
100 | |||
101 | foreach ($superAttributes as $attributeKey => $attributeValue) { |
||
102 | $combinedSuperAttributeNames[$attributeKey] = ucfirst(sprintf('%s: %s', $attributeKey, $attributeValue)); |
||
103 | } |
||
104 | |||
105 | return $combinedSuperAttributeNames; |
||
106 | } |
||
107 | } |
||
108 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.