Completed
Push — master ( a2df97...e9a9f0 )
by Vladimir
06:27
created

CheckPluginAbstract::_importance()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3.0175

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 20
ccs 14
cts 16
cp 0.875
rs 9.7666
c 0
b 0
f 0
cc 3
nc 1
nop 1
crap 3.0175
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;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
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
abstract class CheckPluginAbstract implements CheckPluginInterface
23
{
24
    const IMPORTANCE_EMERGENCY = 'EMERGENCY';
25
    const IMPORTANCE_WARNING = 'WARNING';
26
    const IMPORTANCE_NOTE = 'NOTE';
27
    const IMPORTANCE_INFO = 'INFO';
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @return string[]
31
     */
32 54
    public static function getImportances(): array
33
    {
34
        return [
35 54
            self::IMPORTANCE_EMERGENCY => self::IMPORTANCE_EMERGENCY,
36 54
            self::IMPORTANCE_WARNING => self::IMPORTANCE_WARNING,
37 54
            self::IMPORTANCE_NOTE => self::IMPORTANCE_NOTE,
38 54
            self::IMPORTANCE_INFO => self::IMPORTANCE_INFO,
39
        ];
40
    }
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $checkSettings should have a doc-comment as per coding-style.
Loading history...
43
     * @throws FeatureRequired
44
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
45 37
    public function checkRequirements(array $checkSettings)
46
    {
47 37
    }
48
49
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $builder should have a doc-comment as per coding-style.
Loading history...
50
     * @return NodeDefinition|ArrayNodeDefinition
51
     */
52 54
    public function checkConf(TreeBuilder $builder): NodeDefinition
53
    {
54
        $node = $builder
55 54
            ->root(static::CHECK_NAME, 'array')
56 54
            ->info(static::DESCR); //--
57
58 54
        $this->_check($node);
59
60 54
        return $node;
61
    }
62
63
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $builder should have a doc-comment as per coding-style.
Loading history...
64
     * @return NodeDefinition|ArrayNodeDefinition
65
     */
66 54
    public function checkFactoryConf(TreeBuilder $builder): NodeDefinition
67
    {
68
        $node = $builder
69 54
            ->root(static::CHECK_NAME.'_factory', 'array')
70 54
            ->info(static::DESCR)
71 54
            ->children()
72 54
                ->arrayNode('items')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
73 54
                    ->prototype('array'); //--
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
74 54
        $node = $this->_check($node)
75 54
                    ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
76 54
                ->end()
0 ignored issues
show
Bug introduced by
The method end() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Config...ion\Builder\TreeBuilder. Are you sure you never get one of those? ( Ignorable by Annotation )

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

76
                ->/** @scrutinizer ignore-call */ end()
Loading history...
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
77 54
            ->end();
78
79 54
        $this->_addition($node);
80
81 54
        return $node;
82
    }
83
84
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
85
     * @param NodeDefinition|ArrayNodeDefinition $node
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
86
     *
87
     * @return NodeDefinition|ArrayNodeDefinition
88
     */
89 54
    protected function _addition(NodeDefinition $node): NodeDefinition
0 ignored issues
show
Coding Style introduced by
Protected method name "CheckPluginAbstract::_addition" must not be prefixed with an underscore
Loading history...
90
    {
91 54
        $this->_group($node);
92 54
        $this->_tags($node);
93 54
        $this->_importance($node);
94 54
        $this->_label($node);
95 54
        $this->_descr($node);
96
97
98 54
        return $node;
99
    }
100
101
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
102
     * @param NodeDefinition|ArrayNodeDefinition $node
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
103
     *
104
     * @return NodeDefinition|ArrayNodeDefinition
105
     */
106
    abstract protected function _check(NodeDefinition $node): NodeDefinition;
0 ignored issues
show
Coding Style introduced by
Protected method name "CheckPluginAbstract::_check" must not be prefixed with an underscore
Loading history...
107
108
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
109
     * @param NodeDefinition|ArrayNodeDefinition $node
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
110
     *
111
     * @return NodeDefinition|ArrayNodeDefinition
112
     */
113 54
    protected function _label(NodeDefinition $node): NodeDefinition
0 ignored issues
show
Coding Style introduced by
Protected method name "CheckPluginAbstract::_label" must not be prefixed with an underscore
Loading history...
114
    {
115
        return $node
116 54
            ->children()
117 54
                ->scalarNode('label')->defaultNull()->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
118 54
            ->end();
119
    }
120
121
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
122
     * @param NodeDefinition|ArrayNodeDefinition $node
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
123
     *
124
     * @return NodeDefinition|ArrayNodeDefinition
125
     */
126 54
    protected function _importance(ArrayNodeDefinition $node): NodeDefinition
0 ignored issues
show
Coding Style introduced by
Protected method name "CheckPluginAbstract::_importance" must not be prefixed with an underscore
Loading history...
127
    {
128
        return $node
129 54
            ->children()
130 54
                ->scalarNode('importance')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
131 54
                    ->validate()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
132 54
                        ->ifTrue( function($value) {
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
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 FUNCTION keyword; 0 found
Loading history...
133 1
                            if($value === null) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
134
                                return false;
135 1
                            } else if(in_array($value, self::getImportances())) {
0 ignored issues
show
Coding Style introduced by
Expected "} else if (...) \n"; found " else if(...) {\n"
Loading history...
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
136 1
                                return false;
137
                            }
138
139
                            return true;
140 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...
141 54
                        ->thenInvalid(sprintf('importance has to one of value [%s]', implode(', ', self::getImportances())))
142 54
                    ->end()
143 54
                    ->defaultNull()
144 54
                ->end()
145 54
            ->end();
146
    }
147
148
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
149
     * @param NodeDefinition|ArrayNodeDefinition $node
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
150
     *
151
     * @return NodeDefinition|ArrayNodeDefinition
152
     */
153 54
    protected function _group(NodeDefinition $node): NodeDefinition
0 ignored issues
show
Coding Style introduced by
Protected method name "CheckPluginAbstract::_group" must not be prefixed with an underscore
Loading history...
154
    {
155
        return $node
156 54
            ->children()
157 54
                ->scalarNode('group')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
158 54
                    ->cannotBeEmpty()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
159 54
                ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
160 54
                ->scalarNode('_group')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
161 54
                    ->defaultValue(static::GROUP)
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
162 54
                    ->cannotBeOverwritten()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
163 54
                ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
164 54
            ->end();
165
    }
166
167
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
168
     * @param NodeDefinition|ArrayNodeDefinition $node
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
169
     *
170
     * @return NodeDefinition|ArrayNodeDefinition
171
     */
172 54
    protected function _tags(NodeDefinition $node): NodeDefinition
0 ignored issues
show
Coding Style introduced by
Protected method name "CheckPluginAbstract::_tags" must not be prefixed with an underscore
Loading history...
173
    {
174
        return $node
175 54
            ->children()
176 54
                ->arrayNode('tags')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
177 54
                    ->prototype('scalar')->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
178 54
                ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
179 54
            ->end();
180
    }
181
182
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
183
     * @param NodeDefinition|ArrayNodeDefinition $node
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
184
     *
185
     * @return NodeDefinition|ArrayNodeDefinition
186
     */
187 54
    protected function _descr(NodeDefinition $node): NodeDefinition
0 ignored issues
show
Coding Style introduced by
Protected method name "CheckPluginAbstract::_descr" must not be prefixed with an underscore
Loading history...
188
    {
189
        return $node
190 54
            ->children()
191 54
                ->scalarNode('descr')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
192 54
                    ->defaultNull()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
193 54
                ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
194 54
            ->end();
195
    }
196
}
197