AmazonPayToShipmentBridge::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Apache OSL-2
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\AmazonPay\Dependency\Facade;
9
10
use Generated\Shared\Transfer\AddressTransfer;
11
use Generated\Shared\Transfer\QuoteTransfer;
12
use Generated\Shared\Transfer\ShipmentTransfer;
13
use RuntimeException;
14
15
class AmazonPayToShipmentBridge implements AmazonPayToShipmentInterface
16
{
17
    /**
18
     * @var \Spryker\Zed\Shipment\Business\ShipmentFacadeInterface
19
     */
20
    protected $shipmentFacade;
21
22
    /**
23
     * @param \Spryker\Zed\Shipment\Business\ShipmentFacadeInterface $shipmentFacade
24
     */
25
    public function __construct($shipmentFacade)
26
    {
27
        $this->shipmentFacade = $shipmentFacade;
28
    }
29
30
    /**
31
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
32
     *
33
     * @throws \RuntimeException
34
     *
35
     * @return \Generated\Shared\Transfer\ShipmentMethodsTransfer
36
     */
37
    public function getAvailableShipmentMethods(QuoteTransfer $quoteTransfer)
38
    {
39
        if (method_exists($this->shipmentFacade, 'getAvailableMethodsByShipment') === true) {
40
            foreach ($quoteTransfer->getItems() as $itemTransfer) {
41
                $itemTransfer->setShipment(new ShipmentTransfer());
42
                $itemTransfer->getShipment()->setShippingAddress(new AddressTransfer());
43
            }
44
45
            $shipmentMethodsCollectionTransfer = $this->shipmentFacade->getAvailableMethodsByShipment($quoteTransfer);
46
47
            if ($shipmentMethodsCollectionTransfer->getShipmentMethods()->count() > 1) {
48
                throw new RuntimeException('Split shipping is not supported');
49
            }
50
51
            foreach ($quoteTransfer->getItems() as $itemTransfer) {
52
                $itemTransfer->setShipment(null);
53
            }
54
55
            $shipmentMethodsTransfer = $shipmentMethodsCollectionTransfer->getShipmentMethods()->getIterator()
56
                ->current();
57
58
            return $shipmentMethodsTransfer;
59
        }
60
61
        return $this->shipmentFacade->getAvailableMethods($quoteTransfer);
0 ignored issues
show
Bug introduced by
The method getAvailableMethods() does not exist on Spryker\Zed\Shipment\Bus...ShipmentFacadeInterface. Did you maybe mean getAvailableMethodsByShipment()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
        return $this->shipmentFacade->/** @scrutinizer ignore-call */ getAvailableMethods($quoteTransfer);

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...
62
    }
63
}
64