Completed
Pull Request — dev (#11)
by
unknown
04:51
created

AbstractResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Vectorface\SnappyRouter\Response;
4
5
/**
6
 * An abstract class that defines a basic constructor for the response as well
7
 * as the required methods the implementation requires.
8
 * @copyright Copyright (c) 2014, VectorFace, Inc.
9
 * @author Dan Bruce <[email protected]>
10
 */
11
abstract class AbstractResponse implements ResponseInterface
12
{
13
    /** HTTP response code for OK */
14
    const RESPONSE_OK = 200;
15
    /** HTTP response code for a bad request */
16
    const RESPONSE_BAD_REQUEST = 400;
17
    /** HTTP response code for unauthorized */
18
    const RESPONSE_UNAUTHORIZED = 401;
19
    /** HTTP response code for forbidden */
20
    const RESPONSE_FORBIDDEN = 403;
21
    /** HTTP response code for not found */
22
    const RESPONSE_NOT_FOUND = 404;
23
    /** HTTP response code for method not allowed */
24
    const RESPONSE_METHOD_NOT_ALLOWED = 405;
25
    /** HTTP response code for too many requests in a period of time
26
     *  See: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#429 */
27
    const RESPONSE_RATE_LIMITED = 429;
28
    /** HTTP response code for a server error */
29
    const RESPONSE_SERVER_ERROR = 500;
30
    /** HTTP response code for server unavailable */
31
    const RESPONSE_SERVICE_UNAVAILABLE = 503;
32
33
    /**
34
     * Constructor for the response.
35
     * @param mixed $responseObject A response object that can be serialized to a string.
36
     * @param int $statusCode The HTTP response.
37
     */
38 23
    public function __construct($responseObject, $statusCode = self::RESPONSE_OK)
39
    {
40 23
        $this->setResponseObject($responseObject);
41 23
        $this->setStatusCode($statusCode);
42 23
    }
43
}
44