Passed
Pull Request — master (#9)
by Volodymyr
05:00
created

QuoteExpander   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A expandQuoteWithShipmentMethod() 0 12 1
A __construct() 0 8 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\Yves\Braintree\Model\QuoteExpander;
9
10
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...
11
use Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginInterface;
12
use SprykerEco\Yves\Braintree\Dependency\Client\BraintreeToCalculationClientInterface;
13
use SprykerEco\Yves\Braintree\Dependency\Client\BraintreeToPriceClientInterface;
14
use SprykerEco\Yves\Braintree\Dependency\Client\BraintreeToQuoteClientInterface;
15
use Symfony\Component\HttpFoundation\Request;
16
17
class QuoteExpander implements QuoteExpanderInterface
18
{
19
    /**
20
     * @var \SprykerEco\Yves\Braintree\Dependency\Client\BraintreeToQuoteClientInterface
21
     */
22
    public $quoteClient;
23
24
    /**
25
     * @var \SprykerEco\Yves\Braintree\Dependency\Client\BraintreeToCalculationClientInterface
26
     */
27
    public $calculationClient;
28
29
    /**
30
     * @var StepHandlerPluginInterface
31
     */
32
    public $shipmentHandlerPlugin;
33
34
    /**
35
     * @param \SprykerEco\Yves\Braintree\Dependency\Client\BraintreeToQuoteClientInterface $quoteClient
36
     * @param \SprykerEco\Yves\Braintree\Dependency\Client\BraintreeToCalculationClientInterface $calculationClient
37
     * @param StepHandlerPluginInterface $shipmentHandlerPlugin
38
     */
39
    public function __construct(
40
        BraintreeToQuoteClientInterface $quoteClient,
41
        BraintreeToCalculationClientInterface $calculationClient,
42
        StepHandlerPluginInterface $shipmentHandlerPlugin
43
    ) {
44
        $this->quoteClient = $quoteClient;
45
        $this->calculationClient = $calculationClient;
46
        $this->shipmentHandlerPlugin = $shipmentHandlerPlugin;
47
    }
48
49
    /**
50
     * @param Request $request
51
     * @param int $idShipmentMethod
52
     *
53
     * @return \Generated\Shared\Transfer\QuoteTransfer
54
     */
55
    public function expandQuoteWithShipmentMethod(Request $request, int $idShipmentMethod): QuoteTransfer
56
    {
57
        $quoteClient = $this->quoteClient;
58
59
        $quoteTransfer = $quoteClient->getQuote();
60
        $quoteTransfer->getShipment()->setShipmentSelection($idShipmentMethod);
61
        $quoteTransfer = $this->shipmentHandlerPlugin->addToDataClass($request, $quoteTransfer);
62
        $quoteTransfer = $this->calculationClient->recalculate($quoteTransfer);
63
64
        $quoteClient->setQuote($quoteTransfer);
65
66
        return $quoteTransfer;
67
    }
68
}
69