Test Failed
Push — master ( ec8ff1...24c3c9 )
by Vladimir
05:33
created

Manager::getChecks()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 8
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
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\DependencyInjection\ContainerAwareTrait;
15
16
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
17
 * @author Vladimir Turnaev <[email protected]>
18
 */
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...
19
class Manager implements \ArrayAccess, \Iterator, \Countable
20
{
21
    use ContainerAwareTrait;
22
    use CheckArraybleTrait;
23
24
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
     * @var Group[]
26
     */
27
    protected $groups = [];
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @var Group[]
31
     */
32
    protected $tags = [];
33
34
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
35
     * @param array $tagsMap
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
36
     * @param array $checkServiceMap
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
37
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
38 36
    public function init(array $tagsMap, array $checkServiceMap)
39
    {
40 36
        $this->setTagsMap($tagsMap);
41 36
        $this->setCheckServiceMap($checkServiceMap);
42 36
    }
43
44
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $alias should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $groups should have a doc-comment as per coding-style.
Loading history...
45
     * @param null|string|string[] $tags
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $tags does not match actual variable name $alias
Loading history...
46
     *
47
     * @return Tag[]
48
     */
49 32
    public function getChecks($alias = null, $groups = null, $tags = null): array
0 ignored issues
show
Unused Code introduced by
The parameter $tags is not used and could be removed. ( Ignorable by Annotation )

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

49
    public function getChecks($alias = null, $groups = null, /** @scrutinizer ignore-unused */ $tags = null): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $alias is not used and could be removed. ( Ignorable by Annotation )

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

49
    public function getChecks(/** @scrutinizer ignore-unused */ $alias = null, $groups = null, $tags = null): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $groups is not used and could be removed. ( Ignorable by Annotation )

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

49
    public function getChecks($alias = null, /** @scrutinizer ignore-unused */ $groups = null, $tags = null): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51 32
        $out = [];
52
        foreach ($this as $id => $check) {
53
            $out[] = $check;
54
        }
55
56
        return $out;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $out returns an array which contains values of type Tvi\MonitorBundle\Check\CheckInterface which are incompatible with the documented value type Tvi\MonitorBundle\Check\Tag.
Loading history...
57
    }
58
59 1
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
60
     * @param Group $group
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
61 1
     *
62 1
     * @return Group
63
     */
64 1
    public function getTags(Group $group): Group
65 1
    {
66 1
        return empty($this->groups[$group->getName()]) ? $this->groups[$group->getName()] = $group : $this->groups[$group->getName()];
67
    }
68
69 1
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
70
     * @param Group $group
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
71
     *
72
     * @return Group
73
     */
74
    public function addGroup(Group $group): Group
75
    {
76
        return empty($this->groups[$group->getName()]) ? $this->groups[$group->getName()] = $group : $this->groups[$group->getName()];
77 4
    }
78
79 4
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
80
     * @param null|string|string[] $groups
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
81
     *
82
     * @return Group[]
83
     */
84
    public function getGroups($groups = null): array
85
    {
86
        if ($groups) {
87 2
            $groups = \is_string($groups) ? [$groups] : $groups;
88
89 2
            return array_filter($this->groups, function ($t) use ($groups) {
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...
90 1
                return \in_array($t->getName(), $groups);
91
            });
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...
92 1
        }
93 1
94 1
        return $this->groups;
95
    }
96
97 2
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
98
     * @param Tag $tag
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
99
     *
100
     * @return Tag
101
     */
102
    public function addTag(Tag $tag): Tag
103
    {
104 36
        return empty($this->tags[$tag->getName()]) ? $this->tags[$tag->getName()] = $tag : $this->tags[$tag->getName()];
0 ignored issues
show
Bug Best Practice introduced by
The expression return empty($this->tags...->tags[$tag->getName()] could return the type Tvi\MonitorBundle\Check\Group which is incompatible with the type-hinted return Tvi\MonitorBundle\Check\Tag. Consider adding an additional type-check to rule them out.
Loading history...
105
    }
106 36
107 2
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
108
     * @param array $tagsMap
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
109 36
     * @param array $checksMap
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Superfluous parameter comment
Loading history...
110
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
111
    protected function setTagsMap(array $tagsMap)
112
    {
113
        foreach ($tagsMap as $tag => $tagSetting) {
114 36
            $this->addTag(new Tag($tag));
115
        }
116 36
    }
117 32
118 32
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
119 32
     * @param array $checkServiceMap
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
120
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
121 32
    protected function setCheckServiceMap($checkServiceMap)
122 32
    {
123
        foreach ($checkServiceMap as $checkId => $check) {
124 32
            $checkServiceId = $check['serviceId'];
125
            $checkProxy = new Proxy(function () use ($checkServiceId, $checkId) {
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...
126 32
                $this->checks[$checkId] = $this->container->get($checkServiceId);
127 3
128 3
                return $this->checks[$checkId];
129
            });
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...
130
131 32
            $this->checks[$checkId] = $checkProxy;
132 32
133 32
            foreach ($check['tags'] as $tagName) {
134
                $tag = $this->addTag(new Tag($tagName));
135
                $tag->addCheck($checkId, $this->checks[$checkId]);
136 36
            }
137 4
138 4
            $group = $this->addGroup(new Group($check['group']));
139
            $group->addCheck($checkId, $this->checks[$checkId]);
140
            $this->groups[$group->getName()] = $group;
141 36
        }
142
143
        foreach ($this->tags as $id => $tag) {
144
            if (!\count($tag)) {
145
                unset($this->tags[$id]);
146
            }
147
        }
148
    }
149
}
150