Passed
Push — feature/eco-2300/crefopay-cred... ( 3c5e73...5287a1 )
by Aleksey
01:15
created

DirectDebitSubForm::addPaymentMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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