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

UpdateCustomerHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Handler;
6
7
use Sylius\Component\Core\Model\CustomerInterface;
8
use Sylius\Component\Resource\Repository\RepositoryInterface;
9
use Sylius\ShopApiPlugin\Command\UpdateCustomer;
10
11
final class UpdateCustomerHandler
12
{
13
    /** @var RepositoryInterface */
14
    private $customerRepository;
15
16
    public function __construct(
17
        RepositoryInterface $customerRepository
18
    ) {
19
        $this->customerRepository = $customerRepository;
20
    }
21
22
    public function handle(UpdateCustomer $command): void
23
    {
24
        /** @var CustomerInterface $customer */
25
        $customer = $this->customerRepository->findOneBy(['email' => $command->email()]);
26
27
        $customer->setFirstName($command->firstName());
28
        $customer->setLastName($command->lastName());
29
        $customer->setEmail($command->email());
30
        $customer->setGender($command->gender());
31
        $customer->setBirthday(new \DateTimeImmutable($command->birthday()));
32
        $customer->setPhoneNumber($command->phoneNumber());
33
        $customer->setSubscribedToNewsletter($command->subscribedToNewsletter());
34
35
        $this->customerRepository->add($customer);
36
    }
37
}
38