Completed
Push — master ( e98215...11a2d8 )
by Adam
05:41
created

ExchangeOptions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 12 1
A renderJs() 0 13 1
A getJavascriptType() 0 4 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Component\Form\Dependencies;
14
15
use Symfony\Component\OptionsResolver\OptionsResolver;
16
use WellCommerce\Component\Form\Elements\ElementInterface;
17
use WellCommerce\Component\Form\Elements\Form;
18
19
/**
20
 * Class ExchangeOptions
21
 *
22
 * @author  Adam Piotrowski <[email protected]>
23
 */
24
class ExchangeOptions extends AbstractDependency
25
{
26
    
27
    public function configureOptions(OptionsResolver $resolver)
28
    {
29
        $resolver->setRequired([
30
            'field',
31
            'form',
32
            'load_options_route',
33
        ]);
34
        
35
        $resolver->setAllowedTypes('field', ElementInterface::class);
36
        $resolver->setAllowedTypes('form', Form::class);
37
        $resolver->setAllowedTypes('load_options_route', 'string');
38
    }
39
    
40
    public function renderJs()
41
    {
42
        $javascriptType = $this->getJavascriptType();
43
        $fieldName      = $this->getField()->getName();
44
        $formName       = $this->getForm()->getName();
45
        
46
        return sprintf("new GFormDependency(GFormDependency.%s, '%s.%s', '%s')",
47
            $javascriptType,
48
            $formName,
49
            $fieldName,
50
            $this->options['load_options_route']
51
        );
52
    }
53
    
54
    public function getJavascriptType()
55
    {
56
        return 'EXCHANGE_OPTIONS';
57
    }
58
}
59