Passed
Push — master ( 50f32f...624c72 )
by Vladimir
05:02
created

ApiController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
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\JsonResponse;
15
use Symfony\Component\HttpFoundation\Request;
16
use Tvi\MonitorBundle\Reporter\Api;
17
use Tvi\MonitorBundle\Reporter\ReporterManager;
18
use Tvi\MonitorBundle\Runner\RunnerManager;
19
20
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
21
 * @author Vladimir Turnaev <[email protected]>
22
 */
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...
23
class ApiController
24
{
25
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
26
     * @var RunnerManager
27
     */
28
    protected $runnerManager;
29
30
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @var ReporterManager
32
     */
33
    protected $reporterManager;
34
35
    public function __construct(RunnerManager $runnerManager, ReporterManager $reporterManager)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
36
    {
37
        $this->runnerManager = $runnerManager;
38
        $this->reporterManager = $reporterManager;
39
    }
40
41
    public function testAction(Request $request)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testAction()
Loading history...
42
    {
43
        $check = $request->get('check', []);
44
        if (\is_string($check)) {
45
            $check = $check ? [$check] : [];
46
        }
47
48
        $groups = $request->get('group', []);
49
        if (\is_string($groups)) {
50
            $groups = $groups ? [$groups] : [];
51
        }
52
53
        $tags = $request->get('tag', []);
54
        if (\is_string($tags)) {
55
            $tags = $tags ? [$tags] : [];
56
        }
57
58
        $runner = $this->runnerManager->getRunner($check, $groups, $tags);
59
        /** @var $reporter Api */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
60
        $reporter = $this->reporterManager->getReporter('api');
61
62
        $runner->addReporter($reporter);
63
        $runner->run();
64
65
        return new JsonResponse([
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...
66
            'statusCode' => $reporter->getStatusCode(),
67
            'statusName' => $reporter->getStatusName(),
68
69
            'successes' => $reporter->getSuccessCount(),
70
            'warnings' => $reporter->getWarningCount(),
71
            'failures' => $reporter->getFailureCount(),
72
            'unknowns' => $reporter->getUnknownCount(),
73
            'total' => $reporter->getTotalCount(),
74
75
            'checks' => $reporter->getCheckResults(),
76
        ]);
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...
77
78
//        v($reporter->getResults());
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
79
//        exit;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
80
//        $number = random_int(0, 100);
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
81
//
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
82
//        return new Response(
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
83
//            '<html><body>Lucky number: '.$number.'</body></html>'
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
84
//        );
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
85
    }
86
}
87