PayPalSubForm::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
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\Braintree\Form;
9
10
use Generated\Shared\Transfer\BraintreePaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\BraintreePaymentTransfer 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\Shared\Config\Config;
12
use Spryker\Shared\Kernel\Store;
13
use SprykerEco\Shared\Braintree\BraintreeConfig;
14
use SprykerEco\Shared\Braintree\BraintreeConstants;
15
use Symfony\Component\Form\FormInterface;
16
use Symfony\Component\Form\FormView;
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
class PayPalSubForm extends AbstractSubForm
20
{
21
    public const PAYMENT_METHOD = 'pay-pal';
22
23
    public const ENV = 'env';
24
    public const CLIENT_TOKEN = 'clientToken';
25
    public const AMOUNT = 'amount';
26
    public const CURRENCY = 'currency';
27
    public const LOCALE = 'locale';
28
29
    /**
30
     * @return string
31
     */
32
    public function getName()
33
    {
34
        return BraintreeConfig::PAYMENT_METHOD_PAY_PAL;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getPropertyPath()
41
    {
42
        return BraintreeConfig::PAYMENT_METHOD_PAY_PAL;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getTemplatePath()
49
    {
50
        return BraintreeConfig::PROVIDER_NAME . '/' . static::PAYMENT_METHOD;
51
    }
52
53
    /**
54
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
55
     *
56
     * @return void
57
     */
58
    public function configureOptions(OptionsResolver $resolver): void
59
    {
60
        $resolver->setDefaults([
61
            'data_class' => BraintreePaymentTransfer::class,
62
        ])->setRequired(static::OPTIONS_FIELD_NAME);
63
    }
64
65
    /**
66
     * @param \Symfony\Component\Form\FormView $view The view
67
     * @param \Symfony\Component\Form\FormInterface $form The form
68
     * @param array $options The options
69
     *
70
     * @return void
71
     */
72
    public function buildView(FormView $view, FormInterface $form, array $options)
73
    {
74
        parent::buildView($view, $form, $options);
75
76
        /** @var \Generated\Shared\Transfer\QuoteTransfer $quote */
77
        $quote = $form->getParent()->getViewData();
78
79
        $view->vars[static::ENV] = Config::get(BraintreeConstants::ENVIRONMENT);
80
        $view->vars[static::CLIENT_TOKEN] = $this->generateClientToken();
81
        $view->vars[static::AMOUNT] = $quote->getTotals()->getGrandTotal();
82
        $view->vars[static::CURRENCY] = $quote->getCurrency()->getCode();
83
        $view->vars[static::LOCALE] = Store::getInstance()->getCurrentLocale();
84
    }
85
}
86