CustomerSimpleRegistrationType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A buildForm() 0 14 1
A configureOptions() 0 7 1
A getBlockPrefix() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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
namespace App\Form\Type\Customer;
13
14
use App\Form\EventSubscriber\CustomerRegistrationFormSubscriber;
15
use App\Form\Type\User\AppUserRegistrationType;
16
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
17
use Sylius\Component\Resource\Repository\RepositoryInterface;
18
use Symfony\Component\Form\Extension\Core\Type\EmailType;
19
use Symfony\Component\Form\FormBuilderInterface;
20
use Symfony\Component\OptionsResolver\OptionsResolver;
21
use Symfony\Component\Validator\Constraints\Valid;
22
23
class CustomerSimpleRegistrationType extends AbstractResourceType
24
{
25
    /**
26
     * @var RepositoryInterface
27
     */
28
    private $customerRepository;
29
30
    /**
31
     * @param string              $dataClass
32
     * @param array               $validationGroups
33
     * @param RepositoryInterface $customerRepository
34
     */
35
    public function __construct($dataClass, array $validationGroups, RepositoryInterface $customerRepository)
36
    {
37
        parent::__construct($dataClass, $validationGroups);
38
39
        $this->customerRepository = $customerRepository;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function buildForm(FormBuilderInterface $builder, array $options = [])
46
    {
47
        $builder
48
            ->add('email', EmailType::class, [
49
                'label' => 'sylius.form.customer.email',
50
            ])
51
            ->add('user', AppUserRegistrationType::class, [
52
                'label' => false,
53
                'constraints' => [new Valid()],
54
            ])
55
            ->addEventSubscriber(new CustomerRegistrationFormSubscriber($this->customerRepository))
56
            ->setDataLocked(false)
57
        ;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function configureOptions(OptionsResolver $resolver): void
64
    {
65
        $resolver->setDefaults([
66
            'data_class' => $this->dataClass,
67
            'validation_groups' => $this->validationGroups,
68
        ]);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getBlockPrefix()
75
    {
76
        return 'sylius_customer_simple_registration';
77
    }
78
}
79