Completed
Push — master ( 0f40a6...d6049e )
by Vragov
03:23
created

getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 8.8945
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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