turnaev /
monitor-bundle
| 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
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
|
|||||
| 27 | class Configuration implements ConfigurationInterface |
||||
| 28 | { |
||||
| 29 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 30 | * @var array |
||||
| 31 | */ |
||||
| 32 | private $checkPlugins = []; |
||||
|
0 ignored issues
–
show
|
|||||
| 33 | |||||
| 34 | private $checkPluginClasses = []; |
||||
|
0 ignored issues
–
show
|
|||||
| 35 | |||||
| 36 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 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
|
|||||
| 61 | 57 | ->append($this->addChecksSearchPaths()) |
|||
|
0 ignored issues
–
show
|
|||||
| 62 | 57 | ->append($this->addGroups()) |
|||
|
0 ignored issues
–
show
|
|||||
| 63 | 57 | ->append($this->addTags()) |
|||
|
0 ignored issues
–
show
|
|||||
| 64 | 57 | ->append($this->addReporers()) |
|||
|
0 ignored issues
–
show
|
|||||
| 65 | 57 | ->append($this->addChecks()) |
|||
|
0 ignored issues
–
show
|
|||||
| 66 | 57 | ->end() |
|||
| 67 | 57 | ->end(); |
|||
|
0 ignored issues
–
show
|
|||||
| 68 | |||||
| 69 | 57 | return $treeBuilder; |
|||
| 70 | } |
||||
| 71 | |||||
| 72 | 57 | private function addChecks(): ArrayNodeDefinition |
|||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 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
|
|||||
| 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
|
|||||
| 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
|
|||||
| 130 | { |
||||
| 131 | 57 | return (new TreeBuilder()) |
|||
| 132 | 57 | ->root('reporters', 'array') |
|||
| 133 | 57 | ->children() |
|||
| 134 | 57 | ->arrayNode('mailer') |
|||
|
0 ignored issues
–
show
|
|||||
| 135 | 57 | ->children() |
|||
|
0 ignored issues
–
show
|
|||||
| 136 | 57 | ->scalarNode('recipient') |
|||
|
0 ignored issues
–
show
|
|||||
| 137 | 57 | ->isRequired() |
|||
|
0 ignored issues
–
show
|
|||||
| 138 | 57 | ->cannotBeEmpty() |
|||
|
0 ignored issues
–
show
|
|||||
| 139 | 57 | ->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 140 | 57 | ->scalarNode('sender') |
|||
|
0 ignored issues
–
show
|
|||||
| 141 | 57 | ->isRequired() |
|||
|
0 ignored issues
–
show
|
|||||
| 142 | 57 | ->cannotBeEmpty() |
|||
|
0 ignored issues
–
show
|
|||||
| 143 | 57 | ->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 144 | 57 | ->scalarNode('subject') |
|||
|
0 ignored issues
–
show
|
|||||
| 145 | 57 | ->isRequired() |
|||
|
0 ignored issues
–
show
|
|||||
| 146 | 57 | ->cannotBeEmpty() |
|||
|
0 ignored issues
–
show
|
|||||
| 147 | 57 | ->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 148 | 57 | ->booleanNode('send_on_warning') |
|||
|
0 ignored issues
–
show
|
|||||
| 149 | 57 | ->defaultTrue() |
|||
|
0 ignored issues
–
show
|
|||||
| 150 | 57 | ->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 151 | 57 | ->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 152 | 57 | ->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 153 | 57 | ->end(); |
|||
| 154 | } |
||||
| 155 | |||||
| 156 | 57 | private function addTags(): ArrayNodeDefinition |
|||
|
0 ignored issues
–
show
|
|||||
| 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
Loading history...
|
|||||
| 161 | 57 | ->children() |
|||
|
0 ignored issues
–
show
|
|||||
| 162 | 57 | ->scalarNode('name')->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 163 | 57 | ->scalarNode('descr')->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 164 | 57 | ->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 165 | 57 | ->end(); |
|||
| 166 | } |
||||
| 167 | |||||
| 168 | 57 | private function addGroups(): ArrayNodeDefinition |
|||
|
0 ignored issues
–
show
|
|||||
| 169 | { |
||||
| 170 | 57 | return (new TreeBuilder()) |
|||
| 171 | 57 | ->root('groups', 'array') |
|||
| 172 | 57 | ->prototype('array') |
|||
| 173 | 57 | ->children() |
|||
|
0 ignored issues
–
show
|
|||||
| 174 | 57 | ->scalarNode('name')->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 175 | 57 | ->scalarNode('descr')->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 176 | 57 | ->end() |
|||
|
0 ignored issues
–
show
|
|||||
| 177 | 57 | ->end(); |
|||
| 178 | } |
||||
| 179 | |||||
| 180 | 57 | private function addChecksSearchPaths(): ArrayNodeDefinition |
|||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 188 | { |
||||
| 189 | 57 | return (new TreeBuilder()) |
|||
| 190 | 57 | ->root('ui_view_template', 'scalar') |
|||
| 191 | 57 | ->cannotBeEmpty() |
|||
|
0 ignored issues
–
show
|
|||||
| 192 | 57 | ->defaultValue('@TviMonitor/UI/index.b4.html.twig'); |
|||
|
0 ignored issues
–
show
|
|||||
| 193 | } |
||||
| 194 | } |
||||
| 195 |