Completed
Push — master ( 6b086b...7ffeec )
by Łukasz
02:25
created

CustomerViewFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Factory;
6
7
use Sylius\Component\Core\Model\CustomerInterface;
8
use Sylius\ShopApiPlugin\View\CustomerView;
9
10
final class CustomerViewFactory implements CustomerViewFactoryInterface
11
{
12
    /** @var string */
13
    private $customerViewClass;
14
15
    public function __construct(string $customerViewClass)
16
    {
17
        $this->customerViewClass = $customerViewClass;
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function create(CustomerInterface $customer): CustomerView
24
    {
25
        /** @var CustomerView $customerView */
26
        $customerView = new $this->customerViewClass();
27
28
        $customerView->id = $customer->getId();
29
        $customerView->firstName = $customer->getFirstName();
30
        $customerView->lastName = $customer->getLastName();
31
        $customerView->email = $customer->getEmail();
32
        $customerView->birthday = $customer->getBirthday();
33
        $customerView->gender = $customer->getGender();
34
        $customerView->phoneNumber = $customer->getPhoneNumber();
35
        $customerView->subscribedToNewsletter = $customer->isSubscribedToNewsletter();
36
37
        return $customerView;
38
    }
39
}
40