Passed
Pull Request — master (#16)
by Anton
12:10 queued 05:26
created

AdvisorQuestionConverter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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\Data;
9
10
use FACTFinder\Data\AdvisorAnswer;
11
use FACTFinder\Data\AdvisorQuestion;
12
use Generated\Shared\Transfer\FactFinderSdkDataAdvisorAnswerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...taAdvisorAnswerTransfer 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 Generated\Shared\Transfer\FactFinderSdkDataAdvisorQuestionTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...AdvisorQuestionTransfer 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...
14
use SprykerEco\Client\FactFinderSdk\Business\Api\Converter\BaseConverter;
15
16
class AdvisorQuestionConverter extends BaseConverter implements AdvisorQuestionConverterInterface
17
{
18
    /**
19
     * @var \FACTFinder\Data\AdvisorQuestion
20
     */
21
    protected $advisorQuestion;
22
23
    /**
24
     * @var \SprykerEco\Client\FactFinderSdk\Business\Api\Converter\Data\ItemConverterInterface
25
     */
26
    protected $itemConverter;
27
28
    /**
29
     * @param \SprykerEco\Client\FactFinderSdk\Business\Api\Converter\Data\ItemConverterInterface $itemConverter
30
     */
31
    public function __construct(ItemConverterInterface $itemConverter)
32
    {
33
        $this->itemConverter = $itemConverter;
34
    }
35
36
    /**
37
     * @param \FACTFinder\Data\AdvisorQuestion $advisorQuestion
38
     *
39
     * @return void
40
     */
41
    public function setAdvisorQuestion(AdvisorQuestion $advisorQuestion)
42
    {
43
        $this->advisorQuestion = $advisorQuestion;
44
    }
45
46
    /**
47
     * @param \FACTFinder\Data\AdvisorQuestion|null $advisorQuestion
48
     *
49
     * @return \Generated\Shared\Transfer\FactFinderSdkDataAdvisorQuestionTransfer
50
     */
51
    public function convert($advisorQuestion = null)
52
    {
53
        $advisorQuestion = $advisorQuestion === null ? $advisorQuestion : $this->advisorQuestion;
54
        $factFinderDataAdvisorQuestionTransfer = new FactFinderSdkDataAdvisorQuestionTransfer();
55
        $factFinderDataAdvisorQuestionTransfer->setText($advisorQuestion->getText());
0 ignored issues
show
Bug introduced by
The method getText() 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 ignore-call  annotation

55
        $factFinderDataAdvisorQuestionTransfer->setText($advisorQuestion->/** @scrutinizer ignore-call */ getText());

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.

Loading history...
56
57
        if ($advisorQuestion->hasAnswers()) {
58
            foreach ($advisorQuestion->getAnswers() as $advisorAnswer) {
59
                $factFinderDataAdvisorQuestionTransfer->addAdvisorAnswer(
60
                    $this->convertAnswer($advisorAnswer)
61
                );
62
            }
63
        }
64
65
        return $factFinderDataAdvisorQuestionTransfer;
66
    }
67
68
    /**
69
     * @param \FACTFinder\Data\AdvisorAnswer $advisorAnswer
70
     *
71
     * @return \Generated\Shared\Transfer\FactFinderSdkDataAdvisorAnswerTransfer
72
     */
73
    public function convertAnswer(AdvisorAnswer $advisorAnswer)
74
    {
75
        $factFinderDataAdvisorAnswerTransfer = new FactFinderSdkDataAdvisorAnswerTransfer();
76
        $factFinderDataAdvisorAnswerTransfer->setText($advisorAnswer->getText());
77
        $factFinderDataAdvisorAnswerTransfer->setUrl($advisorAnswer->getUrl());
78
        $this->itemConverter->setItem($advisorAnswer);
79
        $factFinderDataAdvisorAnswerTransfer->setItem(
80
            $this->itemConverter->convert()
81
        );
82
83
        if ($advisorAnswer->hasFollowUpQuestions()) {
84
            foreach ($advisorAnswer->getFollowUpQuestions() as $followUpQuestion) {
85
                $factFinderDataAdvisorAnswerTransfer->addFollowUpQuestion(
86
                    $this->convert($followUpQuestion)
87
                );
88
            }
89
        }
90
91
        return $factFinderDataAdvisorAnswerTransfer;
92
    }
93
}
94