Response   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 52
ccs 3
cts 3
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomContent() 0 3 1
A getContent() 0 3 1
A setContent() 0 4 1
A setCustomContent() 0 5 1
A __construct() 0 9 2
1
<?php
2
3
namespace MediaMonks\RestApi\Response;
4
5
use Symfony\Component\HttpFoundation\Response as BaseResponse;
6
7
class Response extends BaseResponse implements
8
    ExtendedResponseInterface
9
{
10
    protected mixed $customContent;
11
12
    /**
13
     * @param mixed $data    The response data
14
     * @param int   $status  The response status code
15
     * @param array $headers An array of response headers
16
     * @param bool  $json    If the data is already a JSON string
17
     */
18 13
    public function __construct($data = null, int $status = 200, array $headers = [], bool $json = false)
0 ignored issues
show
Unused Code introduced by
The parameter $json is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

18
    public function __construct($data = null, int $status = 200, array $headers = [], /** @scrutinizer ignore-unused */ bool $json = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
    {
20 13
        parent::__construct('', $status, $headers);
21
22 13
        if (null === $data) {
23
            $data = new \ArrayObject();
24
        }
25
26
        $this->setCustomContent($data);
27
    }
28
29
    /**
30
     * Sets the response content.
31
     *
32
     * We need to allow all sorts of content, not just the ones the regular Response setContent() allows
33
     *
34
     * @param mixed $content
35
     * @return Response
36
     * @api
37
     */
38
    public function setCustomContent(mixed $content): static
39
    {
40
        $this->customContent = $content;
41
42
        return $this;
43
    }
44
45
    public function getCustomContent(): mixed
46
    {
47
        return $this->customContent;
48
    }
49
50
    public function setContent(?string $content): static
51
    {
52
        $this->customContent = $content;
53
        return parent::setContent($content);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::setContent($content) returns the type Symfony\Component\HttpFoundation\Response which includes types incompatible with the type-hinted return MediaMonks\RestApi\Response\Response.
Loading history...
54
    }
55
56
    public function getContent(): string|false
57
    {
58
        return serialize($this->customContent);
59
    }
60
}
61