Response   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 0
dl 0
loc 125
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A content() 0 4 1
A contentType() 0 4 1
A headerLine() 0 12 2
A headerLines() 0 4 1
A error() 0 4 1
A errorCode() 0 4 1
A statusCode() 0 4 1
A convertIntoAnArray() 0 10 1
1
<?php
2
/**
3
 * @author: stev leibelt <[email protected]>
4
 * @since: 2015-12-09
5
 */
6
7
namespace Net\Bazzline\Component\Curl\Response;
8
9
use InvalidArgumentException;
10
11
class Response
12
{
13
    const ARRAY_KEY_CONTENT         = 'content';
14
    const ARRAY_KEY_CONTENT_TYPE    = 'content_type';
15
    const ARRAY_KEY_ERROR           = 'error';
16
    const ARRAY_KEY_ERROR_CODE      = 'error_code';
17
    const ARRAY_KEY_STATUS_CODE     = 'status_code';
18
19
    /** @var null|mixed */
20
    private $content;
21
22
    /** @var null|string */
23
    private $contentType;
24
25
    /** @var null|string */
26
    private $error;
27
28
    /** @var null|int */
29
    private $errorCode;
30
31
    /** @var array */
32
    private $headerLines;
33
34
    /** @var null|int */
35
    private $statusCode;
36
37
    /**
38
     * @param mixed $content
39
     * @param string $contentType
40
     * @param string $error
41
     * @param int $errorCode
42
     * @param array $headerLines
43
     * @param int $statusCode
44
     */
45
    public function __construct($content, $contentType, $error, $errorCode, array $headerLines, $statusCode)
46
    {
47
        $this->content      = $content;
48
        $this->contentType  = $contentType;
49
        $this->error        = $error;
50
        $this->errorCode    = $errorCode;
51
        $this->headerLines  = $headerLines;
52
        $this->statusCode   = $statusCode;
53
    }
54
55
    /**
56
     * @return null|mixed
57
     */
58
    public function content()
59
    {
60
        return $this->content;
61
    }
62
63
    /**
64
     * @return null|string
65
     */
66
    public function contentType()
67
    {
68
        return $this->contentType;
69
    }
70
71
    /**
72
     * @param string $prefix
73
     * @return null|string
74
     * @throws InvalidArgumentException
75
     */
76
    public function headerLine($prefix)
77
    {
78
        $valueIsNotAvailable = (!isset($this->headerLines[$prefix]));
79
80
        if ($valueIsNotAvailable) {
81
            throw new InvalidArgumentException(
82
                'no headline available for prefix: "' . $prefix . '"'
83
            );
84
        }
85
86
        return $this->headerLines[$prefix];
87
    }
88
89
    /**
90
     * @return array
91
     */
92
    public function headerLines()
93
    {
94
        return $this->headerLines;
95
    }
96
97
    /**
98
     * @return null|string
99
     */
100
    public function error()
101
    {
102
        return $this->error;
103
    }
104
105
    /**
106
     * @return null|int
107
     * @see: http://curl.haxx.se/libcurl/c/libcurl-errors.html
108
     */
109
    public function errorCode()
110
    {
111
        return $this->errorCode;
112
    }
113
114
    /**
115
     * @return null|int
116
     */
117
    public function statusCode()
118
    {
119
        return $this->statusCode;
120
    }
121
122
    /**
123
     * @return array
124
     */
125
    public function convertIntoAnArray()
126
    {
127
        return [
128
                self::ARRAY_KEY_CONTENT         => $this->content,
129
                self::ARRAY_KEY_CONTENT_TYPE    => $this->contentType,
130
                self::ARRAY_KEY_ERROR           => $this->error,
131
                self::ARRAY_KEY_ERROR_CODE      => $this->errorCode,
132
                self::ARRAY_KEY_STATUS_CODE     => $this->statusCode
133
            ];
134
    }
135
}
136