Issues (3641)

DataMapper/CategoryNodePageSearchDataMapper.php (1 issue)

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\Zed\CategoryPageSearch\Business\Search\DataMapper;
9
10
use ArrayObject;
11
use Generated\Shared\Search\PageIndexMap;
12
use Generated\Shared\Transfer\CategoryLocalizedAttributesTransfer;
13
use Generated\Shared\Transfer\NodeTransfer;
14
15
class CategoryNodePageSearchDataMapper implements CategoryNodePageSearchDataMapperInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    protected const TYPE_CATEGORY = 'category';
21
22
    /**
23
     * @var string
24
     */
25
    protected const KEY_ID_CATEGORY = 'id_category';
26
27
    /**
28
     * @var string
29
     */
30
    protected const KEY_NAME = 'name';
31
32
    /**
33
     * @var string
34
     */
35
    protected const KEY_URL = 'url';
36
37
    /**
38
     * @var string
39
     */
40
    protected const KEY_TYPE = 'type';
41
42
    /**
43
     * @param \Generated\Shared\Transfer\NodeTransfer $nodeTransfer
44
     * @param string $storeName
45
     * @param string $localeName
46
     *
47
     * @return array
48
     */
49
    public function mapNodeTransferToCategoryNodePageSearchDataForStoreAndLocale(
50
        NodeTransfer $nodeTransfer,
51
        string $storeName,
52
        string $localeName
53
    ): array {
54
        $categoryLocalizedAttributesTransfer = $this->findCategoryLocalizedAttributesTransferForLocale(
0 ignored issues
show
Are you sure the assignment to $categoryLocalizedAttributesTransfer is correct as $this->findCategoryLocal...ributes(), $localeName) targeting Spryker\Zed\CategoryPage...utesTransferForLocale() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
55
            $nodeTransfer->getCategoryOrFail()->getLocalizedAttributes(),
56
            $localeName,
57
        );
58
59
        return [
60
            PageIndexMap::IS_ACTIVE => $nodeTransfer->getCategoryOrFail()->getIsActive() && $nodeTransfer->getCategoryOrFail()->getIsSearchable(),
61
            PageIndexMap::STORE => $storeName,
62
            PageIndexMap::LOCALE => $localeName,
63
            PageIndexMap::TYPE => static::TYPE_CATEGORY,
64
            PageIndexMap::SEARCH_RESULT_DATA => $this->getSearchResultData($nodeTransfer, $categoryLocalizedAttributesTransfer),
65
            PageIndexMap::FULL_TEXT_BOOSTED => $this->getFullTextBoostedData($categoryLocalizedAttributesTransfer),
66
            PageIndexMap::FULL_TEXT => $this->getFullTextData($categoryLocalizedAttributesTransfer),
67
            PageIndexMap::SUGGESTION_TERMS => $this->getSuggestionTermsData($categoryLocalizedAttributesTransfer),
68
            PageIndexMap::COMPLETION_TERMS => $this->getCompletionTermsData($categoryLocalizedAttributesTransfer),
69
        ];
70
    }
71
72
    /**
73
     * @param \Generated\Shared\Transfer\NodeTransfer $nodeTransfer
74
     * @param \Generated\Shared\Transfer\CategoryLocalizedAttributesTransfer|null $categoryLocalizedAttributesTransfer
75
     *
76
     * @return array
77
     */
78
    protected function getSearchResultData(
79
        NodeTransfer $nodeTransfer,
80
        ?CategoryLocalizedAttributesTransfer $categoryLocalizedAttributesTransfer = null
81
    ): array {
82
        $searchResultData = [
83
            static::KEY_ID_CATEGORY => $nodeTransfer->getFkCategory(),
84
            static::KEY_TYPE => static::TYPE_CATEGORY,
85
        ];
86
87
        if (!$categoryLocalizedAttributesTransfer) {
88
            return $searchResultData;
89
        }
90
91
        $searchResultData[static::KEY_NAME] = $categoryLocalizedAttributesTransfer->getName();
92
        $searchResultData[static::KEY_URL] = $categoryLocalizedAttributesTransfer->getUrl();
93
94
        return $searchResultData;
95
    }
96
97
    /**
98
     * @param \Generated\Shared\Transfer\CategoryLocalizedAttributesTransfer|null $categoryLocalizedAttributesTransfer
99
     *
100
     * @return array
101
     */
102
    protected function getFullTextBoostedData(?CategoryLocalizedAttributesTransfer $categoryLocalizedAttributesTransfer): array
103
    {
104
        return $categoryLocalizedAttributesTransfer ? [$categoryLocalizedAttributesTransfer->getName()] : [''];
105
    }
106
107
    /**
108
     * @param \Generated\Shared\Transfer\CategoryLocalizedAttributesTransfer|null $categoryLocalizedAttributesTransfer
109
     *
110
     * @return array
111
     */
112
    protected function getFullTextData(?CategoryLocalizedAttributesTransfer $categoryLocalizedAttributesTransfer): array
113
    {
114
        if (!$categoryLocalizedAttributesTransfer) {
115
            return [''];
116
        }
117
118
        return [
119
            $categoryLocalizedAttributesTransfer->getMetaTitle() ?? '',
120
            $categoryLocalizedAttributesTransfer->getMetaKeywords() ?? '',
121
            $categoryLocalizedAttributesTransfer->getMetaDescription() ?? '',
122
        ];
123
    }
124
125
    /**
126
     * @param \Generated\Shared\Transfer\CategoryLocalizedAttributesTransfer|null $categoryLocalizedAttributesTransfer
127
     *
128
     * @return array
129
     */
130
    protected function getSuggestionTermsData(?CategoryLocalizedAttributesTransfer $categoryLocalizedAttributesTransfer): array
131
    {
132
        return $categoryLocalizedAttributesTransfer ? [$categoryLocalizedAttributesTransfer->getName()] : [''];
133
    }
134
135
    /**
136
     * @param \Generated\Shared\Transfer\CategoryLocalizedAttributesTransfer|null $categoryLocalizedAttributesTransfer
137
     *
138
     * @return array
139
     */
140
    protected function getCompletionTermsData(?CategoryLocalizedAttributesTransfer $categoryLocalizedAttributesTransfer): array
141
    {
142
        return $categoryLocalizedAttributesTransfer ? [$categoryLocalizedAttributesTransfer->getName()] : [''];
143
    }
144
145
    /**
146
     * @param \ArrayObject<int, \Generated\Shared\Transfer\CategoryLocalizedAttributesTransfer> $categoryLocalizedAttributesTransfers
147
     * @param string $localeName
148
     *
149
     * @return \Generated\Shared\Transfer\CategoryLocalizedAttributesTransfer|null
150
     */
151
    protected function findCategoryLocalizedAttributesTransferForLocale(
152
        ArrayObject $categoryLocalizedAttributesTransfers,
153
        string $localeName
154
    ): ?CategoryLocalizedAttributesTransfer {
155
        foreach ($categoryLocalizedAttributesTransfers as $categoryLocalizedAttributesTransfer) {
156
            if ($localeName === $categoryLocalizedAttributesTransfer->getLocaleOrFail()->getLocaleName()) {
157
                return $categoryLocalizedAttributesTransfer;
158
            }
159
        }
160
161
        return null;
162
    }
163
}
164