Passed
Push — feature/ECO-807-travis-ci ( 7b7181...a6fc91 )
by Andrey
03:17
created

CustomerDataQuoteUpdater::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 9
rs 9.6666
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\Business\Quote;
9
10
use Generated\Shared\Transfer\CustomerTransfer;
11
use Generated\Shared\Transfer\QuoteTransfer;
12
13
class CustomerDataQuoteUpdater extends QuoteUpdaterAbstract
14
{
15
16
    /**
17
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
18
     *
19
     * @return \Generated\Shared\Transfer\QuoteTransfer
20
     */
21
    public function update(QuoteTransfer $quoteTransfer)
22
    {
23
        $amazonCallTransfer = $this->convertQuoteTransferToAmazonPayTransfer($quoteTransfer);
24
        /** @var \Generated\Shared\Transfer\CustomerTransfer $customer */
25
        $customer = $this->executionAdapter->call($amazonCallTransfer);
26
27
        $this->updateCustomer($quoteTransfer, $customer);
28
29
        return $quoteTransfer;
30
    }
31
32
    /**
33
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
34
     * @param \Generated\Shared\Transfer\CustomerTransfer $customer
35
     *
36
     * @return void
37
     */
38
    protected function updateCustomer(QuoteTransfer $quoteTransfer, CustomerTransfer $customer)
39
    {
40
        if (!$quoteTransfer->getCustomer()) {
41
            $quoteTransfer->setCustomer($customer);
42
43
            return;
44
        }
45
46
        $quoteTransfer->getCustomer()->fromArray($customer->modifiedToArray());
47
48
        if ($quoteTransfer->getCustomer()->getIdCustomer()) {
49
            $quoteTransfer->getCustomer()->setIsGuest(false);
50
        }
51
    }
52
53
}
54