Passed
Pull Request — master (#4)
by Aleksey
11:47 queued 02:44
created

CrefoPayQuoteExpander   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addResponseDataToQuoteTransfer() 0 11 1
A expand() 0 18 2
A __construct() 0 6 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\CrefoPay\Business\Quote\Expander;
9
10
use Generated\Shared\Transfer\CrefoPayApiRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...foPayApiRequestTransfer 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...
11
use Generated\Shared\Transfer\CrefoPayApiResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...oPayApiResponseTransfer 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...
12
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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\Zed\CrefoPay\Business\Quote\Expander\Mapper\CrefoPayQuoteExpanderMapperInterface;
14
use SprykerEco\Zed\CrefoPay\Dependency\Facade\CrefoPayToCrefoPayApiFacadeInterface;
15
16
class CrefoPayQuoteExpander implements CrefoPayQuoteExpanderInterface
17
{
18
    /**
19
     * @var \SprykerEco\Zed\CrefoPay\Business\Quote\Expander\Mapper\CrefoPayQuoteExpanderMapperInterface
20
     */
21
    protected $mapper;
22
23
    /**
24
     * @var \SprykerEco\Zed\CrefoPay\Dependency\Facade\CrefoPayToCrefoPayApiFacadeInterface
25
     */
26
    protected $crefoPayApiFacade;
27
28
    /**
29
     * @param \SprykerEco\Zed\CrefoPay\Business\Quote\Expander\Mapper\CrefoPayQuoteExpanderMapperInterface $mapper
30
     * @param \SprykerEco\Zed\CrefoPay\Dependency\Facade\CrefoPayToCrefoPayApiFacadeInterface $crefoPayApiFacade
31
     */
32
    public function __construct(
33
        CrefoPayQuoteExpanderMapperInterface $mapper,
34
        CrefoPayToCrefoPayApiFacadeInterface $crefoPayApiFacade
35
    ) {
36
        $this->mapper = $mapper;
37
        $this->crefoPayApiFacade = $crefoPayApiFacade;
38
    }
39
40
    /**
41
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
42
     *
43
     * @return \Generated\Shared\Transfer\QuoteTransfer
44
     */
45
    public function expand(QuoteTransfer $quoteTransfer): QuoteTransfer
46
    {
47
        $requestTransfer = $this->mapper
48
            ->mapQuoteTransferToRequestTransfer(
49
                $quoteTransfer,
50
                new CrefoPayApiRequestTransfer()
51
            );
52
53
        $quoteTransfer->getCrefoPayTransaction()
54
            ->setCrefoPayOrderId($requestTransfer->getCreateTransactionRequest()->getOrderID());
55
56
        $responseTransfer = $this->crefoPayApiFacade->performCreateTransactionApiCall($requestTransfer);
57
58
        if ($responseTransfer->getIsSuccess()) {
59
            $quoteTransfer = $this->addResponseDataToQuoteTransfer($quoteTransfer, $responseTransfer);
60
        }
61
62
        return $quoteTransfer;
63
    }
64
65
    /**
66
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
67
     * @param \Generated\Shared\Transfer\CrefoPayApiResponseTransfer $responseTransfer
68
     *
69
     * @return \Generated\Shared\Transfer\QuoteTransfer
70
     */
71
    protected function addResponseDataToQuoteTransfer(
72
        QuoteTransfer $quoteTransfer,
73
        CrefoPayApiResponseTransfer $responseTransfer
74
    ): QuoteTransfer {
75
        $quoteTransfer->getCrefoPayTransaction()->fromArray(
76
            $responseTransfer->getCreateTransactionResponse()->toArray(true, true),
77
            true
78
        )
79
        ->setIsSuccess($responseTransfer->getIsSuccess());
80
81
        return $quoteTransfer;
82
    }
83
}
84