Issues (2921)

src/Controller/TraitApiCommon.php (16 issues)

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
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
Missing @link tag in file comment
Loading history...
11
12
namespace Tvi\MonitorBundle\Controller;
13
14
use JMS\Serializer\Serializer;
15
use Symfony\Component\HttpFoundation\Response;
16
use Tvi\MonitorBundle\Reporter\ReporterManager;
17
use Tvi\MonitorBundle\Runner\RunnerManager;
18
19
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
20
 * @author Vladimir Turnaev <[email protected]>
21
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @package tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
22
trait TraitApiCommon
23
{
24
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
25
     * @var RunnerManager
26
     */
27
    protected $runnerManager;
28
29
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
30
     * @var ReporterManager
31
     */
32
    protected $reporterManager;
33
34
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
35
     * @var Serializer
36
     */
37
    protected $serializer;
38
39 95
    public function __construct(RunnerManager $runnerManager, ReporterManager $reporterManager, Serializer $serializer)
0 ignored issues
show
Missing doc comment for function __construct()
Loading history...
40
    {
41 95
        $this->runnerManager = $runnerManager;
42 95
        $this->reporterManager = $reporterManager;
43 95
        $this->serializer = $serializer;
44 95
    }
45
46 95
    protected function creatResponse($data = null, int $status = Response::HTTP_OK, bool $json = false, array $headers = []): Response
0 ignored issues
show
Missing doc comment for function creatResponse()
Loading history...
47
    {
48 95
        if ($json && !\is_string($json)) {
49 61
            $data = $this->serializer->serialize($data, 'json');
50
        }
51
52 95
        if ($json) {
53 61
            $headers['Content-Type'] = 'application/json';
54
        }
55
56 95
        return new Response($data, $status, $headers);
57
    }
58
}
59