diff --git a/composer.json b/composer.json index 8f8b6db..1b17320 100644 --- a/composer.json +++ b/composer.json @@ -17,24 +17,27 @@ "amphp/socket": "^1.1", "composer/semver": "^3.2", "phpinnacle/buffer": "^1.2", - "psr/log": "^1.1" + "psr/log": "^3.0" }, "require-dev": { "amphp/log": "^1.1", - "dg/bypass-finals": "^1.3", "ergebnis/composer-normalize": "^2.15", - "friendsofphp/php-cs-fixer": "^3.0", - "infection/infection": "^0.23.0", + "friendsofphp/php-cs-fixer": "^3.4", + "infection/infection": "^0.26.13", "nyholm/nsa": "^1.2", - "phpstan/phpstan": "^0.12.68", - "phpstan/phpstan-phpunit": "^0.12.17", - "phpstan/phpstan-strict-rules": "^0.12.9", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.3", "phpunit/phpunit": "^9.5", - "symfony/var-dumper": "^5.3", + "symfony/var-dumper": "^6.1", "vimeo/psalm": "^4.4" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "ergebnis/composer-normalize": true, + "infection/extension-installer": true + } }, "autoload": { "psr-4": { diff --git a/examples/discovery/producer.php b/examples/discovery/producer.php index feb01e5..de32f0a 100644 --- a/examples/discovery/producer.php +++ b/examples/discovery/producer.php @@ -14,6 +14,7 @@ use Nsq\Config\ClientConfig; use Nsq\Config\LookupConfig; use Nsq\Lookup; use Nsq\Producer; + use function Amp\asyncCall; use function Amp\delay; @@ -55,7 +56,7 @@ Loop::run(static function () { unset($producers[$address]); }) ->connect() - ; + ; }); } diff --git a/examples/simple/consumer.php b/examples/simple/consumer.php index d946fb1..ecc4f19 100644 --- a/examples/simple/consumer.php +++ b/examples/simple/consumer.php @@ -14,6 +14,7 @@ use Monolog\Processor\PsrLogMessageProcessor; use Nsq\Config\ClientConfig; use Nsq\Consumer; use Nsq\Message; + use function Amp\call; Loop::run(static function () { diff --git a/psalm.xml b/psalm.xml index 54abdfa..c3c0f2f 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,5 @@ inflate = @inflate_init(ZLIB_ENCODING_RAW, ['level' => $this->level]); - $this->deflate = @deflate_init(ZLIB_ENCODING_RAW, ['level' => $this->level]); + $inflate = @inflate_init(ZLIB_ENCODING_RAW, ['level' => $this->level]); + $deflate = @deflate_init(ZLIB_ENCODING_RAW, ['level' => $this->level]); - if (false === $this->inflate) { + if (false === $inflate) { throw new StreamException('Failed initializing inflate context'); } - if (false === $this->deflate) { + if (false === $deflate) { throw new StreamException('Failed initializing deflate context'); } + $this->inflate = $inflate; + $this->deflate = $deflate; $this->buffer = new Buffer($bytes); } diff --git a/src/Stream/SnappyStream.php b/src/Stream/SnappyStream.php index 63d618f..3318281 100644 --- a/src/Stream/SnappyStream.php +++ b/src/Stream/SnappyStream.php @@ -8,18 +8,19 @@ use Amp\Promise; use Nsq\Buffer; use Nsq\Exception\SnappyException; use Nsq\Stream; + use function Amp\call; class SnappyStream implements Stream { - private const IDENTIFIER = [0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59]; + private const IDENTIFIER = [0xFF, 0x06, 0x00, 0x00, 0x73, 0x4E, 0x61, 0x50, 0x70, 0x59]; private const SIZE_HEADER = 4; private const SIZE_CHECKSUM = 4; private const SIZE_CHUNK = 65536; - private const TYPE_IDENTIFIER = 0xff; + private const TYPE_IDENTIFIER = 0xFF; private const TYPE_COMPRESSED = 0x00; private const TYPE_UNCOMPRESSED = 0x01; - private const TYPE_PADDING = 0xfe; + private const TYPE_PADDING = 0xFE; private Buffer $buffer; @@ -45,7 +46,7 @@ class SnappyStream implements Stream $type = $this->buffer->readUInt32LE(); $size = $type >> 8; - $type &= 0xff; + $type &= 0xFF; while ($this->buffer->size() < $size && null !== ($chunk = yield $this->stream->read())) { $this->buffer->append($chunk); @@ -106,7 +107,7 @@ class SnappyStream implements Stream /** @phpstan-ignore-next-line */ $checksum = unpack('N', hash('crc32c', $uncompressed, true))[1]; - $checksum = (($checksum >> 15) | ($checksum << 17)) + 0xa282ead8 & 0xffffffff; + $checksum = (($checksum >> 15) | ($checksum << 17)) + 0xA282EAD8 & 0xFFFFFFFF; $size = (\strlen($data) + 4) << 8; diff --git a/src/Stream/SocketStream.php b/src/Stream/SocketStream.php index 3cf0eee..f00e9aa 100644 --- a/src/Stream/SocketStream.php +++ b/src/Stream/SocketStream.php @@ -9,6 +9,7 @@ use Amp\Socket\ClientTlsContext; use Amp\Socket\ConnectContext; use Amp\Socket\EncryptableSocket; use Nsq\Stream; + use function Amp\call; use function Amp\Socket\connect;