From b2b444d1efdd40fd9dd41c4be824f79784ee2e32 Mon Sep 17 00:00:00 2001 From: Konstantin Grachev Date: Mon, 1 Feb 2021 02:49:53 +0300 Subject: [PATCH] cs: don't import globals --- .php_cs.dist | 3 ++- src/Config/ClientConfig.php | 10 ++-------- src/Connection.php | 7 +------ src/Consumer.php | 3 +-- src/Exception/ConnectionFail.php | 4 +--- src/Exception/NsqException.php | 4 +--- src/NsqSocket.php | 1 - src/Protocol/Error.php | 1 - src/Protocol/Response.php | 2 -- src/Reconnect/ExponentialStrategy.php | 3 +-- src/Socket/DeflateSocket.php | 8 +++----- src/Socket/SnappySocket.php | 4 ---- tests/Protocol/ErrorTypeTest.php | 8 +++----- 13 files changed, 15 insertions(+), 43 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index a4cfc42..84cf4b1 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -9,9 +9,10 @@ return (new PhpCsFixer\Config()) '@PSR12' => true, '@PSR12:risky' => true, 'blank_line_before_statement' => [ - 'statements' => ['continue', 'do', 'die', 'exit', 'goto', 'if', 'return', 'switch', 'throw', 'try'] + 'statements' => ['continue', 'do', 'die', 'exit', 'goto', 'if', 'return', 'switch', 'throw', 'try'], ], 'declare_strict_types' => true, + 'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false], 'php_unit_internal_class' => false, 'php_unit_test_case_static_method_calls'=> ['call_type' => 'self'], 'php_unit_test_class_requires_covers' => false, diff --git a/src/Config/ClientConfig.php b/src/Config/ClientConfig.php index db7cd20..894b075 100644 --- a/src/Config/ClientConfig.php +++ b/src/Config/ClientConfig.php @@ -5,12 +5,6 @@ declare(strict_types=1); namespace Nsq\Config; use Composer\InstalledVersions; -use InvalidArgumentException; -use JsonSerializable; -use function gethostname; -use function json_encode; -use const JSON_FORCE_OBJECT; -use const JSON_THROW_ON_ERROR; /** * This class is used for configuring the clients for nsq. Immutable properties must be set when creating the object and @@ -19,7 +13,7 @@ use const JSON_THROW_ON_ERROR; * * @psalm-immutable */ -final class ClientConfig implements JsonSerializable +final class ClientConfig implements \JsonSerializable { /** * @psalm-suppress ImpureFunctionCall @@ -116,7 +110,7 @@ final class ClientConfig implements JsonSerializable } if ($this->snappy && $this->deflate) { - throw new InvalidArgumentException('Client cannot enable both [snappy] and [deflate]'); + throw new \InvalidArgumentException('Client cannot enable both [snappy] and [deflate]'); } } diff --git a/src/Connection.php b/src/Connection.php index 5200a00..1f8bc9a 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -22,11 +22,6 @@ use Nsq\Socket\SnappySocket; use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Throwable; -use function addcslashes; -use function http_build_query; -use function implode; -use const PHP_EOL; /** * @internal @@ -111,7 +106,7 @@ abstract class Connection try { $this->command('CLS'); $this->socket->close(); - } catch (Throwable) { + } catch (\Throwable $e) { } $this->closed = true; diff --git a/src/Consumer.php b/src/Consumer.php index 838cf6a..7ddda98 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -12,7 +12,6 @@ use Nsq\Protocol\Error; use Nsq\Protocol\Message; use Nsq\Protocol\Response; use Psr\Log\LoggerInterface; -use function microtime; final class Consumer extends Connection { @@ -31,7 +30,7 @@ final class Consumer extends Connection /** * @psalm-return Generator */ - public function generator(): Generator + public function generator(): \Generator { $this->command('SUB', [$this->topic, $this->channel])->checkIsOK(); diff --git a/src/Exception/ConnectionFail.php b/src/Exception/ConnectionFail.php index a91db05..6920e99 100644 --- a/src/Exception/ConnectionFail.php +++ b/src/Exception/ConnectionFail.php @@ -4,14 +4,12 @@ declare(strict_types=1); namespace Nsq\Exception; -use Throwable; - final class ConnectionFail extends NsqException { /** * @codeCoverageIgnore */ - public static function fromThrowable(Throwable $throwable): self + public static function fromThrowable(\Throwable $throwable): self { return new self($throwable->getMessage(), (int) $throwable->getCode(), $throwable); } diff --git a/src/Exception/NsqException.php b/src/Exception/NsqException.php index a81620b..0ca40f5 100644 --- a/src/Exception/NsqException.php +++ b/src/Exception/NsqException.php @@ -4,8 +4,6 @@ declare(strict_types=1); namespace Nsq\Exception; -use RuntimeException; - -class NsqException extends RuntimeException +class NsqException extends \RuntimeException { } diff --git a/src/NsqSocket.php b/src/NsqSocket.php index c41353a..cb6966a 100644 --- a/src/NsqSocket.php +++ b/src/NsqSocket.php @@ -8,7 +8,6 @@ use Nsq\Exception\ConnectionFail; use Nsq\Socket\Socket; use PHPinnacle\Buffer\ByteBuffer; use Throwable; -use const PHP_EOL; final class NsqSocket { diff --git a/src/Protocol/Error.php b/src/Protocol/Error.php index a480f3f..ae789e6 100644 --- a/src/Protocol/Error.php +++ b/src/Protocol/Error.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Nsq\Protocol; use Nsq\Bytes; -use function explode; /** * @psalm-immutable diff --git a/src/Protocol/Response.php b/src/Protocol/Response.php index 4340ab8..9850e45 100644 --- a/src/Protocol/Response.php +++ b/src/Protocol/Response.php @@ -5,8 +5,6 @@ declare(strict_types=1); namespace Nsq\Protocol; use Nsq\Bytes; -use function json_decode; -use const JSON_THROW_ON_ERROR; /** * @psalm-immutable diff --git a/src/Reconnect/ExponentialStrategy.php b/src/Reconnect/ExponentialStrategy.php index 33626a1..2454977 100644 --- a/src/Reconnect/ExponentialStrategy.php +++ b/src/Reconnect/ExponentialStrategy.php @@ -8,7 +8,6 @@ use Nsq\Exception\ConnectionFail; use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Throwable; final class ExponentialStrategy implements ReconnectStrategy { @@ -47,7 +46,7 @@ final class ExponentialStrategy implements ReconnectStrategy try { $callable(); - } catch (Throwable $e) { + } catch (\Throwable $e) { $nextDelay = 0 === $this->delay ? $this->minDelay : $this->delay * 2; $this->delay = $nextDelay > $this->maxDelay ? $this->maxDelay : $nextDelay; $this->nextTryAfter = $currentTime + $this->delay; diff --git a/src/Socket/DeflateSocket.php b/src/Socket/DeflateSocket.php index d077e74..8aadc3a 100644 --- a/src/Socket/DeflateSocket.php +++ b/src/Socket/DeflateSocket.php @@ -4,8 +4,6 @@ declare(strict_types=1); namespace Nsq\Socket; -use LogicException; - final class DeflateSocket implements Socket { public function __construct( @@ -18,7 +16,7 @@ final class DeflateSocket implements Socket */ public function write(string $data): void { - throw new LogicException('not implemented.'); + throw new \LogicException('not implemented.'); } /** @@ -26,7 +24,7 @@ final class DeflateSocket implements Socket */ public function read(int $length): string { - throw new LogicException('not implemented.'); + throw new \LogicException('not implemented.'); } /** @@ -34,7 +32,7 @@ final class DeflateSocket implements Socket */ public function close(): void { - throw new LogicException('not implemented.'); + throw new \LogicException('not implemented.'); } /** diff --git a/src/Socket/SnappySocket.php b/src/Socket/SnappySocket.php index 50d41d3..ac22e34 100644 --- a/src/Socket/SnappySocket.php +++ b/src/Socket/SnappySocket.php @@ -6,10 +6,6 @@ namespace Nsq\Socket; use PHPinnacle\Buffer\ByteBuffer; use Psr\Log\LoggerInterface; -use function hash; -use function pack; -use function str_split; -use function unpack; final class SnappySocket implements Socket { diff --git a/tests/Protocol/ErrorTypeTest.php b/tests/Protocol/ErrorTypeTest.php index 2a3ba5a..b9fdc83 100644 --- a/tests/Protocol/ErrorTypeTest.php +++ b/tests/Protocol/ErrorTypeTest.php @@ -4,10 +4,8 @@ declare(strict_types=1); namespace Protocol; -use Generator; use Nsq\Protocol\ErrorType; use PHPUnit\Framework\TestCase; -use ReflectionClass; final class ErrorTypeTest extends TestCase { @@ -21,11 +19,11 @@ final class ErrorTypeTest extends TestCase } /** - * @return Generator> + * @return \Generator> */ - public function data(): Generator + public function data(): \Generator { - foreach ((new ReflectionClass(ErrorType::class))->getConstants() as $constant => $isTerminated) { + foreach ((new \ReflectionClass(ErrorType::class))->getConstants() as $constant => $isTerminated) { yield $constant => [$constant, $isTerminated]; } }