Response::setPrevious()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
c 1
b 1
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace XoopsModules\Wggithub\Github\Http;
4
5
use XoopsModules\Wggithub\Github;
6
7
8
/**
9
 * HTTP response envelope.
10
 *
11
 * @author  Miloslav Hůla (https://github.com/milo)
12
 */
13
class Response extends Message
14
{
15
    /** HTTP 1.1 code */
16
    const
17
        S200_OK = 200,
18
        S301_MOVED_PERMANENTLY = 301,
19
        S302_FOUND = 302,
20
        S304_NOT_MODIFIED = 304,
21
        S307_TEMPORARY_REDIRECT = 307,
22
        S400_BAD_REQUEST = 400,
23
        S401_UNAUTHORIZED = 401,
24
        S403_FORBIDDEN = 403,
25
        S404_NOT_FOUND = 404,
26
        S422_UNPROCESSABLE_ENTITY = 422;
27
28
    /** @var int */
29
    private $code;
30
31
    /** @var Response */
32
    private $previous;
33
34
35
    /**
36
     * @param  int
37
     * @param  array
38
     * @param  string
39
     */
40
    public function __construct($code, array $headers, $content)
41
    {
42
        $this->code = (int) $code;
43
        parent::__construct($headers, $content);
44
    }
45
46
47
    /**
48
     * HTTP code.
49
     * @return int
50
     */
51
    public function getCode()
52
    {
53
        return $this->code;
54
    }
55
56
57
    /**
58
     * @param  int
59
     * @return bool
60
     */
61
    public function isCode($code)
62
    {
63
        return $this->code === (int) $code;
64
    }
65
66
67
    /**
68
     * @return Response|NULL
69
     */
70
    public function getPrevious()
71
    {
72
        return $this->previous;
73
    }
74
75
76
    /**
77
     * @param Response|null $previous
78
     * @return self
79
     *
80
     */
81
    public function setPrevious(Response $previous = NULL)
82
    {
83
        if ($this->previous) {
84
            throw new Github\LogicException('Previous response is already set.');
85
        }
86
        $this->previous = $previous;
87
88
        return $this;
89
    }
90
91
}
92