Passed
Push — master ( 7f6a2e...f50264 )
by Vladimir
07:00
created

Plugin::checkFactoryConf()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 42
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 5.0144

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 42
ccs 22
cts 24
cp 0.9167
rs 9.1288
c 0
b 0
f 0
cc 5
nc 1
nop 1
crap 5.0144
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\http\GuzzleHttpService;
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
guzzle_http_service description
27
TXT;
28
29
    const PATH = __DIR__;
30
31
    const GROUP = 'http';
32
    const CHECK_NAME = 'core:guzzle_http_service';
33
34
    /**
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...
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 (!interface_exists('\GuzzleHttp\ClientInterface')) {
40
            throw new FeatureRequired('GuzzleHttp is not installed');
41
        }
42 1
    }
43
44 57
    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 57
        $node = parent::checkFactoryConf($builder);
48
        $keys = [
49 57
            'headers',
50
            'options',
51
            'statusCode',
52
            'method',
53
            'content',
54
            'body',
55
            'withData',
56
        ];
57
58
        $node = $node
59 57
            ->beforeNormalization()
60 57
            ->ifArray()
61 57
            ->then(static function ($value) use ($keys) {
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...
62 1
                foreach ($keys as $key) {
63 1
                    if (isset($value[$key])) {
64
                        foreach ($value['items'] as &$v) {
65
                            if (!array_key_exists($key, $v['check'])) {
66 1
                                $v['check'][$key] = $value[$key];
67
                            }
68
                        }
69
                    }
70
                }
71
72 1
                return $value;
73 57
            })
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...
74 57
            ->end();
75 57
        $node->children()
76 57
            ->variableNode('headers')->end()
77 57
            ->variableNode('options')->end()
78 57
            ->integerNode('statusCode')->end()
79 57
            ->scalarNode('method')->end()
80 57
            ->scalarNode('content')->end()
81 57
            ->scalarNode('body')->end()
82 57
            ->booleanNode('withData')->end()
83 57
        ->end();
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 8
Loading history...
84
85 57
        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...
86
    }
87
88 57
    protected function _check(ArrayNodeDefinition $node): ArrayNodeDefinition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function _check()
Loading history...
Coding Style introduced by
Protected method name "Plugin::_check" must not be prefixed with an underscore
Loading history...
89
    {
90
        $node = $node
91 57
            ->children()
92 57
                ->arrayNode('check')
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
93 57
                    ->children()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
94 57
                        ->scalarNode('requestOrUrl')->defaultValue('localhost')->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
95 57
                        ->variableNode('headers')->defaultValue([])->end()
0 ignored issues
show
Bug introduced by
The method variableNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

95
                        ->/** @scrutinizer ignore-call */ variableNode('headers')->defaultValue([])->end()
Loading history...
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
96 57
                        ->variableNode('options')->defaultValue([])->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
97 57
                        ->integerNode('statusCode')->defaultValue(200)->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
98 57
                        ->scalarNode('method')->defaultValue('GET')->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
99 57
                        ->scalarNode('content')->defaultNull()->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
100 57
                        ->scalarNode('body')->defaultNull()->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
101 57
                        ->booleanNode('withData')->defaultFalse()->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 24
Loading history...
102 57
                    ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 20
Loading history...
103 57
                ->end()
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 12 spaces but found 16
Loading history...
104 57
            ->end();
105
106 57
        $this->_addition($node);
107
108 57
        return $node;
109
    }
110
}
111