getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 91

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 91
rs 8.1963
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 OmnideskBundle\Request\Cases\ListCasesRequest;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * Class ListCasesRequestConfiguration
11
 * @package OmnideskBundle\Configuration\Cases
12
 */
13
class ListCasesRequestConfiguration implements ConfigurationInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    const MESSAGE_CHANNEL_INVALID_TYPE = 'Chanel invalid type.';
19
20
    /**
21
     * @var string
22
     */
23
    const MESSAGE_PRIORITY_INVALID_TYPE = 'Priority invalid type.';
24
25
    /**
26
     * @var string
27
     */
28
    const MESSAGE_STATUS_INVALID_TYPE = 'Status invalid type.';
29
30
    /**
31
     * @var string
32
     */
33
    const MESSAGE_SORT_INVALID_TYPE = 'Sort invalid type.';
34
35
    /**
36
     * @return TreeBuilder
37
     */
38
    public function getConfigTreeBuilder()
39
    {
40
        $treeBuilder = new TreeBuilder();
41
42
        $rootNode = $treeBuilder->root('params');
43
44
        $rootNode
45
            ->children()
46
                ->scalarNode('page')
47
                    ->defaultNull()
48
                ->end()
49
                ->scalarNode('limit')
50
                    ->defaultNull()
51
                ->end()
52
                ->scalarNode('user_id')
53
                    ->defaultNull()
54
                ->end()
55
                ->scalarNode('user_email')
56
                    ->defaultNull()
57
                ->end()
58
                ->scalarNode('user_phone')
59
                    ->defaultNull()
60
                ->end()
61
                ->scalarNode('subject')
62
                    ->defaultNull()
63
                ->end()
64
                ->scalarNode('staff_id')
65
                    ->defaultNull()
66
                ->end()
67
                ->scalarNode('group_id')
68
                    ->defaultNull()
69
                ->end()
70
                ->scalarNode('channel')
71
                    ->defaultNull()
72
                    ->validate()
73
                        ->ifNotInArray([
74
                            null,
75
                            Cases::CHANNEL_CHAT,
76
                            Cases::CHANNEL_EMAIL,
77
                            Cases::CHANNEL_FACEBOOK,
78
                            Cases::CHANNEL_IDEA,
79
                            Cases::CHANNEL_TWITTER,
80
                        ])
81
                        ->thenInvalid(self::MESSAGE_CHANNEL_INVALID_TYPE)
82
                    ->end()
83
                ->end()
84
                ->scalarNode('priority')
85
                    ->validate()
86
                        ->ifNotInArray([
87
                            null,
88
                            Cases::PRIORITY_LOW,
89
                            Cases::PRIORITY_NORMAL,
90
                            Cases::PRIORITY_HIGH,
91
                            Cases::PRIORITY_CRITICAL,
92
                        ])
93
                        ->thenInvalid(self::MESSAGE_PRIORITY_INVALID_TYPE)
94
                    ->end()
95
                ->end()
96
                ->scalarNode('status')
97
                    ->validate()
98
                        ->ifNotInArray([
99
                            null,
100
                            Cases::STATUS_OPEN,
101
                            Cases::STATUS_WAITING,
102
                            Cases::STATUS_CLOSED,
103
                        ])
104
                        ->thenInvalid(self::MESSAGE_STATUS_INVALID_TYPE)
105
                    ->end()
106
                ->end()
107
                ->arrayNode('custom_fields')
108
                    ->prototype('scalar')
109
                    ->end()
110
                ->end()
111
                ->arrayNode('labels')
112
                ->end()
113
                ->scalarNode('sort')
114
                    ->validate()
115
                        ->ifNotInArray([
116
                            null,
117
                            ListCasesRequest::SORT_CREATED_AT_ASC,
118
                            ListCasesRequest::SORT_CREATED_AT_DESC,
119
                            ListCasesRequest::SORT_UPDATED_AT_ASC,
120
                            ListCasesRequest::SORT_UPDATED_AT_DESC,
121
                        ])
122
                        ->thenInvalid(self::MESSAGE_SORT_INVALID_TYPE)
123
                    ->end()
124
                ->end()
125
            ->end();
126
127
        return $treeBuilder;
128
    }
129
}
130