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

ApiInfoCheckTrait::checkInfosAction()   A

Complexity

Conditions 2
Paths 6

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 6
nop 1
crap 6
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 JMS\Serializer\Serializer;
17
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
18
use Tvi\MonitorBundle\Exception\HttpException;
19
use Tvi\MonitorBundle\Reporter\ReporterManager;
20
use Tvi\MonitorBundle\Runner\RunnerManager;
21
22
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
 * @property RunnerManager   $runnerManager
24
 * @property ReporterManager $reporterManager
25
 * @property Serializer      $serializer
26
 *
27
 * @author Vladimir Turnaev <[email protected]>
28
 */
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...
29
trait ApiInfoCheckTrait
30
{
31
    public function checkInfoAction(Request $request, $id): JsonResponse
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function checkInfoAction()
Loading history...
32
    {
33
        try {
34
            list($checks, $groups, $tags) = $this->getFilterParams($request);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This list assign is not used and could be removed.
Loading history...
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

34
            /** @scrutinizer ignore-call */ 
35
            list($checks, $groups, $tags) = $this->getFilterParams($request);
Loading history...
35
36
            $checks = $this->runnerManager->findChecks($id);
37
            if (1 === \count($checks)) {
38
                $check = current($checks);
39
                $json = $this->serializer->serialize($check, 'json');
40
41
                return JsonResponse::fromJsonString($json);
42
            }
43
44
            throw new NotFoundHttpException(sprintf('Check "%s" not found', $id));
45
        } catch (NotFoundHttpException $e) {
46
            $e = new HttpException(404, $e->getMessage());
47
            $json = $this->serializer->serialize($e->toArray(), 'json');
48
49
            return JsonResponse::fromJsonString($json, $e->getStatusCode());
50
        } catch (\Exception $e) {
51
            $e = new HttpException(500, $e->getMessage());
52
53
            $data = $this->serializer->serialize($e->toArray(), 'json');
54
55
            return JsonResponse::fromJsonString($data, $e->getStatusCode());
56
        }
57
    }
58
59
    public function checkInfosAction(Request $request): JsonResponse
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function checkInfosAction()
Loading history...
60
    {
61
        try {
62
            list($checks, $groups, $tags) = $this->getFilterParams($request);
63
64
            $checks = $this->runnerManager->findChecks($checks, $groups, $tags);
65
            $checks = array_values($checks);
66
            $json = $this->serializer->serialize($checks, 'json');
67
68
            return JsonResponse::fromJsonString($json);
69
        } catch (\Exception $e) {
70
            $e = new HttpException(500, $e->getMessage());
71
            $json = $this->serializer->serialize($e->toArray(), 'json');
72
73
            return JsonResponse::fromJsonString($json, $e->getStatusCode());
74
        }
75
    }
76
}
77