Passed
Push — feature/eco-3656/eco-3658-enab... ( da021b...202423 )
by
unknown
04:29
created

ComputopQuoteDefaultShipmentExpander   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 11
c 1
b 0
f 0
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A expandQuoteWithDefaultShippingMethod() 0 7 3
A quoteAlreadyHasShipment() 0 11 3
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\Computop;
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
12
class ComputopQuoteDefaultShipmentExpander implements ComputopQuoteDefaultShipmentExpanderInterface
13
{
14
    /**
15
     * @var \SprykerEco\Client\Computop\ComputopClientInterface
16
     */
17
    protected $computopClient;
18
19
    /**
20
     * @param \SprykerEco\Client\Computop\ComputopClientInterface $computopClient
21
     */
22
    public function __construct(ComputopClientInterface $computopClient)
23
    {
24
        $this->computopClient = $computopClient;
25
    }
26
27
    /**
28
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
29
     *
30
     * @return \Generated\Shared\Transfer\QuoteTransfer
31
     */
32
    public function expandQuoteWithDefaultShippingMethod(QuoteTransfer $quoteTransfer): QuoteTransfer
33
    {
34
        if (count($quoteTransfer->getItems()) === 0 || $this->quoteAlreadyHasShipment($quoteTransfer)) {
35
            return $quoteTransfer;
36
        }
37
38
        return $this->computopClient->expandQuoteWithDefaultShippingMethod($quoteTransfer);
39
    }
40
41
    /**
42
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
43
     *
44
     * @return bool
45
     */
46
    protected function quoteAlreadyHasShipment(QuoteTransfer $quoteTransfer): bool
47
    {
48
        foreach ($quoteTransfer->getItems() as $itemTransfer) {
49
            $itemShipmentTransfer = $itemTransfer->getShipment();
50
            if ($itemShipmentTransfer !== null) {
51
                //at least one item already has shipment method
52
                return true;
53
            }
54
        }
55
56
        return false;
57
    }
58
}
59