Passed
Pull Request — feature/eco-2295/eco-2356-main... (#2)
by Aleksey
02:28 queued 01:19
created

DirectDebitSubForm::addPaymentMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type Spryker\Yves\StepEngine\...orm\AbstractSubFormType 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...
12
use Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface;
0 ignored issues
show
Bug introduced by
The type Spryker\Yves\StepEngine\...y\Form\SubFormInterface 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...
13
use Spryker\Yves\StepEngine\Dependency\Form\SubFormProviderNameInterface;
0 ignored issues
show
Bug introduced by
The type Spryker\Yves\StepEngine\...rmProviderNameInterface 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...
14
use SprykerEco\Shared\CrefoPay\CrefoPayConfig;
15
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\E...on\Core\Type\HiddenType 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...
16
use Symfony\Component\Form\Extension\Core\Type\RadioType;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\E...ion\Core\Type\RadioType 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...
17
use Symfony\Component\Form\FormBuilderInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\FormBuilderInterface 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...
18
use Symfony\Component\Form\FormInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\FormInterface 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...
19
use Symfony\Component\Form\FormView;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\FormView 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...
20
use Symfony\Component\OptionsResolver\OptionsResolver;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\OptionsResolver\OptionsResolver 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...
21
22
class DirectDebitSubForm extends AbstractSubFormType implements SubFormInterface, SubFormProviderNameInterface
23
{
24
    public const CREFO_PAY_SHOP_PUBLIC_KEY = 'shopPublicKey';
25
    public const CREFO_PAY_ORDER_ID = 'orderID';
26
    public const CREFO_PAY_SECURE_FIELDS_API_ENDPOINT = 'secureFieldsApiEndpoint';
27
    public const CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS = 'secureFieldsPlaceholders';
28
29
    protected const PAYMENT_METHOD = 'direct-debit';
30
    protected const FORM_FIELD_PAYMENT_METHOD = 'paymentMethod';
31
    protected const FORM_FIELD_PAYMENT_METHOD_DATA = 'DD';
32
    protected const FORM_FIELD_PAYMENT_METHOD_CLASSES = 'crefopay-payment-method is_hidden';
33
    protected const FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_NAME = 'data-crefopay';
34
    protected const FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_VALUE = 'paymentMethod';
35
    protected const FORM_FIELD_PAYMENT_INSTRUMENT_ID = 'paymentInstrumentId';
36
37
    /**
38
     * @return string
39
     */
40
    public function getProviderName(): string
41
    {
42
        return CrefoPayConfig::PROVIDER_NAME;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getName(): string
49
    {
50
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_DIRECT_DEBIT;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getPropertyPath(): string
57
    {
58
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_DIRECT_DEBIT;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getTemplatePath(): string
65
    {
66
        return CrefoPayConfig::PROVIDER_NAME . DIRECTORY_SEPARATOR . static::PAYMENT_METHOD;
67
    }
68
69
    /**
70
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
71
     *
72
     * @return void
73
     */
74
    public function configureOptions(OptionsResolver $resolver): void
75
    {
76
        $resolver->setDefaults([
77
            'data_class' => CrefoPayPaymentTransfer::class,
78
        ])->setRequired(static::OPTIONS_FIELD_NAME);
79
    }
80
81
    /**
82
     * @param \Symfony\Component\Form\FormView $view The view
83
     * @param \Symfony\Component\Form\FormInterface $form The form
84
     * @param array $options The options
85
     *
86
     * @return void
87
     */
88
    public function buildView(FormView $view, FormInterface $form, array $options): void
89
    {
90
        parent::buildView($view, $form, $options);
91
        $selectedOptions = $options[static::OPTIONS_FIELD_NAME];
92
        $view->vars[static::CREFO_PAY_SHOP_PUBLIC_KEY] = $selectedOptions[static::CREFO_PAY_SHOP_PUBLIC_KEY];
93
        $view->vars[static::CREFO_PAY_ORDER_ID] = $selectedOptions[static::CREFO_PAY_ORDER_ID];
94
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT];
95
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS];
96
    }
97
98
    /**
99
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
100
     * @param array $options
101
     *
102
     * @return void
103
     */
104
    public function buildForm(FormBuilderInterface $builder, array $options): void
105
    {
106
        $this->addPaymentMethod($builder)
107
            ->addPaymentInstrumentId($builder);
108
    }
109
110
    /**
111
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
112
     *
113
     * @return $this
114
     */
115
    protected function addPaymentMethod(FormBuilderInterface $builder)
116
    {
117
        $builder->add(
118
            static::FORM_FIELD_PAYMENT_METHOD,
119
            RadioType::class,
120
            [
121
                'label' => false,
122
                'value' => static::FORM_FIELD_PAYMENT_METHOD_DATA,
123
                'attr' => [
124
                    'class' => static::FORM_FIELD_PAYMENT_METHOD_CLASSES,
125
                    static::FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_NAME => static::FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_VALUE,
126
                ],
127
            ]
128
        );
129
130
        return $this;
131
    }
132
133
    /**
134
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
135
     *
136
     * @return $this
137
     */
138
    protected function addPaymentInstrumentId(FormBuilderInterface $builder)
139
    {
140
        $builder->add(
141
            static::FORM_FIELD_PAYMENT_INSTRUMENT_ID,
142
            HiddenType::class,
143
            ['label' => false]
144
        );
145
146
        return $this;
147
    }
148
}
149