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

CustomerAfterCheckoutFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createNew() 0 7 1
A createAfterCheckout() 0 13 1
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