Passed
Push — feature/eco-2295/eco-2356-main... ( 8009c8...d55ff2 )
by Aleksey
01:22
created

PayPalSubForm::buildView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 3
dl 0
loc 8
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\ChoiceType;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\E...on\Core\Type\ChoiceType 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\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...
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 PayPalSubForm 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 = 'paypal';
30
    protected const FORM_FIELD_PAYMENT_METHOD = 'paymentMethod';
31
    protected const FORM_FIELD_PAYMENT_METHOD_DATA = 'PAYPAL';
32
33
    /**
34
     * @return string
35
     */
36
    public function getProviderName(): string
37
    {
38
        return CrefoPayConfig::PROVIDER_NAME;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getName(): string
45
    {
46
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_PAY_PAL;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getPropertyPath(): string
53
    {
54
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_PAY_PAL;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getTemplatePath(): string
61
    {
62
        return CrefoPayConfig::PROVIDER_NAME . DIRECTORY_SEPARATOR . static::PAYMENT_METHOD;
63
    }
64
65
    /**
66
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
67
     *
68
     * @return void
69
     */
70
    public function configureOptions(OptionsResolver $resolver): void
71
    {
72
        $resolver->setDefaults([
73
            'data_class' => CrefoPayPaymentTransfer::class,
74
        ])->setRequired(static::OPTIONS_FIELD_NAME);
75
    }
76
77
    /**
78
     * @param \Symfony\Component\Form\FormView $view The view
79
     * @param \Symfony\Component\Form\FormInterface $form The form
80
     * @param array $options The options
81
     *
82
     * @return void
83
     */
84
    public function buildView(FormView $view, FormInterface $form, array $options): void
85
    {
86
        parent::buildView($view, $form, $options);
87
        $selectedOptions = $options[static::OPTIONS_FIELD_NAME];
88
        $view->vars[static::CREFO_PAY_SHOP_PUBLIC_KEY] = $selectedOptions[static::CREFO_PAY_SHOP_PUBLIC_KEY];
89
        $view->vars[static::CREFO_PAY_ORDER_ID] = $selectedOptions[static::CREFO_PAY_ORDER_ID];
90
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT];
91
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS];
92
    }
93
94
    /**
95
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
96
     * @param array $options
97
     *
98
     * @return void
99
     */
100
    public function buildForm(FormBuilderInterface $builder, array $options): void
101
    {
102
        $this->addPaymentMethod($builder);
103
    }
104
105
    /**
106
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
107
     *
108
     * @return $this
109
     */
110
    protected function addPaymentMethod(FormBuilderInterface $builder)
111
    {
112
        $builder->add(
113
            static::FORM_FIELD_PAYMENT_METHOD,
114
            ChoiceType::class,
115
            [
116
                'choices' => [static::FORM_FIELD_PAYMENT_METHOD_DATA],
117
                'choices_as_values' => true,
118
                'expanded' => true,
119
            ]
120
        );
121
122
        return $this;
123
    }
124
}
125