getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace OmnideskBundle\Configuration\Message;
3
4
use OmnideskBundle\Request\Message\ListMessageRequest;
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * Class ListMessageRequestConfiguration
10
 * @package OmnideskBundle\Configuration\Message
11
 */
12
class ListMessageRequestConfiguration implements ConfigurationInterface
13
{
14
    /**
15
     * @var int
16
     */
17
    const DEFAULT_PAGE = 1;
18
19
    /**
20
     * @var int
21
     */
22
    const DEFAULT_LIMIT = 100;
23
24
    /**
25
     * @var string
26
     */
27
    const MESSAGE_ORDER_INVALID_TYPE = 'Order invalid type.';
28
29
    /**
30
     * @return TreeBuilder
31
     */
32
    public function getConfigTreeBuilder()
33
    {
34
        $treeBuilder = new TreeBuilder();
35
36
        $rootNode = $treeBuilder->root('params');
37
38
        $rootNode
39
            ->children()
40
                ->integerNode('case_id')
41
                    ->isRequired()
42
                ->end()
43
                ->integerNode('page')
44
                    ->defaultValue(self::DEFAULT_PAGE)
45
                ->end()
46
                ->integerNode('limit')
47
                    ->defaultValue(self::DEFAULT_LIMIT)
48
                ->end()
49
                ->scalarNode('order')
50
                    ->validate()
51
                        ->ifNotInArray([
52
                            null,
53
                            ListMessageRequest::ORDER_ASC,
54
                            ListMessageRequest::ORDER_DESC,
55
                        ])
56
                        ->thenInvalid(self::MESSAGE_ORDER_INVALID_TYPE)
57
                    ->end()
58
                ->end()
59
            ->end();
60
61
        return $treeBuilder;
62
    }
63
}
64