Test Failed
Push — master ( 3e1f63...b2d2e1 )
by Vladimir
04:38
created

ApiInfoTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 35
dl 0
loc 61
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkInfoListAction() 0 23 3
A tagInfoListAction() 0 19 3
A groupInfoListAction() 0 11 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\Exception\HttpException;
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
 * @property RunnerManager   $runnerManager
22
 * @property ReporterManager $reporterManager
23
 *
24
 * @author Vladimir Turnaev <[email protected]>
25
 */
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...
26
trait ApiInfoTrait
27
{
28
    public function checkInfoListAction(Request $request): JsonResponse
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function checkInfoListAction()
Loading history...
29
    {
30
        try {
31
            list($checks, $groups, $tags) = $this->getFilterParams($request);
0 ignored issues
show
Bug introduced by
It seems like getFilterParams() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

31
            /** @scrutinizer ignore-call */ 
32
            list($checks, $groups, $tags) = $this->getFilterParams($request);
Loading history...
32
33
            $checks = $this->runnerManager->findChecks($checks, $groups, $tags);
34
35
            $data = [];
36
            foreach ($checks as $check) {
37
                $tags = $check->getTags();
38
39
                $d = ['check' => $check->getId(), 'label' => $check->getLabel(), 'group' => $check->getGroup(), 'tags' => $tags, 'Descr' => $check->getDescr()];
40
                $d = array_filter($d, static function ($v) {
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...
41
                    return !empty($v);
42
                });
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...
43
                $data[] = $d;
44
            }
45
46
            return new JsonResponse($data);
47
        } catch (\Exception $e) {
48
            $e = new HttpException(500, $e->getMessage());
49
50
            return new JsonResponse($e->toArray(), $e->getStatusCode());
51
        }
52
    }
53
54
    public function groupInfoListAction(Request $request): JsonResponse
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function groupInfoListAction()
Loading history...
55
    {
56
        try {
57
            list($_, $groups, $_) = $this->getFilterParams($request);
58
            $groups = $this->runnerManager->findGroups($groups);
59
60
            return new JsonResponse($groups);
61
        } catch (\Exception $e) {
62
            $e = new HttpException(500, $e->getMessage());
63
64
            return new JsonResponse($e->toArray(), $e->getStatusCode());
65
        }
66
    }
67
68
    public function tagInfoListAction(Request $request): JsonResponse
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function tagInfoListAction()
Loading history...
69
    {
70
        try {
71
            try {
72
                list($_, $_, $tags) = $this->getFilterParams($request);
73
                $tags = $this->runnerManager->findTags($tags);
74
v($tags);
0 ignored issues
show
Bug introduced by
The function v was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

74
/** @scrutinizer ignore-call */ 
75
v($tags);
Loading history...
Coding Style introduced by
Line indented incorrectly; expected at least 16 spaces, found 0
Loading history...
75
                exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\JsonResponse. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
76
                return new JsonResponse($tags);
0 ignored issues
show
Unused Code introduced by
return new Symfony\Compo...ion\JsonResponse($tags) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
77
78
            } catch (\Exception $e) {
79
                $e = new HttpException(500, $e->getMessage());
80
81
                return new JsonResponse($e->toArray(), $e->getStatusCode());
82
            }
83
        } catch (\Exception $e) {
84
            $e = new HttpException(500, $e->getMessage());
85
86
            return new JsonResponse($e->toArray(), $e->getStatusCode());
87
        }
88
    }
89
}
90