Passed
Pull Request — master (#9)
by Volodymyr
17:33 queued 09:33
created

CheckoutShipmentForm   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 3 1
A getBlockPrefix() 0 3 1
A buildForm() 0 5 1
A addIdShipmentMethod() 0 13 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Yves\Braintree\Form;
9
10
use Spryker\Yves\Kernel\Form\AbstractType;
11
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
12
use Symfony\Component\Form\FormBuilderInterface;
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
use Symfony\Component\Validator\Constraints\NotBlank;
15
16
/**
17
 * @method \SprykerEco\Yves\Braintree\BraintreeConfig getConfig()
18
 */
19
class CheckoutShipmentForm extends AbstractType
20
{
21
    public const FIELD_ID_SHIPMENT_METHOD = 'idShipmentMethod';
22
    public const OPTION_SHIPMENT_METHODS = 'shipmentMethods';
23
24
    public const SHIPMENT_PROPERTY_PATH = 'shipment';
25
    public const SHIPMENT_SELECTION = 'shipmentSelection';
26
    public const SHIPMENT_SELECTION_PROPERTY_PATH = self::SHIPMENT_PROPERTY_PATH . '.' . self::SHIPMENT_SELECTION;
27
28
    protected const VALIDATION_NOT_BLANK_MESSAGE = 'validation.not_blank';
29
30
    public const FORM_NAME = 'checkoutShipmentForm';
31
32
    /**
33
     * @return string
34
     */
35
    public function getBlockPrefix()
36
    {
37
        return static::FORM_NAME;
38
    }
39
40
    /**
41
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
42
     * @param array $options
43
     *
44
     * @return void
45
     */
46
    public function buildForm(FormBuilderInterface $builder, array $options): void
47
    {
48
        $builder->setAction('/test');
49
50
        $this->addIdShipmentMethod($builder, $options);
51
    }
52
53
    /**
54
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
55
     * @param array $options
56
     *
57
     * @return void
58
     */
59
    protected function addIdShipmentMethod(FormBuilderInterface $builder, array $options): void
60
    {
61
        $builder->add(self::FIELD_ID_SHIPMENT_METHOD, ChoiceType::class, [
62
            'choices' => $options[self::OPTION_SHIPMENT_METHODS],
63
            'expanded' => true,
64
            'multiple' => false,
65
            'required' => true,
66
            'property_path' => static::SHIPMENT_SELECTION_PROPERTY_PATH,
67
            'placeholder' => false,
68
            'constraints' => [
69
                new NotBlank(),
70
            ],
71
            'label' => false,
72
        ]);
73
    }
74
75
    /**
76
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
77
     *
78
     * @return void
79
     */
80
    public function configureOptions(OptionsResolver $resolver)
81
    {
82
        $resolver->setRequired('shipmentMethods');
83
    }
84
}
85