Passed
Push — master ( c54b8c...2ac8f3 )
by Vladimir
05:52
created

Plugin::_check()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 26
ccs 21
cts 21
cp 1
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Check\rabbitmq\QueueConsumer;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Tvi\MonitorBundle\Check\CheckPluginAbstract;
17
use Tvi\MonitorBundle\Exception\FeatureRequired;
18
19
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
 * @author Vladimir Turnaev <[email protected]>
21
 */
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...
22
class Plugin extends CheckPluginAbstract
23
{
24
    const DESCR =
0 ignored issues
show
Coding Style introduced by
Multi-line assignments must have the equal sign on the second line
Loading history...
25
<<<'TXT'
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 4 spaces, found 0
Loading history...
26
rabbit_mq description
27
TXT;
28
29
    const PATH = __DIR__;
30
31
    const GROUP = 'rabbit_mq';
32
    const CHECK_NAME = 'core:rabbit_mq:queue_consumer';
33
34
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $checkSettings should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
35
     * @throws FeatureRequired
36
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
37 1
    public function checkRequirements(array $checkSettings)
38
    {
39 1
        if (!class_exists('PhpAmqpLib\Connection\AMQPConnection')) {
40
            throw new FeatureRequired('PhpAmqpLib is not installed');
41
        }
42 1
    }
43
44 56
    public function checkFactoryConf(TreeBuilder $builder): ArrayNodeDefinition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function checkFactoryConf()
Loading history...
45
    {
46
        /* @var ArrayNodeDefinition $node */
47 56
        $node = parent::checkFactoryConf($builder);
48
49
        $keys = [
50 56
            'warningThreshold',
51
            'criticalThreshold',
52
            'host',
53
            'port',
54
            'user',
55
            'password',
56
            'vhost',
57
            'dsn',
58
        ];
59
        $node = $node
60 56
            ->beforeNormalization()
61 56
                ->ifArray()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
62 56
                ->then(static function ($value) use($keys) {
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
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Expected 1 space after USE keyword; found 0
Loading history...
63
64 1
                    foreach ($keys as $key) {
65
66 1
                        if (isset($value[$key])) {
67 1
                            foreach ($value['items'] as &$v) {
68 1
                                if (!array_key_exists($key, $v['check'])) {
69 1
                                    $v['check'][$key] = $value[$key];
70
                                }
71
                            }
72
                        }
73
                    }
74 1
                    return $value;
75 56
                })
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...
76 56
            ->end();
77
78 56
        $node->children()
79 56
            ->integerNode('warningThreshold')->end()
80 56
            ->integerNode('criticalThreshold')->end()
81 56
            ->scalarNode('host')->end()
82 56
            ->integerNode('port')->end()
83 56
            ->scalarNode('user')->end()
84 56
            ->scalarNode('password')->end()
85 56
            ->scalarNode('vhost')->end()
86 56
            ->scalarNode('dsn')->end()
87 56
        ->end();
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 8
Loading history...
88
89 56
        return $node;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $node returns the type Symfony\Component\Config...\Builder\NodeDefinition which includes types incompatible with the type-hinted return Symfony\Component\Config...der\ArrayNodeDefinition.
Loading history...
90
    }
91
92 56
    protected function _check(ArrayNodeDefinition $node): ArrayNodeDefinition
0 ignored issues
show
Coding Style introduced by
Protected method name "Plugin::_check" must not be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function _check()
Loading history...
93
    {
94
        $node = $node
95 56
            ->children()
96 56
                ->arrayNode('check')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
97 56
                    ->beforeNormalization()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
98 56
                        ->ifString()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
99
                        ->then(static function ($v) { return ['dsn' => $v]; })
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
Coding Style introduced by
Opening brace must be the last content on the line
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
100 56
                    ->end()
101 56
                    ->children()
102 56
                        ->scalarNode('queue')->isRequired()->end()
103 56
                        ->integerNode('warningThreshold')->defaultValue(null)->end()
104 56
                        ->integerNode('criticalThreshold')->defaultValue(100)->end()
105 56
                        ->scalarNode('host')->defaultValue('localhost')->end()
106 56
                        ->integerNode('port')->defaultValue(5672)->end()
107 56
                        ->scalarNode('user')->defaultValue('guest')->end()
108 56
                        ->scalarNode('password')->defaultValue('guest')->end()
109 56
                        ->scalarNode('vhost')->defaultValue('/')->end()
110 56
                        ->scalarNode('dsn')->defaultNull()->end()
111 56
                    ->end()
112 56
                ->end()
113 56
            ->end();
114
115 56
        $this->_addition($node);
116
117 56
        return $node;
118
    }
119
}
120