From 7f44b05ec76c99a03bdb0177ee2fe9ee3b67fa3a Mon Sep 17 00:00:00 2001 From: Heinz Wiesinger Date: Tue, 15 Mar 2022 16:02:21 +0100 Subject: [PATCH] Requests: Fix style issues --- src/Exception.php | 2 +- src/Exception/InvalidArgument.php | 2 +- src/Requests.php | 8 ++++---- tests/Fixtures/TransportRedirectMock.php | 12 ++++++------ tests/Requests/RequestsTest.php | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Exception.php b/src/Exception.php index af92e19b1..f7b20ec93 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -34,7 +34,7 @@ class Exception extends PHPException { * * @var boolean */ - public $failed_hook_handled = FALSE; + public $failed_hook_handled = false; /** * Create a new exception diff --git a/src/Exception/InvalidArgument.php b/src/Exception/InvalidArgument.php index 2536bea77..f6d69ee81 100644 --- a/src/Exception/InvalidArgument.php +++ b/src/Exception/InvalidArgument.php @@ -17,7 +17,7 @@ final class InvalidArgument extends InvalidArgumentException { * * @var boolean */ - public $failed_hook_handled = FALSE; + public $failed_hook_handled = false; /** * Create a new invalid argument exception with a standardized text. diff --git a/src/Requests.php b/src/Requests.php index 65c6a6610..603b31e5b 100644 --- a/src/Requests.php +++ b/src/Requests.php @@ -474,16 +474,16 @@ public static function request($url, $headers = [], $data = [], $type = self::GE $parsed_response = self::parse_response($response, $url, $headers, $data, $options); } catch (Exception $e) { - if ($e->failed_hook_handled === FALSE) { + if ($e->failed_hook_handled === false) { $options['hooks']->dispatch('requests.failed', [&$e, $url, $headers, $data, $type, $options]); - $e->failed_hook_handled = TRUE; + $e->failed_hook_handled = true; } throw $e; } catch (InvalidArgument $e) { - if ($e->failed_hook_handled === FALSE) { + if ($e->failed_hook_handled === false) { $options['hooks']->dispatch('requests.failed', [&$e, $url, $headers, $data, $type, $options]); - $e->failed_hook_handled = TRUE; + $e->failed_hook_handled = true; } throw $e; diff --git a/tests/Fixtures/TransportRedirectMock.php b/tests/Fixtures/TransportRedirectMock.php index 6cc689e78..2fead036c 100644 --- a/tests/Fixtures/TransportRedirectMock.php +++ b/tests/Fixtures/TransportRedirectMock.php @@ -12,7 +12,7 @@ final class TransportRedirectMock implements Transport { private $redirected = []; - public $redirected_transport = NULL; + public $redirected_transport = null; private static $messages = [ 100 => '100 Continue', @@ -64,12 +64,11 @@ final class TransportRedirectMock implements Transport { ]; public function request($url, $headers = [], $data = [], $options = []) { - if (array_key_exists($url, $this->redirected)) - { + if (array_key_exists($url, $this->redirected)) { return $this->redirected_transport->request($url, $headers, $data, $options); } - $redirect_url = "https://example.com/redirected?url=" . urlencode($url); + $redirect_url = 'https://example.com/redirected?url=' . urlencode($url); $status = isset(self::$messages[$this->code]) ? self::$messages[$this->code] : $this->code . ' unknown'; $response = "HTTP/1.0 $status\r\n"; @@ -77,13 +76,14 @@ public function request($url, $headers = [], $data = [], $options = []) { if ($this->chunked) { $response .= "Transfer-Encoding: chunked\r\n"; } + $response .= "Location: $redirect_url\r\n"; $response .= $this->raw_headers; $response .= "Connection: close\r\n\r\n"; $response .= $this->body; - $this->redirected[$url] = TRUE; - $this->redirected[$redirect_url] = TRUE; + $this->redirected[$url] = true; + $this->redirected[$redirect_url] = true; return $response; } diff --git a/tests/Requests/RequestsTest.php b/tests/Requests/RequestsTest.php index 892c1400e..9de2587f3 100644 --- a/tests/Requests/RequestsTest.php +++ b/tests/Requests/RequestsTest.php @@ -8,12 +8,12 @@ use WpOrg\Requests\Iri; use WpOrg\Requests\Requests; use WpOrg\Requests\Response\Headers; -use WpOrg\Requests\Tests\Fixtures\RawTransportMock; use WpOrg\Requests\Tests\Fixtures\StringableObject; +use WpOrg\Requests\Tests\Fixtures\TransportMock; +use WpOrg\Requests\Tests\Fixtures\RawTransportMock; use WpOrg\Requests\Tests\Fixtures\TestTransportMock; use WpOrg\Requests\Tests\Fixtures\TransportFailedMock; use WpOrg\Requests\Tests\Fixtures\TransportInvalidArgumentMock; -use WpOrg\Requests\Tests\Fixtures\TransportMock; use WpOrg\Requests\Tests\TestCase; use WpOrg\Requests\Tests\TypeProviderHelper; use WpOrg\Requests\Tests\Fixtures\TransportRedirectMock; @@ -410,7 +410,7 @@ public function testRedirectToExceptionTriggersRequestsFailedCallbackOnce() { $transport = new TransportRedirectMock(); $transport->redirected_transport = new TransportFailedMock(); - $options = [ + $options = [ 'hooks' => $hooks, 'transport' => $transport, ]; @@ -433,7 +433,7 @@ public function testRedirectToInvalidArgumentTriggersRequestsFailedCallbackOnce( $transport = new TransportRedirectMock(); $transport->redirected_transport = new TransportInvalidArgumentMock(); - $options = [ + $options = [ 'hooks' => $hooks, 'transport' => $transport, ];