Completed
Pull Request — master (#1)
by Márk
01:55
created

ResponseDecorator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withResponse() 0 7 1
A getStatusCode() 0 4 1
A withStatus() 0 7 1
A getReasonPhrase() 0 4 1
1
<?php
2
3
namespace Http\Message\Decorator;
4
5
use Psr\Http\Message\ResponseInterface;
6
7
/**
8
 * @author Márk Sági-Kazár <[email protected]>
9
 */
10
trait ResponseDecorator
11
{
12
    use MessageDecorator {
13
        getMessage as getResponse;
14
    }
15
16
    /**
17
     * Exchanges the underlying response with another.
18
     *
19
     * @param ResponseInterface $response
20
     *
21
     * @return self
22
     */
23 1
    public function withResponse(ResponseInterface $response)
24
    {
25 1
        $new = clone $this;
26 1
        $new->message = $response;
27
28 1
        return $new;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    public function getStatusCode()
35
    {
36 1
        return $this->message->getStatusCode();
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 1
    public function withStatus($code, $reasonPhrase = '')
43
    {
44 1
        $new = clone $this;
45 1
        $new->message = $this->message->withStatus($code, $reasonPhrase);
46
47 1
        return $new;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 1
    public function getReasonPhrase()
54
    {
55 1
        return $this->message->getReasonPhrase();
56
    }
57
}
58