Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 2.0001

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 28
cts 29
cp 0.9655
rs 9.264
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0001
1
<?php
2
3
namespace Zenstruck\RedirectBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
class Configuration implements ConfigurationInterface
12
{
13 11
    public function getConfigTreeBuilder()
14
    {
15 11
        $treeBuilder = new TreeBuilder('zenstruck_redirect');
16
17
        // Keep compatibility with symfony/config < 4.2
18 11
        if (\method_exists($treeBuilder, 'getRootNode')) {
19 11
            $rootNode = $treeBuilder->getRootNode();
20
        } else {
21
            $rootNode = $treeBuilder->root('zenstruck_redirect');
0 ignored issues
show
Bug introduced by
The method root() does not seem to exist on object<Symfony\Component...on\Builder\TreeBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
        }
23
24
        $rootNode
25 11
            ->children()
26 11
                ->scalarNode('redirect_class')
27 11
                    ->defaultNull()
28 11
                    ->validate()
29
                        ->ifTrue(function($value) {
30 7
                            return !\is_subclass_of($value, 'Zenstruck\RedirectBundle\Model\Redirect');
31 11
                        })
32 11
                        ->thenInvalid('"redirect_class" must be an instance of "Zenstruck\RedirectBundle\Model\Redirect"')
33 11
                    ->end()
34 11
                ->end()
35 11
                ->scalarNode('not_found_class')
36 11
                    ->defaultNull()
37 11
                    ->validate()
38
                        ->ifTrue(function($value) {
39 6
                            return !\is_subclass_of($value, 'Zenstruck\RedirectBundle\Model\NotFound');
40 11
                        })
41 11
                        ->thenInvalid('"not_found_class" must be an instance of "Zenstruck\RedirectBundle\Model\NotFound"')
42 11
                    ->end()
43 11
                ->end()
44 11
                ->booleanNode('remove_not_founds')
45 11
                    ->info('When enabled, when a redirect is updated or created, the NotFound entites with a matching path are removed.')
46 11
                    ->defaultTrue()
47 11
                ->end()
48 11
                ->scalarNode('model_manager_name')->defaultNull()->end()
49 11
            ->end()
50
        ;
51
52 11
        return $treeBuilder;
53
    }
54
}
55