Skip to content

Commit 2f478b5

Browse files
authored
Merge pull request #305 from sosherof/PHP7.2_to_8.2
Support for PHP 7.2 to 8.2
2 parents 0cded3e + e20b236 commit 2f478b5

File tree

17 files changed

+183
-172
lines changed

17 files changed

+183
-172
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ vendor
44
downloads
55
.idea/*
66
tests/.phpunit.result.cache
7+
/rector.php
8+
/.vs

downloads/httpful.phar

67.6 KB
Binary file not shown.

src/Httpful/Bootstrap.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
class Bootstrap
1212
{
1313

14-
const DIR_GLUE = DIRECTORY_SEPARATOR;
15-
const NS_GLUE = '\\';
14+
public const DIR_GLUE = DIRECTORY_SEPARATOR;
15+
public const NS_GLUE = '\\';
1616

1717
public static $registered = false;
1818

@@ -21,7 +21,7 @@ class Bootstrap
2121
*/
2222
public static function init()
2323
{
24-
spl_autoload_register(array('\Httpful\Bootstrap', 'autoload'));
24+
spl_autoload_register(['\\' . \Httpful\Bootstrap::class, 'autoload']);
2525
self::registerHandlers();
2626
}
2727

@@ -32,15 +32,15 @@ public static function init()
3232
*/
3333
public static function autoload($classname)
3434
{
35-
self::_autoload(dirname(dirname(__FILE__)), $classname);
35+
self::_autoload(dirname(__FILE__,2), $classname);
3636
}
3737

3838
/**
3939
* Register the autoloader and any other setup needed
4040
*/
4141
public static function pharInit()
4242
{
43-
spl_autoload_register(array('\Httpful\Bootstrap', 'pharAutoload'));
43+
spl_autoload_register(['\\' . \Httpful\Bootstrap::class, 'pharAutoload']);
4444
self::registerHandlers();
4545
}
4646

@@ -78,12 +78,12 @@ public static function registerHandlers()
7878

7979
// @todo check a conf file to load from that instead of
8080
// hardcoding into the library?
81-
$handlers = array(
81+
$handlers = [
8282
\Httpful\Mime::JSON => new \Httpful\Handlers\JsonHandler(),
8383
\Httpful\Mime::XML => new \Httpful\Handlers\XmlHandler(),
8484
\Httpful\Mime::FORM => new \Httpful\Handlers\FormHandler(),
8585
\Httpful\Mime::CSV => new \Httpful\Handlers\CsvHandler(),
86-
);
86+
];
8787

8888
foreach ($handlers as $mime => $handler) {
8989
// Don't overwrite if the handler has already been registered

src/Httpful/Handlers/CsvHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ public function parse($body)
1818
if (empty($body))
1919
return null;
2020

21-
$parsed = array();
21+
$parsed = [];
2222
$fp = fopen('data://text/plain;base64,' . base64_encode($body), 'r');
2323
while (($r = fgetcsv($fp)) !== FALSE) {
2424
$parsed[] = $r;
2525
}
2626

27-
if (empty($parsed))
27+
if ($parsed === [])
2828
throw new \Exception("Unable to parse response as CSV");
2929
return $parsed;
3030
}
@@ -33,7 +33,7 @@ public function parse($body)
3333
* @param mixed $payload
3434
* @return string
3535
*/
36-
public function serialize($payload)
36+
public function serialize($payload): string
3737
{
3838
$fp = fopen('php://temp/maxmemory:'. (6*1024*1024), 'r+');
3939
$i = 0;

src/Httpful/Handlers/FormHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class FormHandler extends MimeHandlerAdapter
1414
*/
1515
public function parse($body)
1616
{
17-
$parsed = array();
17+
$parsed = [];
1818
parse_str($body, $parsed);
1919
return $parsed;
2020
}
@@ -23,7 +23,7 @@ public function parse($body)
2323
* @param mixed $payload
2424
* @return string
2525
*/
26-
public function serialize($payload)
26+
public function serialize($payload): string
2727
{
2828
return http_build_query($payload, null, '&');
2929
}

src/Httpful/Handlers/JsonHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class JsonHandler extends MimeHandlerAdapter
1414

1515
public function init(array $args)
1616
{
17-
$this->decode_as_array = !!(array_key_exists('decode_as_array', $args) ? $args['decode_as_array'] : false);
17+
$this->decode_as_array = (bool) ($args['decode_as_array'] ?? false);
1818
}
1919

2020
/**
@@ -37,7 +37,7 @@ public function parse($body)
3737
* @param mixed $payload
3838
* @return string
3939
*/
40-
public function serialize($payload)
40+
public function serialize($payload): string
4141
{
4242
return json_encode($payload);
4343
}

src/Httpful/Handlers/MimeHandlerAdapter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class MimeHandlerAdapter
1212
{
13-
public function __construct(array $args = array())
13+
public function __construct(array $args = [])
1414
{
1515
$this->init($args);
1616
}
@@ -36,18 +36,18 @@ public function parse($body)
3636
* @param mixed $payload
3737
* @return string
3838
*/
39-
function serialize($payload)
39+
function serialize($payload): string
4040
{
4141
return (string) $payload;
4242
}
4343

44-
protected function stripBom($body)
44+
protected function stripBom($body): string
4545
{
4646
if ( substr($body,0,3) === "\xef\xbb\xbf" ) // UTF-8
4747
$body = substr($body,3);
48-
else if ( substr($body,0,4) === "\xff\xfe\x00\x00" || substr($body,0,4) === "\x00\x00\xfe\xff" ) // UTF-32
48+
elseif ( substr($body,0,4) === "\xff\xfe\x00\x00" || substr($body,0,4) === "\x00\x00\xfe\xff" ) // UTF-32
4949
$body = substr($body,4);
50-
else if ( substr($body,0,2) === "\xff\xfe" || substr($body,0,2) === "\xfe\xff" ) // UTF-16
50+
elseif ( substr($body,0,2) === "\xff\xfe" || substr($body,0,2) === "\xfe\xff" ) // UTF-16
5151
$body = substr($body,2);
5252
return $body;
5353
}

src/Httpful/Handlers/XmlHandler.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class XmlHandler extends MimeHandlerAdapter
2323
/**
2424
* @param array $conf sets configuration options
2525
*/
26-
public function __construct(array $conf = array())
26+
public function __construct(array $conf = [])
2727
{
28-
$this->namespace = isset($conf['namespace']) ? $conf['namespace'] : '';
29-
$this->libxml_opts = isset($conf['libxml_opts']) ? $conf['libxml_opts'] : 0;
28+
$this->namespace = $conf['namespace'] ?? '';
29+
$this->libxml_opts = $conf['libxml_opts'] ?? 0;
3030
}
3131

3232
/**
@@ -50,9 +50,9 @@ public function parse($body)
5050
* @return string
5151
* @throws \Exception if unable to serialize
5252
*/
53-
public function serialize($payload)
53+
public function serialize($payload): string
5454
{
55-
list($_, $dom) = $this->_future_serializeAsXml($payload);
55+
[$_, $dom] = $this->_future_serializeAsXml($payload);
5656
return $dom->saveXml();
5757
}
5858

@@ -61,7 +61,7 @@ public function serialize($payload)
6161
* @return string
6262
* @author Ted Zellers
6363
*/
64-
public function serialize_clean($payload)
64+
public function serialize_clean($payload): string
6565
{
6666
$xml = new \XMLWriter;
6767
$xml->openMemory();
@@ -75,7 +75,7 @@ public function serialize_clean($payload)
7575
* @param mixed $node to serialize
7676
* @author Ted Zellers
7777
*/
78-
public function serialize_node(&$xmlw, $node){
78+
public function serialize_node(&$xmlw, $node) {
7979
if (!is_array($node)){
8080
$xmlw->text($node);
8181
} else {
@@ -90,7 +90,7 @@ public function serialize_node(&$xmlw, $node){
9090
/**
9191
* @author Zack Douglas <zack@zackerydouglas.info>
9292
*/
93-
private function _future_serializeAsXml($value, $node = null, $dom = null)
93+
private function _future_serializeAsXml($value, $node = null, $dom = null): array
9494
{
9595
if (!$dom) {
9696
$dom = new \DOMDocument;
@@ -107,21 +107,21 @@ private function _future_serializeAsXml($value, $node = null, $dom = null)
107107
$objNode = $dom->createElement(get_class($value));
108108
$node->appendChild($objNode);
109109
$this->_future_serializeObjectAsXml($value, $objNode, $dom);
110-
} else if (is_array($value)) {
110+
} elseif (is_array($value)) {
111111
$arrNode = $dom->createElement('array');
112112
$node->appendChild($arrNode);
113113
$this->_future_serializeArrayAsXml($value, $arrNode, $dom);
114-
} else if (is_bool($value)) {
114+
} elseif (is_bool($value)) {
115115
$node->appendChild($dom->createTextNode($value?'TRUE':'FALSE'));
116116
} else {
117117
$node->appendChild($dom->createTextNode($value));
118118
}
119-
return array($node, $dom);
119+
return [$node, $dom];
120120
}
121121
/**
122122
* @author Zack Douglas <zack@zackerydouglas.info>
123123
*/
124-
private function _future_serializeArrayAsXml($value, &$parent, &$dom)
124+
private function _future_serializeArrayAsXml($value, &$parent, &$dom): array
125125
{
126126
foreach ($value as $k => &$v) {
127127
$n = $k;
@@ -132,12 +132,12 @@ private function _future_serializeArrayAsXml($value, &$parent, &$dom)
132132
$parent->appendChild($el);
133133
$this->_future_serializeAsXml($v, $el, $dom);
134134
}
135-
return array($parent, $dom);
135+
return [$parent, $dom];
136136
}
137137
/**
138138
* @author Zack Douglas <zack@zackerydouglas.info>
139139
*/
140-
private function _future_serializeObjectAsXml($value, &$parent, &$dom)
140+
private function _future_serializeObjectAsXml($value, &$parent, &$dom): array
141141
{
142142
$refl = new \ReflectionObject($value);
143143
foreach ($refl->getProperties() as $pr) {
@@ -147,6 +147,6 @@ private function _future_serializeObjectAsXml($value, &$parent, &$dom)
147147
$this->_future_serializeAsXml($pr->getValue($value), $el, $dom);
148148
}
149149
}
150-
return array($parent, $dom);
150+
return [$parent, $dom];
151151
}
152152
}

src/Httpful/Http.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77
*/
88
class Http
99
{
10-
const HEAD = 'HEAD';
11-
const GET = 'GET';
12-
const POST = 'POST';
13-
const PUT = 'PUT';
14-
const DELETE = 'DELETE';
15-
const PATCH = 'PATCH';
16-
const OPTIONS = 'OPTIONS';
17-
const TRACE = 'TRACE';
10+
public const HEAD = 'HEAD';
11+
public const GET = 'GET';
12+
public const POST = 'POST';
13+
public const PUT = 'PUT';
14+
public const DELETE = 'DELETE';
15+
public const PATCH = 'PATCH';
16+
public const OPTIONS = 'OPTIONS';
17+
public const TRACE = 'TRACE';
1818

1919
/**
2020
* @return array of HTTP method strings
2121
*/
22-
public static function safeMethods()
22+
public static function safeMethods(): array
2323
{
24-
return array(self::HEAD, self::GET, self::OPTIONS, self::TRACE);
24+
return [self::HEAD, self::GET, self::OPTIONS, self::TRACE];
2525
}
2626

2727
/**
2828
* @param string HTTP method
2929
* @return bool
3030
*/
31-
public static function isSafeMethod($method)
31+
public static function isSafeMethod($method): bool
3232
{
3333
return in_array($method, self::safeMethods());
3434
}
@@ -37,27 +37,27 @@ public static function isSafeMethod($method)
3737
* @param string HTTP method
3838
* @return bool
3939
*/
40-
public static function isUnsafeMethod($method)
40+
public static function isUnsafeMethod($method): bool
4141
{
4242
return !in_array($method, self::safeMethods());
4343
}
4444

4545
/**
4646
* @return array list of (always) idempotent HTTP methods
4747
*/
48-
public static function idempotentMethods()
48+
public static function idempotentMethods(): array
4949
{
5050
// Though it is possible to be idempotent, POST
5151
// is not guarunteed to be, and more often than
5252
// not, it is not.
53-
return array(self::HEAD, self::GET, self::PUT, self::DELETE, self::OPTIONS, self::TRACE, self::PATCH);
53+
return [self::HEAD, self::GET, self::PUT, self::DELETE, self::OPTIONS, self::TRACE, self::PATCH];
5454
}
5555

5656
/**
5757
* @param string HTTP method
5858
* @return bool
5959
*/
60-
public static function isIdempotent($method)
60+
public static function isIdempotent($method): bool
6161
{
6262
return in_array($method, self::safeidempotentMethodsMethods());
6363
}
@@ -66,7 +66,7 @@ public static function isIdempotent($method)
6666
* @param string HTTP method
6767
* @return bool
6868
*/
69-
public static function isNotIdempotent($method)
69+
public static function isNotIdempotent($method): bool
7070
{
7171
return !in_array($method, self::idempotentMethods());
7272
}
@@ -78,9 +78,9 @@ public static function isNotIdempotent($method)
7878
*
7979
* @return array of HTTP method strings
8080
*/
81-
public static function canHaveBody()
81+
public static function canHaveBody(): array
8282
{
83-
return array(self::POST, self::PUT, self::PATCH, self::OPTIONS);
83+
return [self::POST, self::PUT, self::PATCH, self::OPTIONS];
8484
}
8585

8686
}

src/Httpful/Httpful.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Httpful;
44

55
class Httpful {
6-
const VERSION = '0.3.0';
6+
public const VERSION = '0.3.0';
77

8-
private static $mimeRegistrar = array();
8+
private static $mimeRegistrar = [];
99
private static $default = null;
1010

1111
/**
@@ -40,7 +40,7 @@ public static function get($mimeType = null)
4040
* @param string $mimeType
4141
* @return bool
4242
*/
43-
public static function hasParserRegistered($mimeType)
43+
public static function hasParserRegistered($mimeType): bool
4444
{
4545
return isset(self::$mimeRegistrar[$mimeType]);
4646
}

0 commit comments

Comments
 (0)