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

UpdateCustomerHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 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