Skip to content

Commit bacf006

Browse files
committed
:octocat: +backslashes for built-in functions
1 parent b8ac9d8 commit bacf006

18 files changed

+258
-261
lines changed

src/HTTPOptionsTrait.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ trait HTTPOptionsTrait{
6565
*/
6666
protected function HTTPOptionsTrait():void{
6767

68-
if(!is_array($this->curl_options)){
68+
if(!\is_array($this->curl_options)){
6969
$this->curl_options = [];
7070
}
7171

72-
if(!is_string($this->user_agent) || empty(trim($this->user_agent))){
72+
if(!\is_string($this->user_agent) || empty(\trim($this->user_agent))){
7373
throw new ClientException('invalid user agent');
7474
}
7575

@@ -83,69 +83,69 @@ protected function HTTPOptionsTrait():void{
8383
protected function setCA():void{
8484

8585
// disable verification if wanted so
86-
if($this->ssl_verifypeer !== true || (isset($this->curl_options[CURLOPT_SSL_VERIFYPEER]) && !$this->curl_options[CURLOPT_SSL_VERIFYPEER])){
87-
unset($this->curl_options[CURLOPT_CAINFO], $this->curl_options[CURLOPT_CAPATH]);
86+
if($this->ssl_verifypeer !== true || (isset($this->curl_options[\CURLOPT_SSL_VERIFYPEER]) && !$this->curl_options[\CURLOPT_SSL_VERIFYPEER])){
87+
unset($this->curl_options[\CURLOPT_CAINFO], $this->curl_options[\CURLOPT_CAPATH]);
8888

89-
$this->curl_options[CURLOPT_SSL_VERIFYHOST] = 0;
90-
$this->curl_options[CURLOPT_SSL_VERIFYPEER] = false;
89+
$this->curl_options[\CURLOPT_SSL_VERIFYHOST] = 0;
90+
$this->curl_options[\CURLOPT_SSL_VERIFYPEER] = false;
9191

9292
return;
9393
}
9494

95-
$this->curl_options[CURLOPT_SSL_VERIFYHOST] = 2;
96-
$this->curl_options[CURLOPT_SSL_VERIFYPEER] = true;
95+
$this->curl_options[\CURLOPT_SSL_VERIFYHOST] = 2;
96+
$this->curl_options[\CURLOPT_SSL_VERIFYPEER] = true;
9797

9898
// a path/dir/link to a CA bundle is given, let's check that
99-
if(is_string($this->ca_info)){
99+
if(\is_string($this->ca_info)){
100100

101101
// if you - for whatever obscure reason - need to check Windows .lnk links,
102102
// see http://php.net/manual/en/function.is-link.php#91249
103103
switch(true){
104-
case is_dir($this->ca_info):
105-
case is_link($this->ca_info) && is_dir(readlink($this->ca_info)): // @codeCoverageIgnore
106-
$this->curl_options[CURLOPT_CAPATH] = $this->ca_info;
107-
unset($this->curl_options[CURLOPT_CAINFO]);
104+
case \is_dir($this->ca_info):
105+
case \is_link($this->ca_info) && \is_dir(\readlink($this->ca_info)): // @codeCoverageIgnore
106+
$this->curl_options[\CURLOPT_CAPATH] = $this->ca_info;
107+
unset($this->curl_options[\CURLOPT_CAINFO]);
108108
return;
109109

110-
case is_file($this->ca_info):
111-
case is_link($this->ca_info) && is_file(readlink($this->ca_info)): // @codeCoverageIgnore
112-
$this->curl_options[CURLOPT_CAINFO] = $this->ca_info;
113-
unset($this->curl_options[CURLOPT_CAPATH]);
110+
case \is_file($this->ca_info):
111+
case \is_link($this->ca_info) && \is_file(\readlink($this->ca_info)): // @codeCoverageIgnore
112+
$this->curl_options[\CURLOPT_CAINFO] = $this->ca_info;
113+
unset($this->curl_options[\CURLOPT_CAPATH]);
114114
return;
115115
}
116116

117117
throw new ClientException('invalid path to SSL CA bundle (HTTPOptions::$ca_info): '.$this->ca_info);
118118
}
119119

120120
// we somehow landed here, so let's check if there's a CA bundle given via the cURL options
121-
$ca = $this->curl_options[CURLOPT_CAPATH] ?? $this->curl_options[CURLOPT_CAINFO] ?? false;
121+
$ca = $this->curl_options[\CURLOPT_CAPATH] ?? $this->curl_options[\CURLOPT_CAINFO] ?? false;
122122

123123
if($ca){
124124

125125
// just check if the file/path exists
126126
switch(true){
127-
case is_dir($ca):
128-
case is_link($ca) && is_dir(readlink($ca)): // @codeCoverageIgnore
129-
unset($this->curl_options[CURLOPT_CAINFO]);
127+
case \is_dir($ca):
128+
case \is_link($ca) && \is_dir(\readlink($ca)): // @codeCoverageIgnore
129+
unset($this->curl_options[\CURLOPT_CAINFO]);
130130
return;
131131

132-
case is_file($ca):
133-
case is_link($ca) && is_file(readlink($ca)): // @codeCoverageIgnore
132+
case \is_file($ca):
133+
case \is_link($ca) && \is_file(\readlink($ca)): // @codeCoverageIgnore
134134
return;
135135
}
136136

137137
throw new ClientException('invalid path to SSL CA bundle (CURLOPT_CAPATH/CURLOPT_CAINFO): '.$ca);
138138
}
139139

140140
// check php.ini options - PHP should find the file by itself
141-
if(file_exists(ini_get('curl.cainfo'))){
141+
if(\file_exists(\ini_get('curl.cainfo'))){
142142
return; // @codeCoverageIgnore
143143
}
144144

145145
// this is getting weird. as a last resort, we're going to check some default paths for a CA bundle file
146146
$cafiles = [
147147
// check other php.ini settings
148-
ini_get('openssl.cafile'),
148+
\ini_get('openssl.cafile'),
149149
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
150150
'/etc/pki/tls/certs/ca-bundle.crt',
151151
// Ubuntu, Debian (provided by the ca-certificates package)
@@ -169,8 +169,8 @@ protected function setCA():void{
169169
];
170170

171171
foreach($cafiles as $file){
172-
if(is_file($file) || (is_link($file) && is_file(readlink($file)))){
173-
$this->curl_options[CURLOPT_CAINFO] = $file;
172+
if(\is_file($file) || (\is_link($file) && \is_file(\readlink($file)))){
173+
$this->curl_options[\CURLOPT_CAINFO] = $file;
174174
return;
175175
}
176176
}

src/Psr17/StreamFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ public function createStream(string $content = ''):StreamInterface{
4747
*/
4848
public function createStreamFromFile(string $filename, string $mode = 'r'):StreamInterface{
4949

50-
if(empty($filename) || !is_file($filename)){
50+
if(empty($filename) || !\is_file($filename)){
5151
throw new RuntimeException('invalid file');
5252
}
5353

5454
if(!isset(Stream::MODES_WRITE[$mode]) && !isset(Stream::MODES_READ[$mode])){
5555
throw new InvalidArgumentException('invalid mode');
5656
}
5757

58-
return new Stream(fopen($filename, $mode));
58+
return new Stream(\fopen($filename, $mode));
5959
}
6060

6161
/**

src/Psr17/factory_helpers.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ function create_server_request_from_globals():ServerRequest{
3131
$serverRequest = new ServerRequest(
3232
isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : ServerRequest::METHOD_GET,
3333
create_uri_from_globals(),
34-
function_exists('getallheaders') ? getallheaders() : [],
34+
\function_exists('getallheaders') ? \getallheaders() : [],
3535
(new StreamFactory)->createStream(),
36-
isset($_SERVER['SERVER_PROTOCOL']) ? str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1',
36+
isset($_SERVER['SERVER_PROTOCOL']) ? \str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1',
3737
$_SERVER
3838
);
3939

@@ -58,7 +58,7 @@ function create_uri_from_globals():UriExtended{
5858
$parts['scheme'] = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http';
5959

6060
if(isset($_SERVER['HTTP_HOST'])){
61-
$hostHeaderParts = explode(':', $_SERVER['HTTP_HOST']);
61+
$hostHeaderParts = \explode(':', $_SERVER['HTTP_HOST']);
6262
$parts['host'] = $hostHeaderParts[0];
6363

6464
if(isset($hostHeaderParts[1])){
@@ -78,7 +78,7 @@ function create_uri_from_globals():UriExtended{
7878
}
7979

8080
if(isset($_SERVER['REQUEST_URI'])){
81-
$requestUriParts = explode('?', $_SERVER['REQUEST_URI']);
81+
$requestUriParts = \explode('?', $_SERVER['REQUEST_URI']);
8282
$parts['path'] = $requestUriParts[0];
8383

8484
if(isset($requestUriParts[1])){
@@ -105,11 +105,11 @@ function create_uri_from_globals():UriExtended{
105105
* @return \chillerlan\HTTP\Psr7\Stream|\Psr\Http\Message\StreamInterface
106106
*/
107107
function create_stream(string $content = ''):Stream{
108-
$stream = fopen('php://temp', 'r+');
108+
$stream = \fopen('php://temp', 'r+');
109109

110110
if($content !== ''){
111-
fwrite($stream, $content);
112-
fseek($stream, 0);
111+
\fwrite($stream, $content);
112+
\fseek($stream, 0);
113113
}
114114

115115
return new Stream($stream);
@@ -127,15 +127,15 @@ function create_stream_from_input($in = null):StreamInterface{
127127
// a) trouble if the given string accidentally matches a file path, and
128128
// b) security implications because of the above.
129129
// use with caution and never with user input!
130-
if(is_string($in) && is_file($in) && is_readable($in)){
130+
if(\is_string($in) && \is_file($in) && \is_readable($in)){
131131
return new Stream(fopen($in, 'r'));
132132
}
133133

134-
if(is_scalar($in)){
134+
if(\is_scalar($in)){
135135
return create_stream((string)$in);
136136
}
137137

138-
$type = gettype($in);
138+
$type = \gettype($in);
139139

140140
if($type === 'resource'){
141141
return new Stream($in);
@@ -145,7 +145,7 @@ function create_stream_from_input($in = null):StreamInterface{
145145
if($in instanceof StreamInterface){
146146
return $in;
147147
}
148-
elseif(method_exists($in, '__toString')){
148+
elseif(\method_exists($in, '__toString')){
149149
return create_stream((string)$in);
150150
}
151151

src/Psr18/CurlClient.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ public function sendRequest(RequestInterface $request):ResponseInterface{
3131
$handle = new $this->options->curlHandle($request, $this->responseFactory->createResponse(), $this->options);
3232
$handle->init();
3333

34-
curl_exec($handle->curl);
34+
\curl_exec($handle->curl);
3535

36-
$errno = curl_errno($handle->curl);
36+
$errno = \curl_errno($handle->curl);
3737

38-
if($errno !== CURLE_OK){
39-
$error = curl_error($handle->curl);
38+
if($errno !== \CURLE_OK){
39+
$error = \curl_error($handle->curl);
4040

4141
$network_errors = [
42-
CURLE_COULDNT_RESOLVE_PROXY,
43-
CURLE_COULDNT_RESOLVE_HOST,
44-
CURLE_COULDNT_CONNECT,
45-
CURLE_OPERATION_TIMEOUTED,
46-
CURLE_SSL_CONNECT_ERROR,
47-
CURLE_GOT_NOTHING,
42+
\CURLE_COULDNT_RESOLVE_PROXY,
43+
\CURLE_COULDNT_RESOLVE_HOST,
44+
\CURLE_COULDNT_CONNECT,
45+
\CURLE_OPERATION_TIMEOUTED,
46+
\CURLE_SSL_CONNECT_ERROR,
47+
\CURLE_GOT_NOTHING,
4848
];
4949

5050
$this->logger->error('cURL error #'.$errno.': '.$error);
5151

52-
if(in_array($errno, $network_errors, true)){
52+
if(\in_array($errno, $network_errors, true)){
5353
throw new NetworkException($error, $request);
5454
}
5555

0 commit comments

Comments
 (0)