ResourceDoResponse   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 38
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getContent() 0 4 1
A setContent() 0 4 1
A __construct() 0 6 1
A createBody() 0 6 1
1
<?php
2
namespace Staticus\Diactoros\Response;
3
4
use Staticus\Resources\ResourceDOInterface;
5
use Zend\Diactoros\Response;
6
use Zend\Diactoros\Stream;
7
8
class ResourceDoResponse extends Response implements ResourceDoResponseInterface
9
{
10
    /**
11
     * @var ResourceDOInterface
12
     */
13
    protected $content;
14
15
    public function getContent()
16
    {
17
        return $this->content;
18
    }
19
20
    public function setContent(ResourceDOInterface $content)
21
    {
22
        $this->content = $content;
23
    }
24
25
    /**
26
     * Create an empty response with the given status code and attached resource.
27
     *
28
     * @param ResourceDOInterface $resource
29
     * @param int $status Status code for the response, if any.
30
     * @param array $headers Headers for the response, if any.
31
     */
32
    public function __construct(ResourceDOInterface $resource, $status = 204, array $headers = [])
33
    {
34
        $this->setContent($resource);
35
        $body = $this->createBody();
36
        parent::__construct($body, $status, $headers);
37
    }
38
39
    protected function createBody()
40
    {
41
        $stream = new Stream('php://temp', 'r');
42
43
        return $stream;
44
    }
45
}
46