EasycreditSubForm::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 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\Easycredit\Form;
9
10
use Generated\Shared\Transfer\EasycreditTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\EasycreditTransfer 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 Generated\Shared\Transfer\PaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentTransfer 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\AbstractSubFormType;
13
use Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface;
14
use Spryker\Yves\StepEngine\Dependency\Form\SubFormProviderNameInterface;
15
use SprykerEco\Shared\Easycredit\EasycreditConfig;
16
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
17
use Symfony\Component\Form\FormBuilderInterface;
18
use Symfony\Component\Form\FormInterface;
19
use Symfony\Component\Form\FormView;
20
use Symfony\Component\OptionsResolver\OptionsResolver;
21
use Symfony\Component\Validator\Constraint;
22
use Symfony\Component\Validator\Constraints\NotBlank;
23
24
class EasycreditSubForm extends AbstractSubFormType implements SubFormInterface, SubFormProviderNameInterface
25
{
26
    public const VARS_KEY_LEGAL_TEXT = 'legalText';
27
    protected const FIELD_OPT_IN_CHECKBOX = 'optInCheckbox';
28
29
    /**
30
     * @return string
31
     */
32
    public function getPropertyPath(): string
33
    {
34
        return PaymentTransfer::EASYCREDIT;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getName(): string
41
    {
42
        return PaymentTransfer::EASYCREDIT;
43
    }
44
45
    /**
46
     * @param \Symfony\Component\Form\FormView $view
47
     * @param \Symfony\Component\Form\FormInterface $form
48
     * @param array $options
49
     *
50
     * @return void
51
     */
52
    public function buildView(FormView $view, FormInterface $form, array $options): void
53
    {
54
        parent::buildView($view, $form, $options);
55
56
        $selectedOptions = $options[static::OPTIONS_FIELD_NAME];
57
        $view->vars[static::VARS_KEY_LEGAL_TEXT] = $selectedOptions[static::VARS_KEY_LEGAL_TEXT];
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    protected function getTemplatePath(): string
64
    {
65
        return EasycreditConfig::PROVIDER_NAME . '/' . EasycreditConfig::PAYMENT_METHOD;
66
    }
67
68
    /**
69
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
70
     *
71
     * @return void
72
     */
73
    public function configureOptions(OptionsResolver $resolver): void
74
    {
75
        $resolver->setDefaults([
76
            'data_class' => EasycreditTransfer::class,
77
            SubFormInterface::OPTIONS_FIELD_NAME => [],
78
        ]);
79
    }
80
81
    /**
82
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
83
     * @param array $options
84
     *
85
     * @return void
86
     */
87
    public function buildForm(FormBuilderInterface $builder, array $options): void
88
    {
89
        $this->addCreditCardPaymentOptions($builder, $options);
90
    }
91
92
    /**
93
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
94
     * @param array $options
95
     *
96
     * @return $this
97
     */
98
    public function addCreditCardPaymentOptions(FormBuilderInterface $builder, array $options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

98
    public function addCreditCardPaymentOptions(FormBuilderInterface $builder, /** @scrutinizer ignore-unused */ array $options)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
99
    {
100
        $builder->add(
101
            static::FIELD_OPT_IN_CHECKBOX,
102
            CheckboxType::class,
103
            [
104
                'label' => '',
105
                'required' => true,
106
                'constraints' => [
107
                    $this->createNotBlankConstraint(),
108
                ],
109
            ]
110
        );
111
112
        return $this;
113
    }
114
115
    /**
116
     * @return \Symfony\Component\Validator\Constraint
117
     */
118
    protected function createNotBlankConstraint(): Constraint
119
    {
120
        return new NotBlank(['groups' => $this->getPropertyPath()]);
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public function getProviderName(): string
127
    {
128
        return PaymentTransfer::EASYCREDIT;
129
    }
130
}
131