Completed
Push — feature/eco-1539-heidelpay-eas... ( d0263f...a6169c )
by Ruslan
05:09 queued 05:01
created

EasyCreditSubForm::createNotBlankConstraint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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\Heidelpay\Form;
9
10
use Generated\Shared\Transfer\HeidelpayEasyCreditPaymentTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...syCreditPaymentTransfer 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;
1 ignored issue
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\SubFormInterface;
13
use SprykerEco\Shared\Heidelpay\HeidelpayConfig;
14
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
15
use Symfony\Component\Form\FormBuilderInterface;
16
use Symfony\Component\Form\FormInterface;
17
use Symfony\Component\Form\FormView;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
use Symfony\Component\Validator\Constraint;
20
use Symfony\Component\Validator\Constraints\NotBlank;
21
22
class EasyCreditSubForm extends AbstractHeidelpaySubForm
23
{
24
    public const PAYMENT_METHOD = HeidelpayConfig::PAYMENT_METHOD_EASY_CREDIT;
25
    public const PAYMENT_METHOD_TEMPLATE_PATH = 'easy-credit';
26
    public const VARS_KEY_LEGAL_TEXT = 'legalText';
27
    public const VARS_KEY_LOGO_URL = 'logo_url';
28
    public const VARS_KEY_INFO_LINK = 'info_link';
29
30
    protected const FIELD_EASY_CREDIT_POLICY_AGREEMENT = 'isPolicyAgreementChecked';
31
32
33
    /**
34
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
35
     *
36
     * @return void
37
     */
38
    public function configureOptions(OptionsResolver $resolver): void
39
    {
40
        $resolver->setDefaults([
41
            'data_class' => HeidelpayEasyCreditPaymentTransfer::class,
42
            SubFormInterface::OPTIONS_FIELD_NAME => [],
43
        ]);
44
    }
45
46
    /**
47
     * @param \Symfony\Component\Form\FormView $view
48
     * @param \Symfony\Component\Form\FormInterface $form
49
     * @param array $options
50
     *
51
     * @return void
52
     */
53
    public function buildView(FormView $view, FormInterface $form, array $options): void
54
    {
55
        parent::buildView($view, $form, $options);
56
57
        $view->vars[static::VARS_KEY_LOGO_URL] = $options[static::OPTIONS_FIELD_NAME][static::VARS_KEY_LOGO_URL] ?? '';
58
        $view->vars[static::VARS_KEY_INFO_LINK] = $options[static::OPTIONS_FIELD_NAME][static::VARS_KEY_INFO_LINK] ?? '';
59
    }
60
61
    /**
62
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
63
     * @param array $options
64
     *
65
     * @return void
66
     */
67
    public function buildForm(FormBuilderInterface $builder, array $options): void
68
    {
69
        $this->addEasyCreditPaymentAgreement($builder, $options);
70
    }
71
72
    /**
73
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
74
     * @param array $options
75
     *
76
     * @return $this
77
     */
78
    public function addEasyCreditPaymentAgreement(FormBuilderInterface $builder, array $options)
79
    {
80
        $builder->add(
81
            static::FIELD_EASY_CREDIT_POLICY_AGREEMENT,
82
            CheckboxType::class,
83
            [
84
                'label' => $options[static::OPTIONS_FIELD_NAME][static::VARS_KEY_LEGAL_TEXT] ?? '',
85
                'constraints' => [
86
                    $this->createNotBlankConstraint(),
87
                ],
88
            ]
89
        );
90
91
        return $this;
92
    }
93
94
    /**
95
     * @return \Symfony\Component\Validator\Constraint
96
     */
97
    protected function createNotBlankConstraint(): Constraint
98
    {
99
        return new NotBlank(['groups' => $this->getPropertyPath()]);
100
    }
101
}
102