ResponseFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 6
dl 0
loc 55
ccs 12
cts 28
cp 0.4286
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createEmptyResponse() 0 4 1
A createHtmlResponse() 0 4 1
A createJsonResponse() 0 9 1
A createRedirectResponse() 0 4 1
A createResponse() 0 4 1
A createTextResponse() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Http;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Venta\Contracts\Http\ResponseFactory as ResponseFactoryContract;
7
use Zend\Diactoros\Response;
8
use Zend\Diactoros\Response\EmptyResponse;
9
use Zend\Diactoros\Response\HtmlResponse;
10
use Zend\Diactoros\Response\JsonResponse;
11
use Zend\Diactoros\Response\RedirectResponse;
12
use Zend\Diactoros\Response\TextResponse;
13
14
/**
15
 * Class ResponseFactory
16
 *
17
 * @package Venta\Http
18
 */
19
final class ResponseFactory implements ResponseFactoryContract
20
{
21
    /**
22
     * @inheritDoc
23
     */
24 2
    public function createEmptyResponse($status = 204, array $headers = []): ResponseInterface
25
    {
26 2
        return new EmptyResponse($status, $headers);
27
    }
28
29
    /**
30
     * @inheritDoc
31
     */
32 1
    public function createHtmlResponse(string $html, int $status = 200, array $headers = []): ResponseInterface
33
    {
34 1
        return new HtmlResponse($html, $status, $headers);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function createJsonResponse(
41
        $data,
42
        int $status = 200,
43
        array $headers = [],
44
        int $encodingOptions = ResponseFactoryContract::JSON_FLAG
45
    ): ResponseInterface {
46
47 1
        return new JsonResponse($data, $status, $headers, $encodingOptions);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 2
    public function createRedirectResponse($uri, int $status = 302, array $headers = []): ResponseInterface
54
    {
55 2
        return new RedirectResponse($uri, $status, $headers);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 1
    public function createResponse($body = 'php://memory', int $status = 200, array $headers = []): ResponseInterface
62
    {
63 1
        return new Response($body, $status, $headers);
64
    }
65
66
    /**
67
     * @inheritDoc
68
     */
69 1
    public function createTextResponse($text, $status = 200, array $headers = []): ResponseInterface
70
    {
71 1
        return new TextResponse($text, $status, $headers);
72
    }
73
}