Passed
Pull Request — master (#4)
by Aleksey
15:10 queued 11:37
created

BillSubForm   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 101
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A addPaymentMethod() 0 13 1
A getPropertyPath() 0 3 1
A buildForm() 0 3 1
A getProviderName() 0 3 1
A buildView() 0 8 1
A configureOptions() 0 5 1
A getTemplatePath() 0 3 1
A getName() 0 3 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\CrefoPay\Form;
9
10
use Generated\Shared\Transfer\CrefoPayPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CrefoPayPaymentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Spryker\Yves\StepEngine\Dependency\Form\AbstractSubFormType;
12
use Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface;
13
use Spryker\Yves\StepEngine\Dependency\Form\SubFormProviderNameInterface;
14
use SprykerEco\Shared\CrefoPay\CrefoPayConfig;
15
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
16
use Symfony\Component\Form\FormBuilderInterface;
17
use Symfony\Component\Form\FormInterface;
18
use Symfony\Component\Form\FormView;
19
use Symfony\Component\OptionsResolver\OptionsResolver;
20
21
class BillSubForm extends AbstractSubFormType implements SubFormInterface, SubFormProviderNameInterface
22
{
23
    public const CREFO_PAY_SHOP_PUBLIC_KEY = 'shopPublicKey';
24
    public const CREFO_PAY_ORDER_ID = 'orderID';
25
    public const CREFO_PAY_SECURE_FIELDS_API_ENDPOINT = 'secureFieldsApiEndpoint';
26
    public const CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS = 'secureFieldsPlaceholders';
27
28
    protected const PAYMENT_METHOD = 'bill';
29
    protected const FORM_FIELD_PAYMENT_METHOD = 'paymentMethod';
30
    protected const FORM_FIELD_PAYMENT_METHOD_DATA = 'BILL';
31
32
    /**
33
     * @return string
34
     */
35
    public function getProviderName(): string
36
    {
37
        return CrefoPayConfig::PROVIDER_NAME;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getName(): string
44
    {
45
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_BILL;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getPropertyPath(): string
52
    {
53
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_BILL;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getTemplatePath(): string
60
    {
61
        return CrefoPayConfig::PROVIDER_NAME . DIRECTORY_SEPARATOR . static::PAYMENT_METHOD;
62
    }
63
64
    /**
65
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
66
     *
67
     * @return void
68
     */
69
    public function configureOptions(OptionsResolver $resolver): void
70
    {
71
        $resolver->setDefaults([
72
            'data_class' => CrefoPayPaymentTransfer::class,
73
        ])->setRequired(static::OPTIONS_FIELD_NAME);
74
    }
75
76
    /**
77
     * @param \Symfony\Component\Form\FormView $view The view
78
     * @param \Symfony\Component\Form\FormInterface $form The form
79
     * @param array $options The options
80
     *
81
     * @return void
82
     */
83
    public function buildView(FormView $view, FormInterface $form, array $options): void
84
    {
85
        parent::buildView($view, $form, $options);
86
        $selectedOptions = $options[static::OPTIONS_FIELD_NAME];
87
        $view->vars[static::CREFO_PAY_SHOP_PUBLIC_KEY] = $selectedOptions[static::CREFO_PAY_SHOP_PUBLIC_KEY];
88
        $view->vars[static::CREFO_PAY_ORDER_ID] = $selectedOptions[static::CREFO_PAY_ORDER_ID];
89
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT];
90
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS];
91
    }
92
93
    /**
94
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
95
     * @param array $options
96
     *
97
     * @return void
98
     */
99
    public function buildForm(FormBuilderInterface $builder, array $options): void
100
    {
101
        $this->addPaymentMethod($builder);
102
    }
103
104
    /**
105
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
106
     *
107
     * @return $this
108
     */
109
    protected function addPaymentMethod(FormBuilderInterface $builder)
110
    {
111
        $builder->add(
112
            static::FORM_FIELD_PAYMENT_METHOD,
113
            ChoiceType::class,
114
            [
115
                'choices' => [static::FORM_FIELD_PAYMENT_METHOD_DATA],
116
                'choices_as_values' => true,
117
                'expanded' => true,
118
            ]
119
        );
120
121
        return $this;
122
    }
123
}
124