Skip to content

Commit 992a16b

Browse files
authored
Format code (#5172)
1 parent 44fbbbb commit 992a16b

27 files changed

+162
-112
lines changed

src/Base/MessageTrait.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
namespace Hyperf\HttpMessage\Base;
1313

1414
use Hyperf\HttpMessage\Stream\SwooleStream;
15+
use InvalidArgumentException;
1516
use Laminas\Mime\Decode;
1617
use Psr\Http\Message\StreamInterface;
18+
use RuntimeException;
19+
use Throwable;
1720

1821
/**
1922
* Trait implementing functionality common to requests and responses.
@@ -160,7 +163,7 @@ public function getHeaderLine($name): string
160163
* @param string $name case-insensitive header field name
161164
* @param string|string[] $value header value(s)
162165
* @return static
163-
* @throws \InvalidArgumentException for invalid header names or values
166+
* @throws InvalidArgumentException for invalid header names or values
164167
*/
165168
public function withHeader($name, $value)
166169
{
@@ -202,7 +205,7 @@ public function withHeaders(array $headers): static
202205
* @param string $name case-insensitive header field name to add
203206
* @param string|string[] $value header value(s)
204207
* @return static
205-
* @throws \InvalidArgumentException for invalid header names or values
208+
* @throws InvalidArgumentException for invalid header names or values
206209
*/
207210
public function withAddedHeader($name, $value)
208211
{
@@ -274,7 +277,7 @@ public function getBody()
274277
*
275278
* @param StreamInterface $body body
276279
* @return static
277-
* @throws \InvalidArgumentException when the body is not valid
280+
* @throws InvalidArgumentException when the body is not valid
278281
*/
279282
public function withBody(StreamInterface $body)
280283
{
@@ -300,7 +303,7 @@ public function withBody(StreamInterface $body)
300303
* @param string $wantedPart the wanted part, default is first, if null an array with all parts is returned
301304
* @param string $firstName key name for the first part
302305
* @return array|string wanted part or all parts as array($firstName => firstPart, partname => value)
303-
* @throws \RuntimeException
306+
* @throws RuntimeException
304307
*/
305308
public function getHeaderField(string $name, string $wantedPart = '0', string $firstName = '0')
306309
{
@@ -321,7 +324,7 @@ public function isMultipart(): bool
321324
{
322325
try {
323326
return stripos($this->getContentType(), 'multipart/') === 0;
324-
} catch (\Throwable $e) {
327+
} catch (Throwable $e) {
325328
return false;
326329
}
327330
}

src/Base/Request.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Hyperf\HttpMessage\Stream\SwooleStream;
1515
use Hyperf\HttpMessage\Uri\Uri;
16+
use InvalidArgumentException;
1617
use Psr\Http\Message\RequestInterface;
1718
use Psr\Http\Message\StreamInterface;
1819
use Psr\Http\Message\UriInterface;
@@ -109,7 +110,7 @@ public function getRequestTarget()
109110
public function withRequestTarget($requestTarget)
110111
{
111112
if (preg_match('#\s#', $requestTarget)) {
112-
throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
113+
throw new InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
113114
}
114115

115116
$new = clone $this;
@@ -138,14 +139,14 @@ public function getMethod()
138139
*
139140
* @param string $method case-sensitive method
140141
* @return static
141-
* @throws \InvalidArgumentException for invalid HTTP methods
142+
* @throws InvalidArgumentException for invalid HTTP methods
142143
*/
143144
public function withMethod($method)
144145
{
145146
$method = strtoupper($method);
146147
$methods = ['GET', 'POST', 'PATCH', 'PUT', 'DELETE', 'HEAD'];
147148
if (! in_array($method, $methods)) {
148-
throw new \InvalidArgumentException('Invalid Method');
149+
throw new InvalidArgumentException('Invalid Method');
149150
}
150151
$new = clone $this;
151152
$new->method = $method;

src/Base/Response.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Base;
1313

14+
use InvalidArgumentException;
1415
use Psr\Http\Message\ResponseInterface;
1516

1617
class Response implements ResponseInterface
@@ -177,7 +178,7 @@ public function getStatusCode(): int
177178
* provided status code; if none is provided, implementations MAY
178179
* use the defaults as suggested in the HTTP specification
179180
* @return static
180-
* @throws \InvalidArgumentException for invalid status code arguments
181+
* @throws InvalidArgumentException for invalid status code arguments
181182
*/
182183
public function withStatus($code, $reasonPhrase = '')
183184
{
@@ -202,7 +203,7 @@ public static function getReasonPhraseByCode(int $code): string
202203
* Return an instance with the specified charset content type.
203204
*
204205
* @return static
205-
* @throws \InvalidArgumentException
206+
* @throws InvalidArgumentException
206207
*/
207208
public function withCharset(string $charset)
208209
{

src/Cookie/Cookie.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Cookie;
1313

14+
use DateTimeInterface;
15+
use InvalidArgumentException;
1416
use Stringable;
1517

1618
class Cookie implements Stringable
@@ -30,15 +32,15 @@ class Cookie implements Stringable
3032
/**
3133
* @param string $name The name of the cookie
3234
* @param string $value The value of the cookie
33-
* @param \DateTimeInterface|int|string $expire The time the cookie expires
35+
* @param DateTimeInterface|int|string $expire The time the cookie expires
3436
* @param string $path The path on the server in which the cookie will be available on
3537
* @param string $domain The domain that the cookie is available to
3638
* @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client
3739
* @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol
3840
* @param bool $raw Whether the cookie value should be sent with no url encoding
3941
* @param null|string $sameSite Whether the cookie will be available for cross-site requests
4042
*
41-
* @throws \InvalidArgumentException
43+
* @throws InvalidArgumentException
4244
*/
4345
public function __construct(
4446
protected string $name,
@@ -53,21 +55,21 @@ public function __construct(
5355
) {
5456
// from PHP source code
5557
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
56-
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
58+
throw new InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
5759
}
5860

5961
if (empty($name)) {
60-
throw new \InvalidArgumentException('The cookie name cannot be empty.');
62+
throw new InvalidArgumentException('The cookie name cannot be empty.');
6163
}
6264

6365
// convert expiration time to a Unix timestamp
64-
if ($expire instanceof \DateTimeInterface) {
66+
if ($expire instanceof DateTimeInterface) {
6567
$expire = $expire->format('U');
6668
} elseif (! is_numeric($expire)) {
6769
$expire = strtotime($expire);
6870

6971
if ($expire === false) {
70-
throw new \InvalidArgumentException('The cookie expiration time is not valid.');
72+
throw new InvalidArgumentException('The cookie expiration time is not valid.');
7173
}
7274
}
7375

@@ -79,7 +81,7 @@ public function __construct(
7981
}
8082

8183
if (! in_array($sameSite, [self::SAMESITE_LAX, self::SAMESITE_STRICT, self::SAMESITE_NONE, null], true)) {
82-
throw new \InvalidArgumentException('The "sameSite" parameter value is not valid.');
84+
throw new InvalidArgumentException('The "sameSite" parameter value is not valid.');
8385
}
8486

8587
$this->sameSite = $sameSite;

src/Cookie/CookieJar.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Cookie;
1313

14+
use ArrayIterator;
1415
use Psr\Http\Message\RequestInterface;
1516
use Psr\Http\Message\ResponseInterface;
17+
use RuntimeException;
1618
use Traversable;
1719

1820
/**
@@ -163,7 +165,7 @@ public function setCookie(SetCookie $cookie)
163165
$result = $cookie->validate();
164166
if ($result !== true) {
165167
if ($this->strictMode) {
166-
throw new \RuntimeException('Invalid cookie: ' . $result);
168+
throw new RuntimeException('Invalid cookie: ' . $result);
167169
}
168170
$this->removeCookieIfEmpty($cookie);
169171
return false;
@@ -216,7 +218,7 @@ public function count(): int
216218

217219
public function getIterator(): Traversable
218220
{
219-
return new \ArrayIterator(array_values($this->cookies));
221+
return new ArrayIterator(array_values($this->cookies));
220222
}
221223

222224
public function extractCookies(

src/Cookie/CookieJarInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Cookie;
1313

14+
use Countable;
1415
use Hyperf\Contract\Arrayable;
1516
use Psr\Http\Message\RequestInterface;
1617
use Psr\Http\Message\ResponseInterface;
@@ -25,7 +26,7 @@
2526
*
2627
* @see http://docs.python.org/2/library/cookielib.html Inspiration
2728
*/
28-
interface CookieJarInterface extends \Countable, \IteratorAggregate, Arrayable
29+
interface CookieJarInterface extends Countable, \IteratorAggregate, Arrayable
2930
{
3031
/**
3132
* Create a request with added cookie headers.

src/Cookie/FileCookieJar.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Hyperf\HttpMessage\Cookie;
1313

1414
use Hyperf\Utils\Codec\Json;
15+
use RuntimeException;
1516

1617
/**
1718
* Persists non-session cookies using a JSON formatted file.
@@ -25,7 +26,7 @@ class FileCookieJar extends CookieJar
2526
* @param bool $storeSessionCookies Control whether to persist session cookies or not.
2627
* Set to true to store session cookies in the cookie jar.
2728
*
28-
* @throws \RuntimeException if the file cannot be found or created
29+
* @throws RuntimeException if the file cannot be found or created
2930
*/
3031
public function __construct(private string $filename, private bool $storeSessionCookies = false)
3132
{
@@ -46,7 +47,7 @@ public function __destruct()
4647
* Saves the cookies to a file.
4748
*
4849
* @param string $filename File to save
49-
* @throws \RuntimeException if the file cannot be found or created
50+
* @throws RuntimeException if the file cannot be found or created
5051
*/
5152
public function save(string $filename): void
5253
{
@@ -60,7 +61,7 @@ public function save(string $filename): void
6061

6162
$jsonStr = Json::encode($json);
6263
if (file_put_contents($filename, $jsonStr) === false) {
63-
throw new \RuntimeException("Unable to save file {$filename}");
64+
throw new RuntimeException("Unable to save file {$filename}");
6465
}
6566
}
6667

@@ -70,13 +71,13 @@ public function save(string $filename): void
7071
* Old cookies are kept unless overwritten by newly loaded ones.
7172
*
7273
* @param string $filename cookie file to load
73-
* @throws \RuntimeException if the file cannot be loaded
74+
* @throws RuntimeException if the file cannot be loaded
7475
*/
7576
public function load(string $filename): void
7677
{
7778
$json = file_get_contents($filename);
7879
if ($json === false) {
79-
throw new \RuntimeException("Unable to load file {$filename}");
80+
throw new RuntimeException("Unable to load file {$filename}");
8081
}
8182
if ($json === '') {
8283
return;
@@ -88,7 +89,7 @@ public function load(string $filename): void
8889
$this->setCookie(new SetCookie($cookie));
8990
}
9091
} elseif (strlen($data)) {
91-
throw new \RuntimeException("Invalid cookie file: {$filename}");
92+
throw new RuntimeException("Invalid cookie file: {$filename}");
9293
}
9394
}
9495
}

src/Cookie/SessionCookieJar.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Cookie;
1313

14+
use RuntimeException;
15+
1416
/**
1517
* Persists cookies in the client session for FPM.
1618
*/
@@ -68,7 +70,7 @@ protected function load(): void
6870
$this->setCookie(new SetCookie($cookie));
6971
}
7072
} elseif (strlen($data)) {
71-
throw new \RuntimeException('Invalid cookie data');
73+
throw new RuntimeException('Invalid cookie data');
7274
}
7375
}
7476
}

src/Exception/BadRequestHttpException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Exception;
1313

14+
use Throwable;
15+
1416
class BadRequestHttpException extends HttpException
1517
{
16-
public function __construct($message = null, $code = 0, \Throwable $previous = null)
18+
public function __construct($message = null, $code = 0, Throwable $previous = null)
1719
{
1820
parent::__construct(400, $message, $code, $previous);
1921
}

src/Exception/ForbiddenHttpException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Exception;
1313

14+
use Throwable;
15+
1416
class ForbiddenHttpException extends HttpException
1517
{
16-
public function __construct($message = null, $code = 0, \Throwable $previous = null)
18+
public function __construct($message = null, $code = 0, Throwable $previous = null)
1719
{
1820
parent::__construct(403, $message, $code, $previous);
1921
}

0 commit comments

Comments
 (0)