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

CreditCard3DSubForm::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 CreditCard3DSubForm 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_LIBRARY_URL = 'secureFieldsLibraryUrl';
28
    public const CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS = 'secureFieldsPlaceholders';
29
30
    protected const PAYMENT_METHOD = 'credit-card-3d';
31
    protected const FORM_FIELD_PAYMENT_METHOD = 'paymentMethod';
32
    protected const FORM_FIELD_PAYMENT_METHOD_DATA = 'CC3D';
33
    protected const FORM_FIELD_PAYMENT_METHOD_CLASSES = 'crefopay-payment-method is_hidden';
34
    protected const FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_NAME = 'data-crefopay';
35
    protected const FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_VALUE = 'paymentMethod';
36
    protected const FORM_FIELD_PAYMENT_INSTRUMENT_ID = 'paymentInstrumentId';
37
38
    /**
39
     * @return string
40
     */
41
    public function getProviderName(): string
42
    {
43
        return CrefoPayConfig::PROVIDER_NAME;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getName(): string
50
    {
51
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_CREDIT_CARD_3D;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getPropertyPath(): string
58
    {
59
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_CREDIT_CARD_3D;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getTemplatePath(): string
66
    {
67
        return CrefoPayConfig::PROVIDER_NAME . DIRECTORY_SEPARATOR . static::PAYMENT_METHOD;
68
    }
69
70
    /**
71
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
72
     *
73
     * @return void
74
     */
75
    public function configureOptions(OptionsResolver $resolver): void
76
    {
77
        $resolver->setDefaults([
78
            'data_class' => CrefoPayPaymentTransfer::class,
79
        ])->setRequired(static::OPTIONS_FIELD_NAME);
80
    }
81
82
    /**
83
     * @param \Symfony\Component\Form\FormView $view The view
84
     * @param \Symfony\Component\Form\FormInterface $form The form
85
     * @param array $options The options
86
     *
87
     * @return void
88
     */
89
    public function buildView(FormView $view, FormInterface $form, array $options): void
90
    {
91
        parent::buildView($view, $form, $options);
92
        $selectedOptions = $options[static::OPTIONS_FIELD_NAME];
93
        $view->vars[static::CREFO_PAY_SHOP_PUBLIC_KEY] = $selectedOptions[static::CREFO_PAY_SHOP_PUBLIC_KEY];
94
        $view->vars[static::CREFO_PAY_ORDER_ID] = $selectedOptions[static::CREFO_PAY_ORDER_ID];
95
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT];
96
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS];
97
    }
98
99
    /**
100
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
101
     * @param array $options
102
     *
103
     * @return void
104
     */
105
    public function buildForm(FormBuilderInterface $builder, array $options): void
106
    {
107
        $this->addPaymentMethod($builder)
108
            ->addPaymentInstrumentId($builder);
109
    }
110
111
    /**
112
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
113
     *
114
     * @return $this
115
     */
116
    protected function addPaymentMethod(FormBuilderInterface $builder)
117
    {
118
        $builder->add(
119
            static::FORM_FIELD_PAYMENT_METHOD,
120
            RadioType::class,
121
            [
122
                'label' => false,
123
                'value' => static::FORM_FIELD_PAYMENT_METHOD_DATA,
124
                'attr' => [
125
                    'class' => static::FORM_FIELD_PAYMENT_METHOD_CLASSES,
126
                    static::FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_NAME => static::FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_VALUE,
127
                ],
128
            ]
129
        );
130
131
        return $this;
132
    }
133
134
    /**
135
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
136
     *
137
     * @return $this
138
     */
139
    protected function addPaymentInstrumentId(FormBuilderInterface $builder)
140
    {
141
        $builder->add(
142
            static::FORM_FIELD_PAYMENT_INSTRUMENT_ID,
143
            HiddenType::class,
144
            ['label' => false]
145
        );
146
147
        return $this;
148
    }
149
}
150