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\Yves\AmazonPay\Dependency\Client;
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\Client\Shipment\ShipmentClientInterface
19
     */
20
    protected $shipmentClient;
21
22
    /**
23
     * @param \Spryker\Client\Shipment\ShipmentClientInterface $shipmentClient
24
     */
25
    public function __construct($shipmentClient)
26
    {
27
        $this->shipmentClient = $shipmentClient;
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 getAvailableMethods(QuoteTransfer $quoteTransfer)
38
    {
39
        if (method_exists($this->shipmentClient, 'getAvailableMethodsByShipment') === true) {
40
            foreach ($quoteTransfer->getItems() as $itemTransfer) {
41
                $itemTransfer->setShipment(new ShipmentTransfer());
42
                $itemTransfer->getShipment()->setShippingAddress(new AddressTransfer());
43
            }
44
45
            $shipmentMethodsCollectionTransfer = $this->shipmentClient->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
56
                ->getShipmentMethods()
57
                ->getIterator()
58
                ->current();
59
60
            return $shipmentMethodsTransfer;
61
        }
62
63
        return $this->shipmentClient->getAvailableMethods($quoteTransfer);
0 ignored issues
show
Bug introduced by
The method getAvailableMethods() does not exist on Spryker\Client\Shipment\ShipmentClientInterface. 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

63
        return $this->shipmentClient->/** @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...
64
    }
65
}
66