Passed
Push — master ( 0ec4b3...bff059 )
by Vladimir
05:55
created

Configuration::addUIViewTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of the `tvi/monitor-bundle` project.
5
 *
6
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
11
12
namespace Tvi\MonitorBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17
use Symfony\Component\Config\Definition\ConfigurationInterface;
18
use Tvi\MonitorBundle\Check\CheckPluginFinder;
19
20
/**
21
 * This class contains the configuration information for the bundle.
22
 *
23
 * This information is solely responsible for how the different configuration
24
 * sections are normalized, and merged.
25
 *
26
 * @author Vladimir Turnaev <[email protected]>
27
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
28
class Configuration implements ConfigurationInterface
29
{
30
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @var array
32
     */
33
    private $checkPlugins = [];
0 ignored issues
show
Coding Style introduced by
Private member variable "checkPlugins" must be prefixed with an underscore
Loading history...
34
35
    private $checkPluginClasses = [];
0 ignored issues
show
Coding Style introduced by
Private member variable "checkPluginClasses" must be prefixed with an underscore
Loading history...
36
37
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $pluginFinder should have a doc-comment as per coding-style.
Loading history...
38
     * Configuration constructor.
39
     */
40 54
    public function __construct(CheckPluginFinder $pluginFinder)
41
    {
42 54
        $this->checkPluginClasses = $pluginFinder->find();
43 54
    }
44
45 48
    public function getCheckPlugins(): array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getCheckPlugins()
Loading history...
46
    {
47 48
        return $this->checkPlugins;
48
    }
49
50
    /**
51
     * Generates the configuration tree.
52
     *
53
     * @return TreeBuilder
54
     */
55 54
    public function getConfigTreeBuilder()
56
    {
57 54
        $treeBuilder = new TreeBuilder();
58
59 54
        $treeBuilder->root('tvi_monitor', 'array')
60 54
            ->children()
61 54
                ->append($this->addUIViewTemplate())
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
62 54
                ->append($this->addChecksSearchPaths())
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
63 54
                ->append($this->addGroups())
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
64 54
                ->append($this->addTags())
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
65 54
                ->append($this->addReporers())
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
66 54
                ->append($this->addChecks())
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
67 54
            ->end()
68 54
        ->end();
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 8
Loading history...
69
70 54
        return $treeBuilder;
71
    }
72
73 54
    private function addChecks(): ArrayNodeDefinition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addChecks()
Loading history...
Coding Style introduced by
Private method name "Configuration::addChecks" must be prefixed with an underscore
Loading history...
74
    {
75 54
        $builder = new TreeBuilder();
76
77 54
        $checkPligins = $this->checkPlugins;
78
79 54
        $addChecks = function ($rootNode) use ($checkPligins, $builder) {
0 ignored issues
show
Unused Code introduced by
The import $checkPligins is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
80 54
            foreach ($this->checkPluginClasses as $checkPluginClass) {
81 54
                $checkPligin = new $checkPluginClass();
82
83 54
                $confMethods = array_filter(get_class_methods($checkPligin), static function ($n) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
84 54
                    return preg_match('/Conf$/', $n);
85 54
                });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
86
87 54
                foreach ($confMethods as $confMethod) {
88
89
                    /* @var ArrayNodeDefinition $node */
90 54
                    $node = $checkPligin->$confMethod($builder);
91 54
                    $checkName = $node->getNode(true)->getName();
92 54
                    $serviceName = preg_replace('/_factory$/', '', $checkName);
93
94 54
                    $this->checkPlugins[$checkName] = [
95 54
                        'checkServicePath' => $checkPligin::PATH.\DIRECTORY_SEPARATOR.'check.yml',
96 54
                        'service' => $serviceName,
97 54
                        'pligin' => $checkPligin,
98
                    ];
99
100 54
                    $rootNode->append($node);
101
                }
102
            }
103
104 54
            return $rootNode;
105 54
        };
106
107
        $node = $builder
108 54
            ->root('checks', 'array')
109 54
            ->beforeNormalization()
110 54
            ->always(static function ($value) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
111 43
                $value = $value ? $value : [];
112 43
                foreach ($value as $k => $v) {
113 43
                    $newK = str_replace('(s)', '_factory', $k);
114 43
                    if ($newK !== $k) {
115 38
                        $value[$newK] = $value[$k];
116 43
                        unset($value[$k]);
117
                    }
118
                }
119
120 43
                return $value;
121 54
            })
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
122 54
            ->end()
123 54
            ->children(); //--
124 54
        $node = $addChecks($node)
125 54
            ->end();
126
127 54
        return $node;
128
    }
129
130 54
    private function addReporers(): ArrayNodeDefinition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addReporers()
Loading history...
Coding Style introduced by
Private method name "Configuration::addReporers" must be prefixed with an underscore
Loading history...
131
    {
132 54
        return (new TreeBuilder())
133 54
            ->root('reporters', 'array')
134 54
            ->children()
135 54
                ->arrayNode('mailer')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
136 54
                    ->children()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
137 54
                        ->scalarNode('recipient')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
138 54
                            ->isRequired()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
139 54
                            ->cannotBeEmpty()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
140 54
                        ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
141 54
                        ->scalarNode('sender')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
142 54
                            ->isRequired()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
143 54
                            ->cannotBeEmpty()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
144 54
                        ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
145 54
                        ->scalarNode('subject')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
146 54
                            ->isRequired()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
147 54
                            ->cannotBeEmpty()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
148 54
                        ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
149 54
                        ->booleanNode('send_on_warning')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
150 54
                            ->defaultTrue()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
151 54
                        ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
152 54
                    ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
153 54
                ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
154 54
            ->end();
155
    }
156
157 54
    private function addTags(): ArrayNodeDefinition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addTags()
Loading history...
Coding Style introduced by
Private method name "Configuration::addTags" must be prefixed with an underscore
Loading history...
158
    {
159 54
        return (new TreeBuilder())
160 54
            ->root('tags', 'array')
161 54
            ->prototype('array')
0 ignored issues
show
Bug introduced by
The method prototype() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

161
            ->/** @scrutinizer ignore-call */ prototype('array')
Loading history...
162 54
                ->children()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
163 54
                    ->scalarNode('name')->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
164 54
                    ->scalarNode('descr')->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
165 54
                ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
166 54
            ->end();
167
    }
168
169 54
    private function addGroups(): ArrayNodeDefinition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addGroups()
Loading history...
Coding Style introduced by
Private method name "Configuration::addGroups" must be prefixed with an underscore
Loading history...
170
    {
171 54
        return (new TreeBuilder())
172 54
            ->root('groups', 'array')
173 54
            ->prototype('array')
174 54
                ->children()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
175 54
                    ->scalarNode('name')->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
176 54
                    ->scalarNode('descr')->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
177 54
                ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
178 54
            ->end();
179
    }
180
181 54
    private function addChecksSearchPaths(): ArrayNodeDefinition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addChecksSearchPaths()
Loading history...
Coding Style introduced by
Private method name "Configuration::addChecksSearchPaths" must be prefixed with an underscore
Loading history...
182
    {
183 54
        return (new TreeBuilder())
184 54
            ->root('checks_search_paths', 'array')
185 54
            ->prototype('scalar')->end();
186
    }
187
188 54
    private function addUIViewTemplate()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addUIViewTemplate()
Loading history...
Coding Style introduced by
Private method name "Configuration::addUIViewTemplate" must be prefixed with an underscore
Loading history...
189
    {
190 54
        return (new TreeBuilder())
191 54
            ->root('ui_view_template', 'scalar')
192 54
                ->cannotBeEmpty()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
193 54
                ->defaultValue('@TviMonitor/UI/index.html.twig')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
Coding Style introduced by
Space after closing parenthesis of function call prohibited
Loading history...
194
            ;
195
    }
196
}
197