AbstractController::sendResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Controller\Communication\Controller;
6
7
8
use Symfony\Component\HttpFoundation\Response;
9
use Xervice\Controller\Business\Model\Provider\KernelBridgeInterface;
10
use Xervice\Core\Plugin\AbstractCommunicationPlugin;
11
use Xervice\Kernel\Business\Plugin\ClearServiceInterface;
12
13
abstract class AbstractController extends AbstractCommunicationPlugin
14
{
15
    /**
16
     * @var \Xervice\Controller\Business\Model\Provider\KernelBridgeInterface
17
     */
18
    private $kernel;
19
20
    /**
21
     * @param \Xervice\Controller\Business\Model\Provider\KernelBridgeInterface $kernel
22
     */
23 5
    public function setKernel(KernelBridgeInterface $kernel): void
24
    {
25 5
        $this->kernel = $kernel;
26 5
    }
27
28
    /**
29
     * @param string $serviceName
30
     *
31
     * @return \Xervice\Kernel\Business\Plugin\ClearServiceInterface|null
32
     */
33
    protected function getService(string $serviceName): ?ClearServiceInterface
34
    {
35
        return $this->kernel->getService($serviceName);
36
    }
37
38
    /**
39
     * @param string $content
40
     * @param int $status
41
     * @param array $header
42
     *
43
     * @return \Symfony\Component\HttpFoundation\Response
44
     * @throws \InvalidArgumentException
45
     */
46 4
    protected function sendResponse(
47
        string $content,
48
        int $status = 200,
49
        array $header = []
50
    ): Response
51
    {
52 4
        return new Response(
53 4
            $content,
54 4
            $status,
55 4
            $header
56
        );
57
    }
58
}