Completed
Push — master ( 90448b...2ebf44 )
by Vladimir
05:45 queued 30s
created

ApiCommonTrait::__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 ApiCommonTrait
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 60
    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 60
        $this->runnerManager = $runnerManager;
42 60
        $this->reporterManager = $reporterManager;
43 60
        $this->serializer = $serializer;
44 60
    }
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 [$ids, $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 34
    protected function getFilterParams(Request $request): array
50
    {
51 34
        $id = $request->get('id', []);
52 34
        if (\is_scalar($id)) {
53 4
            $id = $id ? [$id] : [];
54
        }
55
56 34
        $ids = !\is_array($id) ? [$id] : $id;
57
58 34
        $checks = $request->get('check', []);
59 34
        if (\is_scalar($checks)) {
60 3
            $checks = $checks ? [$checks] : [];
61
        }
62 34
        $checks = !\is_array($checks) ? [$checks] : $checks;
63
64 34
        $groups = $request->get('group', []);
65 34
        if (\is_scalar($groups)) {
66 8
            $groups = $groups ? [$groups] : [];
67
        }
68 34
        $groups = !\is_array($groups) ? [$groups] : $groups;
69
70 34
        $tags = $request->get('tag', []);
71 34
        if (\is_scalar($tags)) {
72 4
            $tags = $tags ? [$tags] : [];
73
        }
74 34
        $tags = !\is_array($tags) ? [$tags] : $tags;
75
76 34
        return [$ids, $checks, $groups, $tags];
77
    }
78
}
79