ManualResponse::getHeader()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 1
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 6
rs 10
1
<?php
2
/**
3
 * ActiveRecord for API
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart
6
 * @package   yii2-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\hiart\curl;
12
13
use hiqdev\hiart\AbstractRequest;
14
use hiqdev\hiart\AbstractResponse;
15
16
/**
17
 * For creating response manually.
18
 */
19
class ManualResponse extends AbstractResponse
20
{
21
    /**
22
     * @var mixed
23
     */
24
    protected $data;
25
26
    /**
27
     * @var array[]
28
     */
29
    protected $headers = [];
30
31
    /**
32
     * @var string
33
     */
34
    protected $statusCode;
35
36
    /**
37
     * @var string
38
     */
39
    protected $reasonPhrase;
40
41
    /**
42
     * @param AbstractRequest $request
43
     * @param mixed $data
44
     * @param array $headers
45
     * @param string $statusCode
46
     * @param string $reasonPhrase
47
     */
48
    public function __construct(RequestInterface $request, $data, array $headers = [], $statusCode = null, $reasonPhrase = null)
0 ignored issues
show
Bug introduced by
The type hiqdev\hiart\curl\RequestInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
    {
50
        $this->request = $request;
51
        $this->data = $data;
52
        $this->headers = $headers;
53
        $this->statusCode = $statusCode;
54
        $this->reasonPhrase = $reasonPhrase;
55
    }
56
57
    /**
58
     * @return mixed
59
     */
60
    public function getData()
61
    {
62
        return $this->data;
63
    }
64
65
    /**
66
     * @return mixed
67
     */
68
    public function getRawData()
69
    {
70
        return $this->data;
71
    }
72
73
    /**
74
     * @param string $name the header name
75
     * @return array|null
76
     */
77
    public function getHeader($name)
78
    {
79
        return isset($this->headers[strtolower($name)]) ? $this->headers[strtolower($name)] : null;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function getStatusCode()
86
    {
87
        return $this->statusCode;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getReasonPhrase()
94
    {
95
        return $this->reasonPhrase;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->reasonPhrase returns the type string which is incompatible with the return type mandated by hiqdev\hiart\ResponseInterface::getReasonPhrase() of hiqdev\hiart\ResponseInterface.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
96
    }
97
98
    /**
99
     * Returns array of all headers.
100
     * Key - Header name
101
     * Value - array of header values. For example:.
102
     *
103
     * ```php
104
     * ['Location' => ['http://example.com'], 'Expires' => ['Thu, 01 Jan 1970 00:00:00 GMT']]
105
     * @return array
106
     */
107
    public function getHeaders()
108
    {
109
        return $this->headers;
110
    }
111
}
112