cs: don't import globals

This commit is contained in:
2021-02-01 02:49:53 +03:00
parent f6ef057e40
commit b2b444d1ef
13 changed files with 15 additions and 43 deletions

View File

@ -9,9 +9,10 @@ return (new PhpCsFixer\Config())
'@PSR12' => true, '@PSR12' => true,
'@PSR12:risky' => true, '@PSR12:risky' => true,
'blank_line_before_statement' => [ '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, 'declare_strict_types' => true,
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
'php_unit_internal_class' => false, 'php_unit_internal_class' => false,
'php_unit_test_case_static_method_calls'=> ['call_type' => 'self'], 'php_unit_test_case_static_method_calls'=> ['call_type' => 'self'],
'php_unit_test_class_requires_covers' => false, 'php_unit_test_class_requires_covers' => false,

View File

@ -5,12 +5,6 @@ declare(strict_types=1);
namespace Nsq\Config; namespace Nsq\Config;
use Composer\InstalledVersions; 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 * 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 * @psalm-immutable
*/ */
final class ClientConfig implements JsonSerializable final class ClientConfig implements \JsonSerializable
{ {
/** /**
* @psalm-suppress ImpureFunctionCall * @psalm-suppress ImpureFunctionCall
@ -116,7 +110,7 @@ final class ClientConfig implements JsonSerializable
} }
if ($this->snappy && $this->deflate) { 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]');
} }
} }

View File

@ -22,11 +22,6 @@ use Nsq\Socket\SnappySocket;
use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
use Throwable;
use function addcslashes;
use function http_build_query;
use function implode;
use const PHP_EOL;
/** /**
* @internal * @internal
@ -111,7 +106,7 @@ abstract class Connection
try { try {
$this->command('CLS'); $this->command('CLS');
$this->socket->close(); $this->socket->close();
} catch (Throwable) { } catch (\Throwable $e) {
} }
$this->closed = true; $this->closed = true;

View File

@ -12,7 +12,6 @@ use Nsq\Protocol\Error;
use Nsq\Protocol\Message; use Nsq\Protocol\Message;
use Nsq\Protocol\Response; use Nsq\Protocol\Response;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use function microtime;
final class Consumer extends Connection final class Consumer extends Connection
{ {
@ -31,7 +30,7 @@ final class Consumer extends Connection
/** /**
* @psalm-return Generator<int, Message|float|null, int|null, void> * @psalm-return Generator<int, Message|float|null, int|null, void>
*/ */
public function generator(): Generator public function generator(): \Generator
{ {
$this->command('SUB', [$this->topic, $this->channel])->checkIsOK(); $this->command('SUB', [$this->topic, $this->channel])->checkIsOK();

View File

@ -4,14 +4,12 @@ declare(strict_types=1);
namespace Nsq\Exception; namespace Nsq\Exception;
use Throwable;
final class ConnectionFail extends NsqException final class ConnectionFail extends NsqException
{ {
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public static function fromThrowable(Throwable $throwable): self public static function fromThrowable(\Throwable $throwable): self
{ {
return new self($throwable->getMessage(), (int) $throwable->getCode(), $throwable); return new self($throwable->getMessage(), (int) $throwable->getCode(), $throwable);
} }

View File

@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Nsq\Exception; namespace Nsq\Exception;
use RuntimeException; class NsqException extends \RuntimeException
class NsqException extends RuntimeException
{ {
} }

View File

@ -8,7 +8,6 @@ use Nsq\Exception\ConnectionFail;
use Nsq\Socket\Socket; use Nsq\Socket\Socket;
use PHPinnacle\Buffer\ByteBuffer; use PHPinnacle\Buffer\ByteBuffer;
use Throwable; use Throwable;
use const PHP_EOL;
final class NsqSocket final class NsqSocket
{ {

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Nsq\Protocol; namespace Nsq\Protocol;
use Nsq\Bytes; use Nsq\Bytes;
use function explode;
/** /**
* @psalm-immutable * @psalm-immutable

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Nsq\Protocol; namespace Nsq\Protocol;
use Nsq\Bytes; use Nsq\Bytes;
use function json_decode;
use const JSON_THROW_ON_ERROR;
/** /**
* @psalm-immutable * @psalm-immutable

View File

@ -8,7 +8,6 @@ use Nsq\Exception\ConnectionFail;
use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
use Throwable;
final class ExponentialStrategy implements ReconnectStrategy final class ExponentialStrategy implements ReconnectStrategy
{ {
@ -47,7 +46,7 @@ final class ExponentialStrategy implements ReconnectStrategy
try { try {
$callable(); $callable();
} catch (Throwable $e) { } catch (\Throwable $e) {
$nextDelay = 0 === $this->delay ? $this->minDelay : $this->delay * 2; $nextDelay = 0 === $this->delay ? $this->minDelay : $this->delay * 2;
$this->delay = $nextDelay > $this->maxDelay ? $this->maxDelay : $nextDelay; $this->delay = $nextDelay > $this->maxDelay ? $this->maxDelay : $nextDelay;
$this->nextTryAfter = $currentTime + $this->delay; $this->nextTryAfter = $currentTime + $this->delay;

View File

@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Nsq\Socket; namespace Nsq\Socket;
use LogicException;
final class DeflateSocket implements Socket final class DeflateSocket implements Socket
{ {
public function __construct( public function __construct(
@ -18,7 +16,7 @@ final class DeflateSocket implements Socket
*/ */
public function write(string $data): void 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 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 public function close(): void
{ {
throw new LogicException('not implemented.'); throw new \LogicException('not implemented.');
} }
/** /**

View File

@ -6,10 +6,6 @@ namespace Nsq\Socket;
use PHPinnacle\Buffer\ByteBuffer; use PHPinnacle\Buffer\ByteBuffer;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use function hash;
use function pack;
use function str_split;
use function unpack;
final class SnappySocket implements Socket final class SnappySocket implements Socket
{ {

View File

@ -4,10 +4,8 @@ declare(strict_types=1);
namespace Protocol; namespace Protocol;
use Generator;
use Nsq\Protocol\ErrorType; use Nsq\Protocol\ErrorType;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use ReflectionClass;
final class ErrorTypeTest extends TestCase final class ErrorTypeTest extends TestCase
{ {
@ -21,11 +19,11 @@ final class ErrorTypeTest extends TestCase
} }
/** /**
* @return Generator<string, array<int, bool|string>> * @return \Generator<string, array<int, bool|string>>
*/ */
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]; yield $constant => [$constant, $isTerminated];
} }
} }