Completed
Push — master ( 8cfc77...3ca914 )
by Vladimir
06:29
created

ApiInitTrait::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
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\Controller;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use JMS\Serializer\Serializer;
16
use Tvi\MonitorBundle\Reporter\ReporterManager;
17
use Tvi\MonitorBundle\Runner\RunnerManager;
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
trait ApiInitTrait
23
{
24
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
     * @var RunnerManager
26
     */
27
    protected $runnerManager;
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @var ReporterManager
31
     */
32
    protected $reporterManager;
33
34
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
35
     * @var Serializer
36
     */
37
    protected $serializer;
38
39 51
    public function __construct(RunnerManager $runnerManager, ReporterManager $reporterManager, Serializer $serializer)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
40
    {
41 51
        $this->runnerManager = $runnerManager;
42 51
        $this->reporterManager = $reporterManager;
43 51
        $this->serializer = $serializer;
44 51
    }
45
46
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $request should have a doc-comment as per coding-style.
Loading history...
47
     * return array [$checks, $groups, $tags].
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
48
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
49 28
    protected function getFilterParams(Request $request): array
50
    {
51 28
        $checks = $request->get('check', []);
52 28
        if (\is_scalar($checks)) {
53 3
            $checks = $checks ? [$checks] : [];
54
        }
55 28
        $checks = !\is_array($checks) ? [$checks] : $checks;
56
57 28
        $groups = $request->get('group', []);
58 28
        if (\is_scalar($groups)) {
59 8
            $groups = $groups ? [$groups] : [];
60
        }
61 28
        $groups = !\is_array($groups) ? [$groups] : $groups;
62
63 28
        $tags = $request->get('tag', []);
64 28
        if (\is_scalar($tags)) {
65 4
            $tags = $tags ? [$tags] : [];
66
        }
67 28
        $tags = !\is_array($tags) ? [$tags] : $tags;
68
69 28
        return [$checks, $groups, $tags];
70
    }
71
72
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $request should have a doc-comment as per coding-style.
Loading history...
73
     * return array.
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
74
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
75
    protected function getFilterIds(Request $request): array
76
    {
77
        $id = $request->get('id', []);
78
        if (\is_scalar($id)) {
79
            $id = $id ? [$id] : [];
80
        }
81
82
        return !\is_array($id) ? [$id] : $id;
83
    }
84
}
85