ReporterManager::getReporterAliases()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 3
nc 2
nop 1
crap 3
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\Reporter;
13
14
use ZendDiagnostics\Runner\Reporter\ReporterInterface;
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 ReporterManager
20
{
21
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
22
     * @var ReporterInterface[]
23
     */
24
    protected $reporters = [];
25
26
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $reporter should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $scope should have a doc-comment as per coding-style.
Loading history...
27
     * @param ?string $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
28
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
29 99
    public function addReporter(string $name, ReporterInterface $reporter, string $scope = null)
30
    {
31 99
        if ($scope) {
32 99
            $this->reporters[$scope][$name] = $reporter;
33
        }
34
35 99
        $this->reporters['all'][$name] = $reporter;
36 99
    }
37
38
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $name should have a doc-comment as per coding-style.
Loading history...
39
     * @param ?string $scope
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $scope does not match actual variable name $name
Loading history...
40
     *
41
     * @return ?ReporterInterface
42
     */
43 61
    public function getReporter(string $name, string $scope = null)
44
    {
45 61
        if ($scope) {
46 1
            return isset($this->reporters[$scope][$name]) ? $this->reporters[$scope][$name] : null;
47
        }
48
49 61
        return isset($this->reporters['all'][$name]) ? $this->reporters['all'][$name] : null;
50
    }
51
52
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
53
     * @param ?string $scope
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
54
     *
55
     * @return string[]
56
     */
57 2
    public function getReporterAliases(string $scope = null): array
58
    {
59 2
        if ($scope && isset($this->reporters[$scope])) {
60 1
            return array_keys($this->reporters[$scope]);
0 ignored issues
show
Bug introduced by
$this->reporters[$scope] of type ZendDiagnostics\Runner\Reporter\ReporterInterface is incompatible with the type array expected by parameter $input of array_keys(). ( Ignorable by Annotation )

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

60
            return array_keys(/** @scrutinizer ignore-type */ $this->reporters[$scope]);
Loading history...
61
        }
62
63 2
        return array_keys($this->reporters['all']);
64
    }
65
}
66