Completed
Push — symfony-flex ( 2a70a0 )
by Kamil
26:10 queued 12:40
created

CustomerAfterCheckoutFactory::createNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Component\Core\Factory;
15
16
use Sylius\Component\Core\Model\CustomerInterface;
17
use Sylius\Component\Core\Model\OrderInterface;
18
use Sylius\Component\Resource\Factory\FactoryInterface;
19
20
final class CustomerAfterCheckoutFactory implements CustomerAfterCheckoutFactoryInterface
21
{
22
    /** @var FactoryInterface */
23
    private $baseCustomerFactory;
24
25
    public function __construct(FactoryInterface $baseCustomerFactory)
26
    {
27
        $this->baseCustomerFactory = $baseCustomerFactory;
28
    }
29
30
    public function createNew(): CustomerInterface
31
    {
32
        /** @var CustomerInterface $customer */
33
        $customer = $this->baseCustomerFactory->createNew();
34
35
        return $customer;
36
    }
37
38
    public function createAfterCheckout(OrderInterface $order): CustomerInterface
39
    {
40
        $guest = $order->getCustomer();
41
        $address = $order->getBillingAddress();
42
43
        $customer = $this->createNew();
44
        $customer->setEmail($guest->getEmail());
45
        $customer->setFirstName($address->getFirstName());
46
        $customer->setLastName($address->getLastName());
47
        $customer->setPhoneNumber($address->getPhoneNumber());
48
49
        return $customer;
50
    }
51
}
52