Completed
Push — master ( f8d07f...897034 )
by Vladimir
05:58
created

TraitApiCommon::__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 Symfony\Component\HttpFoundation\Response;
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
trait TraitApiCommon
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
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
36
     * @var Serializer
37
     */
38
    protected $serializer;
39
40 95
    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...
41
    {
42 95
        $this->runnerManager = $runnerManager;
43 95
        $this->reporterManager = $reporterManager;
44 95
        $this->serializer = $serializer;
45 95
    }
46
47 95
    protected function creatResponse($data = null, int $status = Response::HTTP_OK, bool $json = false, array $headers = []): Response
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function creatResponse()
Loading history...
48
    {
49 95
        if ($json && !\is_string($json)) {
50 61
            $data = $this->serializer->serialize($data, 'json');
51
        }
52
53 95
        if ($json) {
54 61
            $headers['Content-Type'] = 'application/json';
55
        }
56
57 95
        return new Response($data, $status, $headers);
58
    }
59
}
60