TraitApiInfoCheck   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 20
dl 0
loc 34
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkInfosAction() 0 12 3
A checkInfoAction() 0 17 4
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 Symfony\Component\HttpFoundation\Response;
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 TraitApiInfoCheck
30
{
31 4
    public function checkInfoAction(Request $request, $id, string $version): Response
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

31
    public function checkInfoAction(/** @scrutinizer ignore-unused */ Request $request, $id, string $version): Response

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $version is not used and could be removed. ( Ignorable by Annotation )

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

31
    public function checkInfoAction(Request $request, $id, /** @scrutinizer ignore-unused */ string $version): Response

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Missing doc comment for function checkInfoAction()
Loading history...
32
    {
33
        try {
34 4
            $checks = $this->runnerManager->findChecks($id);
35 3
            if (1 === \count($checks)) {
36 2
                $check = current($checks);
37
38 2
                return $this->creatResponse($check, Response::HTTP_OK, true);
0 ignored issues
show
Bug introduced by
It seems like creatResponse() 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

38
                return $this->/** @scrutinizer ignore-call */ creatResponse($check, Response::HTTP_OK, true);
Loading history...
39
            }
40
41 1
            throw new NotFoundHttpException(sprintf('Check "%s" not found', $id));
42 2
        } catch (NotFoundHttpException $e) {
43 1
            $e = new HttpException($e->getStatusCode(), $e->getMessage());
44
45 1
            return $this->creatResponse($e->toArray(), $e->getStatusCode(), true);
46 1
        } catch (\Exception $e) {
47 1
            return $this->creatResponse($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
48
        }
49
    }
50
51 8
    public function checkInfosAction(Request $request, string $version): Response
0 ignored issues
show
Unused Code introduced by
The parameter $version is not used and could be removed. ( Ignorable by Annotation )

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

51
    public function checkInfosAction(Request $request, /** @scrutinizer ignore-unused */ string $version): Response

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Missing doc comment for function checkInfosAction()
Loading history...
52
    {
53
        try {
54 8
            list($ids, $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

54
            /** @scrutinizer ignore-call */ 
55
            list($ids, $checks, $groups, $tags) = $this->getFilterParams($request);
Loading history...
55 8
            $checks = $checks ? $checks : $ids;
56
57 8
            $checks = $this->runnerManager->findChecks($checks, $groups, $tags);
58 7
            $checks = array_values($checks);
59
60 7
            return $this->creatResponse($checks, Response::HTTP_OK, true);
61 1
        } catch (\Exception $e) {
62 1
            return $this->creatResponse($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
63
        }
64
    }
65
}
66