Completed
Push — master ( 18ad36...14c21a )
by Boris
15s
created

HttpClientCallbackMock::getStatusCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BWC\Share\Net\HttpClient;
4
5
use BWC\Share\Net\HttpStatusCode;
6
7
8
class HttpClientCallbackMock implements HttpClientInterface
9
{
10
    private $_timeout_ms = 10000;
11
12
    public $statusCode = HttpStatusCode::OK;
13
    public $header;
14
15
    public $callbackRequest;
16
17
18
    /**
19
     * @return int
20
     */
21
    function getTimeoutMS() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
22
        return $this->_timeout_ms;
23
    }
24
25
    /**
26
     * @param int $milliseconds
27
     * @return void
28
     */
29
    function setTimeoutMS($milliseconds) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
30
        $this->_timeout_ms = $milliseconds;
31
    }
32
33
    /**
34
     * @param $path
35
     * @return void
36
     */
37
    public function setCaPath($path)
38
    {
39
40
    }
41
42
    /**
43
     * @param $file
44
     * @return void
45
     */
46
    public function setCaFile($file)
47
    {
48
49
    }
50
51
52
    /**
53
     * @return int
54
     */
55
    function getStatusCode() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56
        return $this->statusCode;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    function getHeader() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
63
        return $this->header;
64
    }
65
66
67
    /**
68
     * @param string $username
69
     * @param string $password
70
     * @return void
71
     */
72
    function setCredentials($username, $password) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
73
        // TODO: Implement setCredentials() method.
74
    }
75
76
77
    /**
78
     * @param string $type   mime type for Accept http header, like text/xml or application/json
79
     * @return void
80
     */
81
    function accept($type) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
82
        // TODO: Implement accept() method.
83
    }
84
85
    /**
86
     * @param string $url
87
     * @param array $queryData
88
     * @param array $arrHeaders
89
     * @return string
90
     */
91
    function get($url, array $queryData = array(), array $arrHeaders = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
92
        $result = $this->request($url, 'GET', $queryData, null, null, $arrHeaders);
93
        return $result;
94
    }
95
96
    function post($url, array $queryData = array(), $postData, $contentType = null, array $arrHeaders = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
97
        $result = $this->request($url, 'POST', $queryData, $postData, $contentType, $arrHeaders);
0 ignored issues
show
Bug introduced by
It seems like $postData defined by parameter $postData on line 96 can also be of type object; however, BWC\Share\Net\HttpClient...CallbackMock::request() does only seem to accept array|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $contentType defined by parameter $contentType on line 96 can also be of type string; however, BWC\Share\Net\HttpClient...CallbackMock::request() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
98
        return $result;
99
    }
100
101
    /**
102
     * @param string $url
103
     * @param array $queryData
104
     * @param array $arrHeaders
105
     * @return string
106
     */
107
    function delete($url, array $queryData = array(), array $arrHeaders = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
108
        $result = $this->request($url, 'DELETE', $queryData, null, null, $arrHeaders);
109
        return $result;
110
    }
111
112
    /**
113
     * @param $url
114
     * @param $method
115
     * @param array $queryData
116
     * @param array|string $postData
117
     * @param null $contentType
118
     * @param array $arrHeaders
119
     * @return string
120
     */
121
    function request($url, $method, array $queryData, $postData, $contentType = null, array $arrHeaders = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
122
        if ($this->callbackRequest) {
123
            return call_user_func($this->callbackRequest, $this, $url, $method, $queryData, $postData, $contentType, $arrHeaders);
124
        } else {
125
            return '';
126
        }
127
    }
128
129
    /**
130
     * @param bool $value
131
     * @return void
132
     */
133
    public function looseSslCheck($value)
134
    {
135
        // TODO: Implement looseSslCheck() method.
136
    }
137
138
    /**
139
     * @return string
140
     */
141
    public function getErrorText()
142
    {
143
        // TODO: Implement getErrorText() method.
144
        return '';
145
    }
146
}
147