Issues (2921)

src/DependencyInjection/Configuration.php (69 issues)

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
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
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\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
use Tvi\MonitorBundle\Check\CheckPluginFinder;
18
19
/**
20
 * This class contains the configuration information for the bundle.
21
 *
22
 * This information is solely responsible for how the different configuration
23
 * sections are normalized, and merged.
24
 *
25
 * @author Vladimir Turnaev <[email protected]>
26
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @package tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
27
class Configuration implements ConfigurationInterface
28
{
29
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
30
     * @var array
31
     */
32
    private $checkPlugins = [];
0 ignored issues
show
Private member variable "checkPlugins" must be prefixed with an underscore
Loading history...
33
34
    private $checkPluginClasses = [];
0 ignored issues
show
Private member variable "checkPluginClasses" must be prefixed with an underscore
Loading history...
35
36
    /**
0 ignored issues
show
Parameter $pluginFinder should have a doc-comment as per coding-style.
Loading history...
37
     * Configuration constructor.
38
     */
39 57
    public function __construct(CheckPluginFinder $pluginFinder)
40
    {
41 57
        $this->checkPluginClasses = $pluginFinder->find();
42 57
    }
43
44 51
    public function getCheckPlugins(): array
0 ignored issues
show
Missing doc comment for function getCheckPlugins()
Loading history...
45
    {
46 51
        return $this->checkPlugins;
47
    }
48
49
    /**
50
     * Generates the configuration tree.
51
     *
52
     * @return TreeBuilder
53
     */
54 57
    public function getConfigTreeBuilder()
55
    {
56 57
        $treeBuilder = new TreeBuilder();
57
58 57
        $treeBuilder->root('tvi_monitor', 'array')
59 57
            ->children()
60 57
                ->append($this->addUIViewTemplate())
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
61 57
                ->append($this->addChecksSearchPaths())
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
62 57
                ->append($this->addGroups())
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
63 57
                ->append($this->addTags())
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
64 57
                ->append($this->addReporers())
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
65 57
                ->append($this->addChecks())
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
66 57
            ->end()
67 57
        ->end();
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 8
Loading history...
68
69 57
        return $treeBuilder;
70
    }
71
72 57
    private function addChecks(): ArrayNodeDefinition
0 ignored issues
show
Private method name "Configuration::addChecks" must be prefixed with an underscore
Loading history...
Missing doc comment for function addChecks()
Loading history...
73
    {
74 57
        $builder = new TreeBuilder();
75
76 57
        $checkPligins = $this->checkPlugins;
77
78 57
        $addChecks = function ($rootNode) use ($checkPligins, $builder) {
0 ignored issues
show
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...
79 57
            foreach ($this->checkPluginClasses as $checkPluginClass) {
80 57
                $checkPlugin = new $checkPluginClass();
81
82 57
                $confMethods = array_filter(get_class_methods($checkPlugin), static function ($n) {
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
83 57
                    return preg_match('/Conf$/', $n);
84 57
                });
0 ignored issues
show
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...
85
86 57
                foreach ($confMethods as $confMethod) {
87
88
                    /* @var ArrayNodeDefinition $node */
89 57
                    $node = $checkPlugin->$confMethod($builder);
90 57
                    $checkName = $node->getNode(true)->getName();
91 57
                    $serviceName = preg_replace('/_factory$/', '', $checkName);
92
93 57
                    $this->checkPlugins[$checkName] = [
94 57
                        'checkServicePath' => $checkPlugin::PATH.\DIRECTORY_SEPARATOR.'check.yml',
95 57
                        'service' => $serviceName,
96 57
                        'plugin' => $checkPlugin,
97
                    ];
98
99 57
                    $rootNode->append($node);
100
                }
101
            }
102
103 57
            return $rootNode;
104 57
        };
105
106
        $node = $builder
107 57
            ->root('checks', 'array')
108 57
            ->beforeNormalization()
109 57
            ->always(static function ($value) {
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
110 46
                $value = $value ? $value : [];
111 46
                foreach ($value as $k => $v) {
112 46
                    $newK = str_replace('(s)', '_factory', $k);
113 46
                    if ($newK !== $k) {
114 41
                        $value[$newK] = $value[$k];
115 46
                        unset($value[$k]);
116
                    }
117
                }
118
119 46
                return $value;
120 57
            })
0 ignored issues
show
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...
121 57
            ->end()
122 57
            ->children(); //--
123 57
        $node = $addChecks($node)
124 57
            ->end();
125
126 57
        return $node;
127
    }
128
129 57
    private function addReporers(): ArrayNodeDefinition
0 ignored issues
show
Missing doc comment for function addReporers()
Loading history...
Private method name "Configuration::addReporers" must be prefixed with an underscore
Loading history...
130
    {
131 57
        return (new TreeBuilder())
132 57
            ->root('reporters', 'array')
133 57
            ->children()
134 57
                ->arrayNode('mailer')
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
135 57
                    ->children()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
136 57
                        ->scalarNode('recipient')
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
137 57
                            ->isRequired()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
138 57
                            ->cannotBeEmpty()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
139 57
                        ->end()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
140 57
                        ->scalarNode('sender')
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
141 57
                            ->isRequired()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
142 57
                            ->cannotBeEmpty()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
143 57
                        ->end()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
144 57
                        ->scalarNode('subject')
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
145 57
                            ->isRequired()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
146 57
                            ->cannotBeEmpty()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
147 57
                        ->end()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
148 57
                        ->booleanNode('send_on_warning')
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
149 57
                            ->defaultTrue()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 28
Loading history...
150 57
                        ->end()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
151 57
                    ->end()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
152 57
                ->end()
0 ignored issues
show
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
153 57
            ->end();
154
    }
155
156 57
    private function addTags(): ArrayNodeDefinition
0 ignored issues
show
Missing doc comment for function addTags()
Loading history...
Private method name "Configuration::addTags" must be prefixed with an underscore
Loading history...
157
    {
158 57
        return (new TreeBuilder())
159 57
            ->root('tags', 'array')
160 57
            ->prototype('array')
0 ignored issues
show
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

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