Completed
Push — master ( aca6e3...e7aa24 )
by Vladimir
05:21
created

ReporterManager::getReporterAliases()   A

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
27 3
    public function addReporter(string $alias, ReporterInterface $reporter, ?string $scope = null)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addReporter()
Loading history...
28
    {
29 3
        if ($scope) {
30 3
            $this->reporters[$scope][$alias] = $reporter;
31
        }
32
33 3
        $this->reporters['all'][$alias] = $reporter;
34 3
    }
35
36
    /**
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 $scope should have a doc-comment as per coding-style.
Loading history...
37
     * @return ReporterInterface
38
     */
39 1
    public function getReporter(string $alias, ?string $scope = null): ?ReporterInterface
40
    {
41 1
        if ($scope && isset($this->reporters[$scope])) {
42 1
            return isset($this->reporters[$scope][$alias]) ? $this->reporters[$scope][$alias] : null;
43
        }
44
45 1
        return isset($this->reporters['all'][$alias]) ? $this->reporters['all'][$alias] : null;
46
    }
47
48
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $scope should have a doc-comment as per coding-style.
Loading history...
49
     * @return string[]
50
     */
51 2
    public function getReporterAliases(?string $scope = null): array
52
    {
53 2
        if ($scope && isset($this->reporters[$scope])) {
54 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

54
            return array_keys(/** @scrutinizer ignore-type */ $this->reporters[$scope]);
Loading history...
55
        }
56
57 2
        return array_keys($this->reporters['all']);
58
    }
59
}
60