Completed
Pull Request — master (#2)
by
unknown
04:55
created

AddCasesRequestConfiguration   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 59 1
1
<?php
2
namespace OmnideskBundle\Configuration\Cases;
3
4
use OmnideskBundle\Model\Cases;
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * Class AddCasesRequestConfiguration
10
 * @package OmnideskBundle\Configuration\Cases
11
 */
12
class AddCasesRequestConfiguration implements ConfigurationInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    const MESSAGE_INVALID_PRIORITY = 'Invalid priority. Allowed priorities are: %s';
18
19
    /**
20
     * @return TreeBuilder
21
     */
22
    public function getConfigTreeBuilder()
23
    {
24
        $treeBuilder = new TreeBuilder();
25
26
        $rootNode = $treeBuilder->root('params');
27
28
        $rootNode
29
            ->children()
30
                ->scalarNode('user_email')
31
                    ->defaultNull()
32
                ->end()
33
                ->scalarNode('user_phone')
34
                    ->defaultNull()
35
                ->end()
36
                ->scalarNode('user_full_name')
37
                    ->defaultNull()
38
                ->end()
39
                ->scalarNode('subject')
40
                    ->isRequired()
41
                    ->cannotBeEmpty()
42
                ->end()
43
                ->scalarNode('content')
44
                    ->isRequired()
45
                    ->cannotBeEmpty()
46
                ->end()
47
                ->scalarNode('content_html')
48
                    ->isRequired()
49
                    ->cannotBeEmpty()
50
                ->end()
51
                ->scalarNode('group_id')
52
                    ->defaultNull()
53
                ->end()
54
                ->scalarNode('language_id')
55
                    ->defaultNull()
56
                ->end()
57
                ->arrayNode('custom_fields')
58
                    ->prototype('scalar')
59
                    ->end()
60
                ->end()
61
                ->arrayNode('labels')
62
                ->end()
63
                ->arrayNode('attachments')
64
                    ->prototype('scalar')
65
                    ->end()
66
                ->end()
67
                ->scalarNode('priority')
68
                    ->defaultNull()
69
                    ->validate()
70
                        ->ifNotInArray(Cases::PRIORITIES)
71
                        ->thenInvalid(sprintf(self::MESSAGE_INVALID_PRIORITY, implode(', ', Cases::PRIORITIES)))
72
                    ->end()
73
                ->end()
74
                ->scalarNode('staff_id')
75
                    ->defaultNull()
76
                ->end()
77
            ->end();
78
79
        return $treeBuilder;
80
    }
81
}
82