@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | /** |
96 | 96 | * Determine if the payload contains a non-empty value for a given key. |
97 | 97 | * |
98 | - * @param string|array $keys |
|
98 | + * @param string|null $keys |
|
99 | 99 | * |
100 | 100 | * @return bool |
101 | 101 | */ |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | /** |
357 | 357 | * Return a value from the array identified from the key. |
358 | 358 | * |
359 | - * @param $key |
|
359 | + * @param string|null $key |
|
360 | 360 | * @param $data |
361 | 361 | * @return mixed |
362 | 362 | */ |
@@ -29,31 +29,31 @@ |
||
29 | 29 | * @var array Supported Formats |
30 | 30 | */ |
31 | 31 | private $supported_formats = [ |
32 | - // XML |
|
32 | + // XML |
|
33 | 33 | 'application/xml' => XML::class, |
34 | 34 | 'text/xml' => XML::class, |
35 | 35 | 'xml' => XML::class, |
36 | - // JSON |
|
36 | + // JSON |
|
37 | 37 | 'application/json' => JSON::class, |
38 | 38 | 'application/x-javascript' => JSON::class, |
39 | 39 | 'text/javascript' => JSON::class, |
40 | 40 | 'text/x-javascript' => JSON::class, |
41 | 41 | 'text/x-json' => JSON::class, |
42 | 42 | 'json' => JSON::class, |
43 | - // BSON |
|
43 | + // BSON |
|
44 | 44 | 'application/bson' => BSON::class, |
45 | 45 | 'bson' => BSON::class, |
46 | - // YAML |
|
46 | + // YAML |
|
47 | 47 | 'text/yaml' => YAML::class, |
48 | 48 | 'text/x-yaml' => YAML::class, |
49 | 49 | 'application/yaml' => YAML::class, |
50 | 50 | 'application/x-yaml' => YAML::class, |
51 | 51 | 'yaml' => YAML::class, |
52 | - // MSGPACK |
|
52 | + // MSGPACK |
|
53 | 53 | 'application/msgpack' => MSGPack::class, |
54 | 54 | 'application/x-msgpack' => MSGPack::class, |
55 | 55 | 'msgpack' => MSGPack::class, |
56 | - // MISC |
|
56 | + // MISC |
|
57 | 57 | 'application/vnd.php.serialized' => Serialize::class, |
58 | 58 | 'serialize' => Serialize::class, |
59 | 59 | 'application/x-www-form-urlencoded' => QueryStr::class, |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | { |
148 | 148 | $keys = []; |
149 | 149 | foreach ($mask as $key => $value) { |
150 | - $keys[] = $key . (is_array($value) ? $this->processMask($value) : ''); |
|
150 | + $keys[] = $key.(is_array($value) ? $this->processMask($value) : ''); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | return $this->only($keys); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | private function processMask($mask) |
164 | 164 | { |
165 | 165 | foreach ($mask as $key => $value) { |
166 | - return '.' . $key . (is_array($value) ? $this->processMask($value) : ''); |
|
166 | + return '.'.$key.(is_array($value) ? $this->processMask($value) : ''); |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function getFormatClass($format = '') |
200 | 200 | { |
201 | - if ( ! empty($format)) { |
|
201 | + if (!empty($format)) { |
|
202 | 202 | return $this->processContentType($format); |
203 | 203 | } |
204 | 204 | |
@@ -277,10 +277,10 @@ discard block |
||
277 | 277 | */ |
278 | 278 | public function registerFormat($format, $class) |
279 | 279 | { |
280 | - if ( ! class_exists($class)) { |
|
280 | + if (!class_exists($class)) { |
|
281 | 281 | throw new \InvalidArgumentException("Parser formatter class {$class} not found."); |
282 | 282 | } |
283 | - if ( ! is_a($class, 'Nathanmac\Utilities\Parser\Formats\FormatInterface', true)) { |
|
283 | + if (!is_a($class, 'Nathanmac\Utilities\Parser\Formats\FormatInterface', true)) { |
|
284 | 284 | throw new \InvalidArgumentException('Parser formatters must implement the Nathanmac\Utilities\Parser\Formats\FormatInterface interface.'); |
285 | 285 | } |
286 | 286 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | $key = array_shift($keys); |
404 | 404 | |
405 | 405 | // Wildcard Key |
406 | - if (preg_match($this->wildcards, $key) && is_array($data) && ! empty($data)) { |
|
406 | + if (preg_match($this->wildcards, $key) && is_array($data) && !empty($data)) { |
|
407 | 407 | // Shift the first item of the array |
408 | 408 | if (preg_match('/^:(index|item)\[\d+\]$/', $key)) { |
409 | 409 | for ($x = substr($key, 7, -1); $x >= 0; $x--) { |
@@ -417,13 +417,13 @@ discard block |
||
417 | 417 | } else { |
418 | 418 | $item = array_shift($data); |
419 | 419 | } |
420 | - $data =& $item; |
|
420 | + $data = & $item; |
|
421 | 421 | } else { |
422 | - if ( ! isset($data[$key]) || ! is_array($data[$key])) { |
|
422 | + if (!isset($data[$key]) || !is_array($data[$key])) { |
|
423 | 423 | return false; |
424 | 424 | } |
425 | 425 | |
426 | - $data =& $data[$key]; |
|
426 | + $data = & $data[$key]; |
|
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | $key = array_shift($keys); |
462 | 462 | |
463 | 463 | // Wildcard Key |
464 | - if (preg_match($this->wildcards, $key) && is_array($data) && ! empty($data)) { |
|
464 | + if (preg_match($this->wildcards, $key) && is_array($data) && !empty($data)) { |
|
465 | 465 | // Shift the first item of the array |
466 | 466 | if (preg_match('/^:(index|item)\[\d+\]$/', $key)) { |
467 | 467 | for ($x = substr($key, 7, -1); $x >= 0; $x--) { |
@@ -475,9 +475,9 @@ discard block |
||
475 | 475 | } else { |
476 | 476 | $item = array_shift($data); |
477 | 477 | } |
478 | - $data =& $item; |
|
478 | + $data = & $item; |
|
479 | 479 | } else { |
480 | - if ( ! isset($data[$key])) { |
|
480 | + if (!isset($data[$key])) { |
|
481 | 481 | return false; |
482 | 482 | } |
483 | 483 | |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | return false; |
490 | 490 | } |
491 | 491 | |
492 | - $data =& $data[$key]; |
|
492 | + $data = & $data[$key]; |
|
493 | 493 | } |
494 | 494 | } |
495 | 495 | return true; |
@@ -525,11 +525,11 @@ discard block |
||
525 | 525 | while (count($keys) > 1) { |
526 | 526 | $key = array_shift($keys); |
527 | 527 | |
528 | - if ( ! isset($array[$key]) || ! is_array($array[$key])) { |
|
528 | + if (!isset($array[$key]) || !is_array($array[$key])) { |
|
529 | 529 | return; |
530 | 530 | } |
531 | 531 | |
532 | - $array =& $array[$key]; |
|
532 | + $array = & $array[$key]; |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | unset($array[array_shift($keys)]); |
@@ -35,7 +35,7 @@ |
||
35 | 35 | /** |
36 | 36 | * Get the services provided by the provider. |
37 | 37 | * |
38 | - * @return array |
|
38 | + * @return string[] |
|
39 | 39 | */ |
40 | 40 | public function provides() |
41 | 41 | { |
@@ -27,7 +27,7 @@ |
||
27 | 27 | */ |
28 | 28 | public function register() |
29 | 29 | { |
30 | - $this->app->bind('Parser', function ($app) { |
|
30 | + $this->app->bind('Parser', function($app) { |
|
31 | 31 | return new Parser; |
32 | 32 | }); |
33 | 33 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | { |
27 | 27 | if ($payload) { |
28 | 28 | $json = json_decode(trim($payload), true); |
29 | - if ( ! $json) { |
|
29 | + if (!$json) { |
|
30 | 30 | throw new ParserException('Failed To Parse JSON'); |
31 | 31 | } |
32 | 32 | return $json; |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! function_exists('bson_decode')) { |
|
3 | +if (!function_exists('bson_decode')) { |
|
4 | 4 | function bson_decode($payload) |
5 | 5 | { |
6 | 6 | return MongoDB\BSON\toPHP($payload, ['root' => 'array', 'document' => 'array']); |
@@ -24,25 +24,25 @@ |
||
24 | 24 | */ |
25 | 25 | public function parse($payload) |
26 | 26 | { |
27 | - if (function_exists('MongoDB\BSON\toPHP') && ! function_exists('bson_decode')) { |
|
28 | - require_once(__DIR__ . '/BSONPolyfill.php'); //@codeCoverageIgnore |
|
29 | - } elseif ( ! (function_exists('bson_decode') || function_exists('MongoDB\BSON\toPHP'))) { |
|
30 | - throw new ParserException('Failed To Parse BSON - Supporting Library Not Available'); // @codeCoverageIgnore |
|
27 | + if (function_exists('MongoDB\BSON\toPHP') && !function_exists('bson_decode')) { |
|
28 | + require_once(__DIR__.'/BSONPolyfill.php'); //@codeCoverageIgnore |
|
29 | + } elseif (!(function_exists('bson_decode') || function_exists('MongoDB\BSON\toPHP'))) { |
|
30 | + throw new ParserException('Failed To Parse BSON - Supporting Library Not Available'); // @codeCoverageIgnore |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | if ($payload) { |
34 | - $prevHandler = set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) { |
|
35 | - throw new \Exception($errstr); // @codeCoverageIgnore |
|
34 | + $prevHandler = set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) { |
|
35 | + throw new \Exception($errstr); // @codeCoverageIgnore |
|
36 | 36 | }); |
37 | 37 | |
38 | 38 | try { |
39 | - $bson = bson_decode(trim($payload, " \t\n\r\x0b")); // Don't trim \0, as it has valid meaning in BSON |
|
40 | - if ( ! $bson) { |
|
41 | - throw new \Exception('Unknown error'); // @codeCoverageIgnore |
|
39 | + $bson = bson_decode(trim($payload, " \t\n\r\x0b")); // Don't trim \0, as it has valid meaning in BSON |
|
40 | + if (!$bson) { |
|
41 | + throw new \Exception('Unknown error'); // @codeCoverageIgnore |
|
42 | 42 | } |
43 | 43 | } catch (\Exception $e) { |
44 | 44 | set_error_handler($prevHandler); |
45 | - throw new ParserException('Failed To Parse BSON - ' . $e->getMessage()); |
|
45 | + throw new ParserException('Failed To Parse BSON - '.$e->getMessage()); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | set_error_handler($prevHandler); |
@@ -26,18 +26,18 @@ discard block |
||
26 | 26 | { |
27 | 27 | if (function_exists('msgpack_unpack')) { |
28 | 28 | if ($payload) { |
29 | - $prevHandler = set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) { |
|
30 | - throw new \Exception($errstr); // @codeCoverageIgnore |
|
29 | + $prevHandler = set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) { |
|
30 | + throw new \Exception($errstr); // @codeCoverageIgnore |
|
31 | 31 | }); |
32 | 32 | |
33 | 33 | try { |
34 | 34 | $msg = msgpack_unpack(trim($payload)); |
35 | - if ( ! $msg) { |
|
36 | - throw new \Exception('Unknown error'); // @codeCoverageIgnore |
|
35 | + if (!$msg) { |
|
36 | + throw new \Exception('Unknown error'); // @codeCoverageIgnore |
|
37 | 37 | } |
38 | 38 | } catch (\Exception $e) { |
39 | 39 | set_error_handler($prevHandler); |
40 | - throw new ParserException('Failed To Parse MSGPack - ' . $e->getMessage()); |
|
40 | + throw new ParserException('Failed To Parse MSGPack - '.$e->getMessage()); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | set_error_handler($prevHandler); |
@@ -47,6 +47,6 @@ discard block |
||
47 | 47 | return []; |
48 | 48 | } |
49 | 49 | |
50 | - throw new ParserException('Failed To Parse MSGPack - Supporting Library Not Available'); // @codeCoverageIgnore |
|
50 | + throw new ParserException('Failed To Parse MSGPack - Supporting Library Not Available'); // @codeCoverageIgnore |
|
51 | 51 | } |
52 | 52 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | protected function recursive_parse($xml, $ns) |
41 | 41 | { |
42 | - $xml_string = (string)$xml; |
|
42 | + $xml_string = (string) $xml; |
|
43 | 43 | |
44 | 44 | if ($xml->count() == 0 and $xml_string != '') { |
45 | 45 | if (count($xml->attributes()) == 0) { |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $attName = "{$nsName}:{$attName}"; |
62 | 62 | } |
63 | 63 | |
64 | - $result["@{$attName}"] = (string)$attValue; |
|
64 | + $result["@{$attName}"] = (string) $attValue; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | foreach ($xml->children($nsUri) as $childName => $child) { |