Passed
Push — master ( e2d202...250565 )
by Vsevolods
03:00
created

AbstractResponder::empty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Adr;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\UriInterface;
7
use Venta\Contracts\Adr\Responder as ResponderContract;
8
use Venta\Contracts\Http\ResponseFactory;
9
use Venta\Contracts\Http\ResponseFactoryAware;
10
use Zend\Diactoros\Response\JsonResponse;
11
12
/**
13
 * Class AbstractResponder
14
 *
15
 * @package Venta\Adr
16
 */
17
abstract class AbstractResponder implements ResponderContract, ResponseFactoryAware
18
{
19
    /**
20
     * @var ResponseFactory
21
     */
22
    private $responseFactory;
23
24
    /**
25
     * @inheritDoc
26
     */
27
    public function setResponseFactory(ResponseFactory $factory)
28
    {
29
        $this->responseFactory = $factory;
30
    }
31
32
    protected function empty($status = 204, array $headers = [])
33
    {
34
        return $this->responseFactory->createEmptyResponse($status, $headers);
35
    }
36
37
    /**
38
     * Creates html response.
39
     *
40
     * @param string $html
41
     * @param int $status
42
     * @param array $headers
43
     * @return ResponseInterface
44
     */
45
    protected function html(string $html, int $status = 200, array $headers = []): ResponseInterface
46
    {
47
        return $this->responseFactory->createHtmlResponse($html, $status, $headers);
48
    }
49
50
    /**
51
     * Creates HTTP response with JSON content type header and JSON encoded $data.
52
     *
53
     * @param mixed $data Data to convert to JSON.
54
     * @param int $status Integer status code for the response; 200 by default.
55
     * @param array $headers Array of headers to use at initialization.
56
     * @param int $jsonFlag JSON encoding options to use.
0 ignored issues
show
Bug introduced by
There is no parameter named $jsonFlag. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
57
     * @return ResponseInterface
58
     */
59
    protected function json(
60
        $data,
61
        int $status = 200,
62
        array $headers = [],
63
        int $encodingOptions = JsonResponse::DEFAULT_JSON_FLAGS
64
    ): ResponseInterface {
65
        return $this->responseFactory->createJsonResponse($data, $status, $headers, $encodingOptions);
66
    }
67
68
    /**
69
     * Creates HTTP redirect response with $uri used as Location header.
70
     *
71
     * @param string|UriInterface $uri
72
     * @param int $status
73
     * @param array $headers
74
     * @return ResponseInterface
75
     */
76
    protected function redirect($uri, $status = 302, array $headers = []): ResponseInterface
77
    {
78
        return $this->responseFactory->createRedirectResponse($uri, $status, $headers);
79
    }
80
81
    /**
82
     * Creates HTTP response.
83
     *
84
     * @param string $bodyStream Stream to use as response body.
85
     * @param int $status
86
     * @param array $headers
87
     * @return ResponseInterface
88
     */
89
    protected function response($bodyStream = 'php://memory', int $status = 200, array $headers = []): ResponseInterface
90
    {
91
        return $this->responseFactory->createResponse($bodyStream, $status, $headers);
92
    }
93
}