RecommendationResponseConverter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 25
dl 0
loc 75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFields() 0 9 2
A convert() 0 15 3
A getRecommendationData() 0 12 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Client\FactFinderSdk\Business\Api\Converter;
9
10
use FACTFinder\Adapter\Recommendation as FactFinderRecommendationAdapter;
11
use FACTFinder\Data\Record;
12
use Generated\Shared\Transfer\FactFinderSdkRecommendationResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ndationResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use SprykerEco\Client\FactFinderSdk\FactFinderSdkConfig;
14
15
class RecommendationResponseConverter extends BaseConverter implements ConverterInterface
16
{
17
    /**
18
     * @var \FACTFinder\Adapter\Recommendation
19
     */
20
    protected $recommendationAdapter;
21
22
    /**
23
     * @var \SprykerEco\Client\FactFinderSdk\FactFinderSdkConfig
24
     */
25
    protected $factFinderSdkConfig;
26
27
    /**
28
     * @param \FACTFinder\Adapter\Recommendation $recommendationAdapter
29
     * @param \SprykerEco\Client\FactFinderSdk\FactFinderSdkConfig $factFinderSdkConfig
30
     */
31
    public function __construct(FactFinderRecommendationAdapter $recommendationAdapter, FactFinderSdkConfig $factFinderSdkConfig)
32
    {
33
        $this->recommendationAdapter = $recommendationAdapter;
34
        $this->factFinderSdkConfig = $factFinderSdkConfig;
35
    }
36
37
    /**
38
     * @return \Generated\Shared\Transfer\FactFinderSdkRecommendationResponseTransfer
39
     */
40
    public function convert()
41
    {
42
        $responseTransfer = new FactFinderSdkRecommendationResponseTransfer();
43
44
        $recommendations = $this->recommendationAdapter
45
            ->getRecommendations();
46
47
        if ($recommendations->count()) {
48
            foreach ($recommendations as $recommendation) {
49
                $recommendationData = $this->getRecommendationData($recommendation);
50
                $responseTransfer->addRecommendations($recommendationData);
51
            }
52
        }
53
54
        return $responseTransfer;
55
    }
56
57
    /**
58
     * @param \FACTFinder\Data\Record $recommendation
59
     *
60
     * @return array
61
     */
62
    protected function getRecommendationData(Record $recommendation)
63
    {
64
        $result = [];
65
66
        $result['position'] = $recommendation->getPosition();
67
        $result['seoPath'] = $recommendation->getSeoPath();
68
        $result['keywords'] = $recommendation->getKeywords();
69
        $result['similarity'] = $recommendation->getSimilarity();
70
        $result['id'] = $recommendation->getID();
71
        $result['fields'] = $this->getFields($recommendation);
72
73
        return $result;
74
    }
75
76
    /**
77
     * @param \FACTFinder\Data\Record $recommendation
78
     *
79
     * @return array
80
     */
81
    protected function getFields(Record $recommendation)
82
    {
83
        $fields = [];
84
85
        foreach ($this->factFinderSdkConfig->getItemFields() as $fieldName) {
86
            $fields[$fieldName] = $recommendation->getField($fieldName);
87
        }
88
89
        return $fields;
90
    }
91
}
92