From 70c483868144353d3d51834406d0fae1c73cc3f5 Mon Sep 17 00:00:00 2001 From: Maksim Masukevich Date: Sat, 15 Aug 2020 16:17:12 +0200 Subject: [PATCH 01/58] update amphp/amp version --- composer.json | 2 +- composer.lock | 611 +++++++++++++++++++++++++++++++------------------- 2 files changed, 385 insertions(+), 228 deletions(-) diff --git a/composer.json b/composer.json index cf1112c..bbfe5c1 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.2", - "amphp/amp": "v2.4.*", + "amphp/amp": "v2.5.*", "amphp/socket": "^1", "phpinnacle/buffer": "^1.0" }, diff --git a/composer.lock b/composer.lock index 85d2ed4..1ec0960 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "85fdb007b08e07a906e9198c358b1868", + "content-hash": "6abbae3e66cfc9b6e3c5be6dc3d09627", "packages": [ { "name": "amphp/amp", - "version": "v2.4.0", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/amphp/amp.git", - "reference": "13930a582947831bb66ff1aeac28672fd91c38ea" + "reference": "f220a51458bf4dd0dedebb171ac3457813c72bbc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/amp/zipball/13930a582947831bb66ff1aeac28672fd91c38ea", - "reference": "13930a582947831bb66ff1aeac28672fd91c38ea", + "url": "https://api.github.com/repos/amphp/amp/zipball/f220a51458bf4dd0dedebb171ac3457813c72bbc", + "reference": "f220a51458bf4dd0dedebb171ac3457813c72bbc", "shasum": "" }, "require": { @@ -27,14 +27,15 @@ "amphp/php-cs-fixer-config": "dev-master", "amphp/phpunit-util": "^1", "ext-json": "*", - "phpstan/phpstan": "^0.8.5", + "jetbrains/phpstorm-stubs": "^2019.3", "phpunit/phpunit": "^6.0.9 | ^7", + "psalm/phar": "^3.11@dev", "react/promise": "^2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.x-dev" } }, "autoload": { @@ -81,33 +82,40 @@ "non-blocking", "promise" ], - "time": "2019-11-11T19:32:05+00:00" + "time": "2020-07-14T21:47:18+00:00" }, { "name": "amphp/byte-stream", - "version": "v1.7.1", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/amphp/byte-stream.git", - "reference": "9d8205686a004948475dc43f8a88d2fa5e75a113" + "reference": "f0c20cf598a958ba2aa8c6e5a71c697d652c7088" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/byte-stream/zipball/9d8205686a004948475dc43f8a88d2fa5e75a113", - "reference": "9d8205686a004948475dc43f8a88d2fa5e75a113", + "url": "https://api.github.com/repos/amphp/byte-stream/zipball/f0c20cf598a958ba2aa8c6e5a71c697d652c7088", + "reference": "f0c20cf598a958ba2aa8c6e5a71c697d652c7088", "shasum": "" }, "require": { - "amphp/amp": "^2" + "amphp/amp": "^2", + "php": ">=7.1" }, "require-dev": { "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1", + "amphp/phpunit-util": "^1.4", "friendsofphp/php-cs-fixer": "^2.3", - "infection/infection": "^0.9.3", - "phpunit/phpunit": "^6" + "jetbrains/phpstorm-stubs": "^2019.3", + "phpunit/phpunit": "^6 || ^7 || ^8", + "psalm/phar": "^3.11.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, "autoload": { "psr-4": { "Amp\\ByteStream\\": "lib" @@ -140,24 +148,25 @@ "non-blocking", "stream" ], - "time": "2019-10-27T14:33:41+00:00" + "time": "2020-06-29T18:35:05+00:00" }, { "name": "amphp/cache", - "version": "v1.3.0", + "version": "v1.4.0", "source": { "type": "git", "url": "https://github.com/amphp/cache.git", - "reference": "14d9fa01a2518eda31b10a421660b41a55249736" + "reference": "e7bccc526fc2a555d59e6ee8380eeb39a95c0835" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/cache/zipball/14d9fa01a2518eda31b10a421660b41a55249736", - "reference": "14d9fa01a2518eda31b10a421660b41a55249736", + "url": "https://api.github.com/repos/amphp/cache/zipball/e7bccc526fc2a555d59e6ee8380eeb39a95c0835", + "reference": "e7bccc526fc2a555d59e6ee8380eeb39a95c0835", "shasum": "" }, "require": { "amphp/amp": "^2", + "amphp/serialization": "^1", "amphp/sync": "^1.2", "php": ">=7.1" }, @@ -165,10 +174,11 @@ "amphp/file": "<0.2 || >=2" }, "require-dev": { - "amphp/file": "^1.0", + "amphp/file": "^1", "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1", - "phpunit/phpunit": "^6 | ^7 | ^8" + "amphp/phpunit-util": "^1.1", + "phpunit/phpunit": "^6 | ^7 | ^8 | ^9", + "vimeo/psalm": "^3.11@dev" }, "type": "library", "autoload": { @@ -192,20 +202,20 @@ ], "description": "A promise-aware caching API for Amp.", "homepage": "https://github.com/amphp/cache", - "time": "2019-11-29T18:47:04+00:00" + "time": "2020-04-19T16:10:08+00:00" }, { "name": "amphp/dns", - "version": "v1.2.1", + "version": "v1.2.3", "source": { "type": "git", "url": "https://github.com/amphp/dns.git", - "reference": "9d7e57f37d21bfed8ff2e78db52b99d45ce0c215" + "reference": "852292532294d7972c729a96b49756d781f7c59d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/dns/zipball/9d7e57f37d21bfed8ff2e78db52b99d45ce0c215", - "reference": "9d7e57f37d21bfed8ff2e78db52b99d45ce0c215", + "url": "https://api.github.com/repos/amphp/dns/zipball/852292532294d7972c729a96b49756d781f7c59d", + "reference": "852292532294d7972c729a96b49756d781f7c59d", "shasum": "" }, "require": { @@ -222,7 +232,7 @@ "require-dev": { "amphp/php-cs-fixer-config": "dev-master", "amphp/phpunit-util": "^1", - "phpunit/phpunit": "^6" + "phpunit/phpunit": "^6 || ^7 || ^8 || ^9" }, "type": "library", "autoload": { @@ -269,7 +279,7 @@ "dns", "resolve" ], - "time": "2019-11-28T20:10:22+00:00" + "time": "2020-07-21T19:04:57+00:00" }, { "name": "amphp/parser", @@ -378,17 +388,71 @@ "time": "2019-02-26T16:33:03+00:00" }, { - "name": "amphp/socket", + "name": "amphp/serialization", "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/amphp/serialization.git", + "reference": "693e77b2fb0b266c3c7d622317f881de44ae94a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/amphp/serialization/zipball/693e77b2fb0b266c3c7d622317f881de44ae94a1", + "reference": "693e77b2fb0b266c3c7d622317f881de44ae94a1", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "amphp/php-cs-fixer-config": "dev-master", + "phpunit/phpunit": "^9 || ^8 || ^7" + }, + "type": "library", + "autoload": { + "psr-4": { + "Amp\\Serialization\\": "src" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Aaron Piotrowski", + "email": "aaron@trowski.com" + }, + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + } + ], + "description": "Serialization tools for IPC and data storage in PHP.", + "homepage": "https://github.com/amphp/serialization", + "keywords": [ + "async", + "asynchronous", + "serialization", + "serialize" + ], + "time": "2020-03-25T21:39:07+00:00" + }, + { + "name": "amphp/socket", + "version": "v1.1.3", "source": { "type": "git", "url": "https://github.com/amphp/socket.git", - "reference": "abc18f1786363ceee2555ffd7fe87e4eead2ce24" + "reference": "b9064b98742d12f8f438eaf73369bdd7d8446331" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/socket/zipball/abc18f1786363ceee2555ffd7fe87e4eead2ce24", - "reference": "abc18f1786363ceee2555ffd7fe87e4eead2ce24", + "url": "https://api.github.com/repos/amphp/socket/zipball/b9064b98742d12f8f438eaf73369bdd7d8446331", + "reference": "b9064b98742d12f8f438eaf73369bdd7d8446331", "shasum": "" }, "require": { @@ -403,10 +467,15 @@ "require-dev": { "amphp/php-cs-fixer-config": "dev-master", "amphp/phpunit-util": "^1", - "league/uri-schemes": "^1.2.1", - "phpunit/phpunit": "^6" + "phpunit/phpunit": "^6 || ^7 || ^8", + "vimeo/psalm": "^3.9@dev" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, "autoload": { "psr-4": { "Amp\\Socket\\": "src" @@ -445,20 +514,20 @@ "tcp", "tls" ], - "time": "2019-08-01T19:32:46+00:00" + "time": "2020-06-25T18:55:28+00:00" }, { "name": "amphp/sync", - "version": "v1.3.0", + "version": "v1.4.0", "source": { "type": "git", "url": "https://github.com/amphp/sync.git", - "reference": "512d62e83c8b8d5c848183005c70e70df2bcca55" + "reference": "613047ac54c025aa800a9cde5b05c3add7327ed4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/sync/zipball/512d62e83c8b8d5c848183005c70e70df2bcca55", - "reference": "512d62e83c8b8d5c848183005c70e70df2bcca55", + "url": "https://api.github.com/repos/amphp/sync/zipball/613047ac54c025aa800a9cde5b05c3add7327ed4", + "reference": "613047ac54c025aa800a9cde5b05c3add7327ed4", "shasum": "" }, "require": { @@ -468,7 +537,7 @@ "require-dev": { "amphp/php-cs-fixer-config": "dev-master", "amphp/phpunit-util": "^1.1", - "phpunit/phpunit": "^8 || ^7" + "phpunit/phpunit": "^9 || ^8 || ^7" }, "type": "library", "autoload": { @@ -476,7 +545,8 @@ "Amp\\Sync\\": "src" }, "files": [ - "src/functions.php" + "src/functions.php", + "src/ConcurrentIterator/functions.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -502,20 +572,20 @@ "semaphore", "synchronization" ], - "time": "2019-11-08T18:42:56+00:00" + "time": "2020-05-07T18:57:50+00:00" }, { "name": "amphp/windows-registry", - "version": "v0.3.2", + "version": "v0.3.3", "source": { "type": "git", "url": "https://github.com/amphp/windows-registry.git", - "reference": "834af7a30ad7c006b0326ccd2686ddc6e6943366" + "reference": "0f56438b9197e224325e88f305346f0221df1f71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/windows-registry/zipball/834af7a30ad7c006b0326ccd2686ddc6e6943366", - "reference": "834af7a30ad7c006b0326ccd2686ddc6e6943366", + "url": "https://api.github.com/repos/amphp/windows-registry/zipball/0f56438b9197e224325e88f305346f0221df1f71", + "reference": "0f56438b9197e224325e88f305346f0221df1f71", "shasum": "" }, "require": { @@ -543,7 +613,7 @@ } ], "description": "Windows Registry Reader.", - "time": "2018-10-24T03:34:54+00:00" + "time": "2020-07-10T16:13:29+00:00" }, { "name": "daverandom/libdns", @@ -758,16 +828,16 @@ "packages-dev": [ { "name": "beberlei/assert", - "version": "v3.2.6", + "version": "v3.2.7", "source": { "type": "git", "url": "https://github.com/beberlei/assert.git", - "reference": "99508be011753690fe108ded450f5caaae180cfa" + "reference": "d63a6943fc4fd1a2aedb65994e3548715105abcf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/beberlei/assert/zipball/99508be011753690fe108ded450f5caaae180cfa", - "reference": "99508be011753690fe108ded450f5caaae180cfa", + "url": "https://api.github.com/repos/beberlei/assert/zipball/d63a6943fc4fd1a2aedb65994e3548715105abcf", + "reference": "d63a6943fc4fd1a2aedb65994e3548715105abcf", "shasum": "" }, "require": { @@ -816,34 +886,36 @@ "assertion", "validation" ], - "time": "2019-10-10T10:33:57+00:00" + "time": "2019-12-19T17:51:41+00:00" }, { "name": "doctrine/annotations", - "version": "v1.8.0", + "version": "1.10.4", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc" + "reference": "bfe91e31984e2ba76df1c1339681770401ec262f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/904dca4eb10715b92569fbcd79e201d5c349b6bc", - "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/bfe91e31984e2ba76df1c1339681770401ec262f", + "reference": "bfe91e31984e2ba76df1c1339681770401ec262f", "shasum": "" }, "require": { "doctrine/lexer": "1.*", - "php": "^7.1" + "ext-tokenizer": "*", + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/cache": "1.*", - "phpunit/phpunit": "^7.5" + "phpstan/phpstan": "^0.12.20", + "phpunit/phpunit": "^7.5 || ^9.1.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.9.x-dev" } }, "autoload": { @@ -884,24 +956,24 @@ "docblock", "parser" ], - "time": "2019-10-01T18:55:10+00:00" + "time": "2020-08-10T19:35:50+00:00" }, { "name": "doctrine/instantiator", - "version": "1.3.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "ae466f726242e637cebdd526a7d991b9433bacf1" + "reference": "f350df0268e904597e3bd9c4685c53e0e333feea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1", - "reference": "ae466f726242e637cebdd526a7d991b9433bacf1", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f350df0268e904597e3bd9c4685c53e0e333feea", + "reference": "f350df0268e904597e3bd9c4685c53e0e333feea", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^6.0", @@ -940,24 +1012,24 @@ "constructor", "instantiate" ], - "time": "2019-10-21T16:45:58+00:00" + "time": "2020-05-29T17:27:14+00:00" }, { "name": "doctrine/lexer", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/doctrine/lexer.git", - "reference": "5242d66dbeb21a30dd8a3e66bf7a73b66e05e1f6" + "reference": "e864bbf5904cb8f5bb334f99209b48018522f042" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/5242d66dbeb21a30dd8a3e66bf7a73b66e05e1f6", - "reference": "5242d66dbeb21a30dd8a3e66bf7a73b66e05e1f6", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/e864bbf5904cb8f5bb334f99209b48018522f042", + "reference": "e864bbf5904cb8f5bb334f99209b48018522f042", "shasum": "" }, "require": { - "php": "^7.2" + "php": "^7.2 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^6.0", @@ -1002,20 +1074,20 @@ "parser", "php" ], - "time": "2019-10-30T14:39:59+00:00" + "time": "2020-05-25T17:44:05+00:00" }, { "name": "lstrojny/functional-php", - "version": "1.10.0", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/lstrojny/functional-php.git", - "reference": "809947093034cb9db1ce69b8b4536f4bbb6fe93e" + "reference": "11610f50323519dd38bd7b527d6730e524e5eb58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/lstrojny/functional-php/zipball/809947093034cb9db1ce69b8b4536f4bbb6fe93e", - "reference": "809947093034cb9db1ce69b8b4536f4bbb6fe93e", + "url": "https://api.github.com/repos/lstrojny/functional-php/zipball/11610f50323519dd38bd7b527d6730e524e5eb58", + "reference": "11610f50323519dd38bd7b527d6730e524e5eb58", "shasum": "" }, "require": { @@ -1023,7 +1095,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.14", - "phpunit/phpunit": "~6", + "phpunit/phpunit": "~7", "squizlabs/php_codesniffer": "~3.0" }, "type": "library", @@ -1032,6 +1104,7 @@ "Functional\\": "src/Functional" }, "files": [ + "src/Functional/Ary.php", "src/Functional/Average.php", "src/Functional/ButLast.php", "src/Functional/Capture.php", @@ -1084,7 +1157,9 @@ "src/Functional/Memoize.php", "src/Functional/Minimum.php", "src/Functional/None.php", + "src/Functional/Noop.php", "src/Functional/Not.php", + "src/Functional/OmitKeys.php", "src/Functional/PartialAny.php", "src/Functional/PartialLeft.php", "src/Functional/PartialMethod.php", @@ -1142,24 +1217,24 @@ "keywords": [ "functional" ], - "time": "2019-09-26T09:38:13+00:00" + "time": "2020-06-16T09:17:22+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.9.4", + "version": "1.10.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "579bb7356d91f9456ccd505f24ca8b667966a0a7" + "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/579bb7356d91f9456ccd505f24ca8b667966a0a7", - "reference": "579bb7356d91f9456ccd505f24ca8b667966a0a7", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", + "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1 || ^8.0" }, "replace": { "myclabs/deep-copy": "self.version" @@ -1190,7 +1265,7 @@ "object", "object graph" ], - "time": "2019-12-15T19:12:40+00:00" + "time": "2020-06-29T13:22:24+00:00" }, { "name": "phar-io/manifest", @@ -1461,28 +1536,25 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "2.0.0", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b", + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b", "shasum": "" }, "require": { - "php": ">=7.1" - }, - "require-dev": { - "phpunit/phpunit": "~6" + "php": "^7.2 || ^8.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-2.x": "2.x-dev" } }, "autoload": { @@ -1509,44 +1581,41 @@ "reflection", "static analysis" ], - "time": "2018-08-07T13:53:10+00:00" + "time": "2020-06-27T09:03:43+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.2", + "version": "5.2.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" + "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d870572532cd70bc3fab58f2e23ad423c8404c44", + "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44", "shasum": "" }, "require": { - "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", - "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", - "webmozart/assert": "^1.0" + "ext-filter": "*", + "php": "^7.2 || ^8.0", + "phpdocumentor/reflection-common": "^2.2", + "phpdocumentor/type-resolver": "^1.3", + "webmozart/assert": "^1.9.1" }, "require-dev": { - "doctrine/instantiator": "^1.0.5", - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^6.4" + "mockery/mockery": "~1.3.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev" + "dev-master": "5.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1557,38 +1626,40 @@ { "name": "Mike van Riel", "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2019-09-12T14:27:41+00:00" + "time": "2020-08-15T11:14:08+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.0.1", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" + "reference": "e878a14a65245fbe78f8080eba03b47c3b705651" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e878a14a65245fbe78f8080eba03b47c3b705651", + "reference": "e878a14a65245fbe78f8080eba03b47c3b705651", "shasum": "" }, "require": { - "php": "^7.1", + "php": "^7.2 || ^8.0", "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "ext-tokenizer": "^7.1", - "mockery/mockery": "~1", - "phpunit/phpunit": "^7.0" + "ext-tokenizer": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.x-dev" + "dev-1.x": "1.x-dev" } }, "autoload": { @@ -1607,37 +1678,37 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2019-08-22T18:11:29+00:00" + "time": "2020-06-27T10:12:23+00:00" }, { "name": "phpspec/prophecy", - "version": "1.10.0", + "version": "1.11.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "d638ebbb58daba25a6a0dc7969e1358a0e3c6682" + "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/d638ebbb58daba25a6a0dc7969e1358a0e3c6682", - "reference": "d638ebbb58daba25a6a0dc7969e1358a0e3c6682", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/b20034be5efcdab4fb60ca3a29cba2949aead160", + "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", - "sebastian/comparator": "^1.2.3|^2.0|^3.0", - "sebastian/recursion-context": "^1.0|^2.0|^3.0" + "doctrine/instantiator": "^1.2", + "php": "^7.2", + "phpdocumentor/reflection-docblock": "^5.0", + "sebastian/comparator": "^3.0 || ^4.0", + "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { - "phpspec/phpspec": "^2.5 || ^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + "phpspec/phpspec": "^6.0", + "phpunit/phpunit": "^8.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.10.x-dev" + "dev-master": "1.11.x-dev" } }, "autoload": { @@ -1670,7 +1741,7 @@ "spy", "stub" ], - "time": "2019-12-17T16:54:23+00:00" + "time": "2020-07-08T12:44:21+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1922,20 +1993,21 @@ "keywords": [ "tokenizer" ], + "abandoned": true, "time": "2019-09-17T06:23:10+00:00" }, { "name": "phpunit/phpunit", - "version": "8.5.0", + "version": "8.5.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3ee1c1fd6fc264480c25b6fb8285edefe1702dab" + "reference": "34c18baa6a44f1d1fbf0338907139e9dce95b997" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3ee1c1fd6fc264480c25b6fb8285edefe1702dab", - "reference": "3ee1c1fd6fc264480c25b6fb8285edefe1702dab", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/34c18baa6a44f1d1fbf0338907139e9dce95b997", + "reference": "34c18baa6a44f1d1fbf0338907139e9dce95b997", "shasum": "" }, "require": { @@ -2005,7 +2077,7 @@ "testing", "xunit" ], - "time": "2019-12-06T05:41:38+00:00" + "time": "2020-06-22T07:06:58+00:00" }, { "name": "psr/container", @@ -2058,16 +2130,16 @@ }, { "name": "psr/log", - "version": "1.1.2", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801" + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/446d54b4cb6bf489fc9d75f55843658e6f25d801", - "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801", + "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", "shasum": "" }, "require": { @@ -2101,7 +2173,7 @@ "psr", "psr-3" ], - "time": "2019-11-01T11:05:21+00:00" + "time": "2020-03-23T09:12:05+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -2720,20 +2792,20 @@ }, { "name": "seld/jsonlint", - "version": "1.7.2", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "e2e5d290e4d2a4f0eb449f510071392e00e10d19" + "reference": "3d5eb71705adfa34bd34b993400622932b2f62fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/e2e5d290e4d2a4f0eb449f510071392e00e10d19", - "reference": "e2e5d290e4d2a4f0eb449f510071392e00e10d19", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/3d5eb71705adfa34bd34b993400622932b2f62fd", + "reference": "3d5eb71705adfa34bd34b993400622932b2f62fd", "shasum": "" }, "require": { - "php": "^5.3 || ^7.0" + "php": "^5.3 || ^7.0 || ^8.0" }, "require-dev": { "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" @@ -2765,26 +2837,27 @@ "parser", "validator" ], - "time": "2019-10-24T14:27:39+00:00" + "time": "2020-08-13T09:07:59+00:00" }, { "name": "symfony/console", - "version": "v4.4.1", + "version": "v4.4.11", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "f0aea3df20d15635b3cb9730ca5eea1c65b7f201" + "reference": "55d07021da933dd0d633ffdab6f45d5b230c7e02" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/f0aea3df20d15635b3cb9730ca5eea1c65b7f201", - "reference": "f0aea3df20d15635b3cb9730ca5eea1c65b7f201", + "url": "https://api.github.com/repos/symfony/console/zipball/55d07021da933dd0d633ffdab6f45d5b230c7e02", + "reference": "55d07021da933dd0d633ffdab6f45d5b230c7e02", "shasum": "" }, "require": { - "php": "^7.1.3", + "php": ">=7.1.3", "symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-php73": "^1.8", + "symfony/polyfill-php80": "^1.15", "symfony/service-contracts": "^1.1|^2" }, "conflict": { @@ -2841,25 +2914,26 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2019-12-01T10:06:17+00:00" + "time": "2020-07-06T13:18:39+00:00" }, { "name": "symfony/debug", - "version": "v4.4.1", + "version": "v4.4.11", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "b8600a1d7d20b0e80906398bb1f50612fa074a8e" + "reference": "47aa9064d75db36389692dd4d39895a0820f00f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/b8600a1d7d20b0e80906398bb1f50612fa074a8e", - "reference": "b8600a1d7d20b0e80906398bb1f50612fa074a8e", + "url": "https://api.github.com/repos/symfony/debug/zipball/47aa9064d75db36389692dd4d39895a0820f00f2", + "reference": "47aa9064d75db36389692dd4d39895a0820f00f2", "shasum": "" }, "require": { - "php": "^7.1.3", - "psr/log": "~1.0" + "php": ">=7.1.3", + "psr/log": "~1.0", + "symfony/polyfill-php80": "^1.15" }, "conflict": { "symfony/http-kernel": "<3.4" @@ -2897,24 +2971,24 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2019-11-28T13:33:56+00:00" + "time": "2020-07-23T08:31:43+00:00" }, { "name": "symfony/filesystem", - "version": "v4.4.1", + "version": "v4.4.11", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "40c2606131d56eff6f193b6e2ceb92414653b591" + "reference": "b27f491309db5757816db672b256ea2e03677d30" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/40c2606131d56eff6f193b6e2ceb92414653b591", - "reference": "40c2606131d56eff6f193b6e2ceb92414653b591", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b27f491309db5757816db672b256ea2e03677d30", + "reference": "b27f491309db5757816db672b256ea2e03677d30", "shasum": "" }, "require": { - "php": "^7.1.3", + "php": ">=7.1.3", "symfony/polyfill-ctype": "~1.8" }, "type": "library", @@ -2947,24 +3021,24 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2019-11-26T23:16:41+00:00" + "time": "2020-05-30T18:50:54+00:00" }, { "name": "symfony/finder", - "version": "v4.4.1", + "version": "v4.4.11", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "ce8743441da64c41e2a667b8eb66070444ed911e" + "reference": "2727aa35fddfada1dd37599948528e9b152eb742" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/ce8743441da64c41e2a667b8eb66070444ed911e", - "reference": "ce8743441da64c41e2a667b8eb66070444ed911e", + "url": "https://api.github.com/repos/symfony/finder/zipball/2727aa35fddfada1dd37599948528e9b152eb742", + "reference": "2727aa35fddfada1dd37599948528e9b152eb742", "shasum": "" }, "require": { - "php": "^7.1.3" + "php": ">=7.1.3" }, "type": "library", "extra": { @@ -2996,24 +3070,24 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2019-11-17T21:56:56+00:00" + "time": "2020-07-05T09:39:30+00:00" }, { "name": "symfony/options-resolver", - "version": "v4.4.1", + "version": "v4.4.11", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "2be23e63f33de16b49294ea6581f462932a77e2f" + "reference": "376bd3a02e7946dbf90b01563361b47dde425025" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/2be23e63f33de16b49294ea6581f462932a77e2f", - "reference": "2be23e63f33de16b49294ea6581f462932a77e2f", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/376bd3a02e7946dbf90b01563361b47dde425025", + "reference": "376bd3a02e7946dbf90b01563361b47dde425025", "shasum": "" }, "require": { - "php": "^7.1.3" + "php": ">=7.1.3" }, "type": "library", "extra": { @@ -3050,20 +3124,20 @@ "configuration", "options" ], - "time": "2019-10-28T21:57:16+00:00" + "time": "2020-07-10T09:12:14+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.13.1", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3" + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454", + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454", "shasum": "" }, "require": { @@ -3075,7 +3149,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -3108,20 +3186,20 @@ "polyfill", "portable" ], - "time": "2019-11-27T13:56:44+00:00" + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.13.1", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f" + "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7b4aab9743c30be783b73de055d24a39cf4b954f", - "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/a6977d63bf9a0ad4c65cd352709e230876f9904a", + "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a", "shasum": "" }, "require": { @@ -3133,7 +3211,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -3167,20 +3249,20 @@ "portable", "shim" ], - "time": "2019-11-27T14:18:11+00:00" + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/polyfill-php73", - "version": "v1.13.1", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "4b0e2222c55a25b4541305a053013d5647d3a25f" + "reference": "fffa1a52a023e782cdcc221d781fe1ec8f87fcca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/4b0e2222c55a25b4541305a053013d5647d3a25f", - "reference": "4b0e2222c55a25b4541305a053013d5647d3a25f", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fffa1a52a023e782cdcc221d781fe1ec8f87fcca", + "reference": "fffa1a52a023e782cdcc221d781fe1ec8f87fcca", "shasum": "" }, "require": { @@ -3189,7 +3271,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -3225,24 +3311,90 @@ "portable", "shim" ], - "time": "2019-11-27T16:25:15+00:00" + "time": "2020-07-14T12:35:20+00:00" + }, + { + "name": "symfony/polyfill-php80", + "version": "v1.18.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "d87d5766cbf48d72388a9f6b85f280c8ad51f981" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/d87d5766cbf48d72388a9f6b85f280c8ad51f981", + "reference": "d87d5766cbf48d72388a9f6b85f280c8ad51f981", + "shasum": "" + }, + "require": { + "php": ">=7.0.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/process", - "version": "v4.4.1", + "version": "v4.4.11", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "51c0135ef3f44c5803b33dc60e96bf4f77752726" + "reference": "65e70bab62f3da7089a8d4591fb23fbacacb3479" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/51c0135ef3f44c5803b33dc60e96bf4f77752726", - "reference": "51c0135ef3f44c5803b33dc60e96bf4f77752726", + "url": "https://api.github.com/repos/symfony/process/zipball/65e70bab62f3da7089a8d4591fb23fbacacb3479", + "reference": "65e70bab62f3da7089a8d4591fb23fbacacb3479", "shasum": "" }, "require": { - "php": "^7.1.3" + "php": ">=7.1.3" }, "type": "library", "extra": { @@ -3274,24 +3426,24 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2019-11-28T13:33:56+00:00" + "time": "2020-07-23T08:31:43+00:00" }, { "name": "symfony/service-contracts", - "version": "v2.0.1", + "version": "v2.1.3", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "144c5e51266b281231e947b51223ba14acf1a749" + "reference": "58c7475e5457c5492c26cc740cc0ad7464be9442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/144c5e51266b281231e947b51223ba14acf1a749", - "reference": "144c5e51266b281231e947b51223ba14acf1a749", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/58c7475e5457c5492c26cc740cc0ad7464be9442", + "reference": "58c7475e5457c5492c26cc740cc0ad7464be9442", "shasum": "" }, "require": { - "php": "^7.2.5", + "php": ">=7.2.5", "psr/container": "^1.0" }, "suggest": { @@ -3300,7 +3452,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -3332,27 +3488,27 @@ "interoperability", "standards" ], - "time": "2019-11-18T17:27:11+00:00" + "time": "2020-07-06T13:23:11+00:00" }, { "name": "theseer/tokenizer", - "version": "1.1.3", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" + "reference": "75a63c33a8577608444246075ea0af0d052e452a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", - "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", + "reference": "75a63c33a8577608444246075ea0af0d052e452a", "shasum": "" }, "require": { "ext-dom": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": "^7.0" + "php": "^7.2 || ^8.0" }, "type": "library", "autoload": { @@ -3372,28 +3528,29 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2019-06-13T22:48:21+00:00" + "time": "2020-07-12T23:59:07+00:00" }, { "name": "webmozart/assert", - "version": "1.6.0", + "version": "1.9.1", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925" + "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/573381c0a64f155a0d9a23f4b0c797194805b925", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925", + "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", + "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0", + "php": "^5.3.3 || ^7.0 || ^8.0", "symfony/polyfill-ctype": "^1.8" }, "conflict": { - "vimeo/psalm": "<3.6.0" + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<3.9.1" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" @@ -3420,7 +3577,7 @@ "check", "validate" ], - "time": "2019-11-24T13:36:37+00:00" + "time": "2020-07-08T17:02:28+00:00" }, { "name": "webmozart/path-util", From 2e3dd73040eddbf9055ea3d465bf54b06c5decbb Mon Sep 17 00:00:00 2001 From: Maksim Masukevich Date: Sat, 15 Aug 2020 20:38:30 +0200 Subject: [PATCH 02/58] commit versions of dependencies --- composer.json | 4 +- composer.lock | 3638 ------------------------------------------------- 2 files changed, 2 insertions(+), 3640 deletions(-) delete mode 100644 composer.lock diff --git a/composer.json b/composer.json index bbfe5c1..4593eca 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "require": { "php": "^7.2", "amphp/amp": "v2.5.*", - "amphp/socket": "^1", - "phpinnacle/buffer": "^1.0" + "amphp/socket": "v1.1.*", + "phpinnacle/buffer": "v1.0.*" }, "require-dev": { "phpbench/phpbench": "^0.16", diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 1ec0960..0000000 --- a/composer.lock +++ /dev/null @@ -1,3638 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "6abbae3e66cfc9b6e3c5be6dc3d09627", - "packages": [ - { - "name": "amphp/amp", - "version": "v2.5.0", - "source": { - "type": "git", - "url": "https://github.com/amphp/amp.git", - "reference": "f220a51458bf4dd0dedebb171ac3457813c72bbc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/amp/zipball/f220a51458bf4dd0dedebb171ac3457813c72bbc", - "reference": "f220a51458bf4dd0dedebb171ac3457813c72bbc", - "shasum": "" - }, - "require": { - "php": ">=7" - }, - "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1", - "ext-json": "*", - "jetbrains/phpstorm-stubs": "^2019.3", - "phpunit/phpunit": "^6.0.9 | ^7", - "psalm/phar": "^3.11@dev", - "react/promise": "^2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Amp\\": "lib" - }, - "files": [ - "lib/functions.php", - "lib/Internal/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Daniel Lowrey", - "email": "rdlowrey@php.net" - }, - { - "name": "Aaron Piotrowski", - "email": "aaron@trowski.com" - }, - { - "name": "Bob Weinand", - "email": "bobwei9@hotmail.com" - }, - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - } - ], - "description": "A non-blocking concurrency framework for PHP applications.", - "homepage": "http://amphp.org/amp", - "keywords": [ - "async", - "asynchronous", - "awaitable", - "concurrency", - "event", - "event-loop", - "future", - "non-blocking", - "promise" - ], - "time": "2020-07-14T21:47:18+00:00" - }, - { - "name": "amphp/byte-stream", - "version": "v1.8.0", - "source": { - "type": "git", - "url": "https://github.com/amphp/byte-stream.git", - "reference": "f0c20cf598a958ba2aa8c6e5a71c697d652c7088" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/byte-stream/zipball/f0c20cf598a958ba2aa8c6e5a71c697d652c7088", - "reference": "f0c20cf598a958ba2aa8c6e5a71c697d652c7088", - "shasum": "" - }, - "require": { - "amphp/amp": "^2", - "php": ">=7.1" - }, - "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1.4", - "friendsofphp/php-cs-fixer": "^2.3", - "jetbrains/phpstorm-stubs": "^2019.3", - "phpunit/phpunit": "^6 || ^7 || ^8", - "psalm/phar": "^3.11.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Amp\\ByteStream\\": "lib" - }, - "files": [ - "lib/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Aaron Piotrowski", - "email": "aaron@trowski.com" - }, - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - } - ], - "description": "A stream abstraction to make working with non-blocking I/O simple.", - "homepage": "http://amphp.org/byte-stream", - "keywords": [ - "amp", - "amphp", - "async", - "io", - "non-blocking", - "stream" - ], - "time": "2020-06-29T18:35:05+00:00" - }, - { - "name": "amphp/cache", - "version": "v1.4.0", - "source": { - "type": "git", - "url": "https://github.com/amphp/cache.git", - "reference": "e7bccc526fc2a555d59e6ee8380eeb39a95c0835" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/cache/zipball/e7bccc526fc2a555d59e6ee8380eeb39a95c0835", - "reference": "e7bccc526fc2a555d59e6ee8380eeb39a95c0835", - "shasum": "" - }, - "require": { - "amphp/amp": "^2", - "amphp/serialization": "^1", - "amphp/sync": "^1.2", - "php": ">=7.1" - }, - "conflict": { - "amphp/file": "<0.2 || >=2" - }, - "require-dev": { - "amphp/file": "^1", - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1.1", - "phpunit/phpunit": "^6 | ^7 | ^8 | ^9", - "vimeo/psalm": "^3.11@dev" - }, - "type": "library", - "autoload": { - "psr-4": { - "Amp\\Cache\\": "lib" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - }, - { - "name": "Daniel Lowrey", - "email": "rdlowrey@php.net" - } - ], - "description": "A promise-aware caching API for Amp.", - "homepage": "https://github.com/amphp/cache", - "time": "2020-04-19T16:10:08+00:00" - }, - { - "name": "amphp/dns", - "version": "v1.2.3", - "source": { - "type": "git", - "url": "https://github.com/amphp/dns.git", - "reference": "852292532294d7972c729a96b49756d781f7c59d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/dns/zipball/852292532294d7972c729a96b49756d781f7c59d", - "reference": "852292532294d7972c729a96b49756d781f7c59d", - "shasum": "" - }, - "require": { - "amphp/amp": "^2", - "amphp/byte-stream": "^1.1", - "amphp/cache": "^1.2", - "amphp/parser": "^1", - "amphp/windows-registry": "^0.3", - "daverandom/libdns": "^2.0.1", - "ext-filter": "*", - "ext-json": "*", - "php": ">=7.0" - }, - "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1", - "phpunit/phpunit": "^6 || ^7 || ^8 || ^9" - }, - "type": "library", - "autoload": { - "psr-4": { - "Amp\\Dns\\": "lib" - }, - "files": [ - "lib/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Chris Wright", - "email": "addr@daverandom.com" - }, - { - "name": "Daniel Lowrey", - "email": "rdlowrey@php.net" - }, - { - "name": "Bob Weinand", - "email": "bobwei9@hotmail.com" - }, - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - }, - { - "name": "Aaron Piotrowski", - "email": "aaron@trowski.com" - } - ], - "description": "Async DNS resolution for Amp.", - "homepage": "https://github.com/amphp/dns", - "keywords": [ - "amp", - "amphp", - "async", - "client", - "dns", - "resolve" - ], - "time": "2020-07-21T19:04:57+00:00" - }, - { - "name": "amphp/parser", - "version": "v1.0.0", - "source": { - "type": "git", - "url": "https://github.com/amphp/parser.git", - "reference": "f83e68f03d5b8e8e0365b8792985a7f341c57ae1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/parser/zipball/f83e68f03d5b8e8e0365b8792985a7f341c57ae1", - "reference": "f83e68f03d5b8e8e0365b8792985a7f341c57ae1", - "shasum": "" - }, - "require": { - "php": ">=7" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.3", - "phpunit/phpunit": "^6" - }, - "type": "library", - "autoload": { - "psr-4": { - "Amp\\Parser\\": "lib" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - }, - { - "name": "Aaron Piotrowski", - "email": "aaron@trowski.com" - } - ], - "description": "A generator parser to make streaming parsers simple.", - "homepage": "https://github.com/amphp/parser", - "keywords": [ - "async", - "non-blocking", - "parser", - "stream" - ], - "time": "2017-06-06T05:29:10+00:00" - }, - { - "name": "amphp/process", - "version": "v1.1.0", - "source": { - "type": "git", - "url": "https://github.com/amphp/process.git", - "reference": "355b1e561b01c16ab3d78fada1ad47ccc96df70e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/process/zipball/355b1e561b01c16ab3d78fada1ad47ccc96df70e", - "reference": "355b1e561b01c16ab3d78fada1ad47ccc96df70e", - "shasum": "" - }, - "require": { - "amphp/amp": "^2", - "amphp/byte-stream": "^1.4", - "php": ">=7" - }, - "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1", - "phpunit/phpunit": "^6" - }, - "type": "library", - "autoload": { - "psr-4": { - "Amp\\Process\\": "lib" - }, - "files": [ - "lib/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bob Weinand", - "email": "bobwei9@hotmail.com" - }, - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - }, - { - "name": "Aaron Piotrowski", - "email": "aaron@trowski.com" - } - ], - "description": "Asynchronous process manager.", - "homepage": "https://github.com/amphp/process", - "time": "2019-02-26T16:33:03+00:00" - }, - { - "name": "amphp/serialization", - "version": "v1.0.0", - "source": { - "type": "git", - "url": "https://github.com/amphp/serialization.git", - "reference": "693e77b2fb0b266c3c7d622317f881de44ae94a1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/serialization/zipball/693e77b2fb0b266c3c7d622317f881de44ae94a1", - "reference": "693e77b2fb0b266c3c7d622317f881de44ae94a1", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "phpunit/phpunit": "^9 || ^8 || ^7" - }, - "type": "library", - "autoload": { - "psr-4": { - "Amp\\Serialization\\": "src" - }, - "files": [ - "src/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Aaron Piotrowski", - "email": "aaron@trowski.com" - }, - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - } - ], - "description": "Serialization tools for IPC and data storage in PHP.", - "homepage": "https://github.com/amphp/serialization", - "keywords": [ - "async", - "asynchronous", - "serialization", - "serialize" - ], - "time": "2020-03-25T21:39:07+00:00" - }, - { - "name": "amphp/socket", - "version": "v1.1.3", - "source": { - "type": "git", - "url": "https://github.com/amphp/socket.git", - "reference": "b9064b98742d12f8f438eaf73369bdd7d8446331" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/socket/zipball/b9064b98742d12f8f438eaf73369bdd7d8446331", - "reference": "b9064b98742d12f8f438eaf73369bdd7d8446331", - "shasum": "" - }, - "require": { - "amphp/amp": "^2", - "amphp/byte-stream": "^1.6", - "amphp/dns": "^1 || ^0.9", - "ext-openssl": "*", - "kelunik/certificate": "^1.1", - "league/uri-parser": "^1.4", - "php": ">=7.1" - }, - "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1", - "phpunit/phpunit": "^6 || ^7 || ^8", - "vimeo/psalm": "^3.9@dev" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Amp\\Socket\\": "src" - }, - "files": [ - "src/functions.php", - "src/Internal/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Daniel Lowrey", - "email": "rdlowrey@gmail.com" - }, - { - "name": "Aaron Piotrowski", - "email": "aaron@trowski.com" - }, - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - } - ], - "description": "Async socket connection / server tools for Amp.", - "homepage": "https://github.com/amphp/socket", - "keywords": [ - "amp", - "async", - "encryption", - "non-blocking", - "sockets", - "tcp", - "tls" - ], - "time": "2020-06-25T18:55:28+00:00" - }, - { - "name": "amphp/sync", - "version": "v1.4.0", - "source": { - "type": "git", - "url": "https://github.com/amphp/sync.git", - "reference": "613047ac54c025aa800a9cde5b05c3add7327ed4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/sync/zipball/613047ac54c025aa800a9cde5b05c3add7327ed4", - "reference": "613047ac54c025aa800a9cde5b05c3add7327ed4", - "shasum": "" - }, - "require": { - "amphp/amp": "^2.2", - "php": ">=7.1" - }, - "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1.1", - "phpunit/phpunit": "^9 || ^8 || ^7" - }, - "type": "library", - "autoload": { - "psr-4": { - "Amp\\Sync\\": "src" - }, - "files": [ - "src/functions.php", - "src/ConcurrentIterator/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Aaron Piotrowski", - "email": "aaron@trowski.com" - }, - { - "name": "Stephen Coakley", - "email": "me@stephencoakley.com" - } - ], - "description": "Mutex, Semaphore, and other synchronization tools for Amp.", - "homepage": "https://github.com/amphp/sync", - "keywords": [ - "async", - "asynchronous", - "mutex", - "semaphore", - "synchronization" - ], - "time": "2020-05-07T18:57:50+00:00" - }, - { - "name": "amphp/windows-registry", - "version": "v0.3.3", - "source": { - "type": "git", - "url": "https://github.com/amphp/windows-registry.git", - "reference": "0f56438b9197e224325e88f305346f0221df1f71" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/amphp/windows-registry/zipball/0f56438b9197e224325e88f305346f0221df1f71", - "reference": "0f56438b9197e224325e88f305346f0221df1f71", - "shasum": "" - }, - "require": { - "amphp/amp": "^2", - "amphp/byte-stream": "^1.4", - "amphp/process": "^1" - }, - "require-dev": { - "amphp/php-cs-fixer-config": "dev-master" - }, - "type": "library", - "autoload": { - "psr-4": { - "Amp\\WindowsRegistry\\": "lib" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - } - ], - "description": "Windows Registry Reader.", - "time": "2020-07-10T16:13:29+00:00" - }, - { - "name": "daverandom/libdns", - "version": "v2.0.2", - "source": { - "type": "git", - "url": "https://github.com/DaveRandom/LibDNS.git", - "reference": "e8b6d6593d18ac3a6a14666d8a68a4703b2e05f9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/DaveRandom/LibDNS/zipball/e8b6d6593d18ac3a6a14666d8a68a4703b2e05f9", - "reference": "e8b6d6593d18ac3a6a14666d8a68a4703b2e05f9", - "shasum": "" - }, - "require": { - "ext-ctype": "*", - "php": ">=7.0" - }, - "suggest": { - "ext-intl": "Required for IDN support" - }, - "type": "library", - "autoload": { - "psr-4": { - "LibDNS\\": "src/" - }, - "files": [ - "src/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "DNS protocol implementation written in pure PHP", - "keywords": [ - "dns" - ], - "time": "2019-12-03T09:12:46+00:00" - }, - { - "name": "kelunik/certificate", - "version": "v1.1.2", - "source": { - "type": "git", - "url": "https://github.com/kelunik/certificate.git", - "reference": "56542e62d51533d04d0a9713261fea546bff80f6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kelunik/certificate/zipball/56542e62d51533d04d0a9713261fea546bff80f6", - "reference": "56542e62d51533d04d0a9713261fea546bff80f6", - "shasum": "" - }, - "require": { - "ext-openssl": "*", - "php": ">=5.4" - }, - "require-dev": { - "fabpot/php-cs-fixer": "^1.9", - "phpunit/phpunit": "^4.8" - }, - "type": "library", - "autoload": { - "psr-4": { - "Kelunik\\Certificate\\": "lib" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Niklas Keller", - "email": "me@kelunik.com" - } - ], - "description": "Access certificate details and transform between different formats.", - "keywords": [ - "DER", - "certificate", - "certificates", - "openssl", - "pem", - "x509" - ], - "time": "2019-05-29T19:02:31+00:00" - }, - { - "name": "league/uri-parser", - "version": "1.4.1", - "source": { - "type": "git", - "url": "https://github.com/thephpleague/uri-parser.git", - "reference": "671548427e4c932352d9b9279fdfa345bf63fa00" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/thephpleague/uri-parser/zipball/671548427e4c932352d9b9279fdfa345bf63fa00", - "reference": "671548427e4c932352d9b9279fdfa345bf63fa00", - "shasum": "" - }, - "require": { - "php": ">=7.0.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.0", - "phpstan/phpstan": "^0.9.2", - "phpstan/phpstan-phpunit": "^0.9.4", - "phpstan/phpstan-strict-rules": "^0.9.0", - "phpunit/phpunit": "^6.0" - }, - "suggest": { - "ext-intl": "Allow parsing RFC3987 compliant hosts", - "league/uri-schemes": "Allow validating and normalizing URI parsing results" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "League\\Uri\\": "src" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ignace Nyamagana Butera", - "email": "nyamsprod@gmail.com", - "homepage": "https://nyamsprod.com" - } - ], - "description": "userland URI parser RFC 3986 compliant", - "homepage": "https://github.com/thephpleague/uri-parser", - "keywords": [ - "parse_url", - "parser", - "rfc3986", - "rfc3987", - "uri", - "url" - ], - "time": "2018-11-22T07:55:51+00:00" - }, - { - "name": "phpinnacle/buffer", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/phpinnacle/buffer.git", - "reference": "7810ab4a371a8085d6b06572e467fc55c08e155f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpinnacle/buffer/zipball/7810ab4a371a8085d6b06572e467fc55c08e155f", - "reference": "7810ab4a371a8085d6b06572e467fc55c08e155f", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "phpunit/phpunit": "^8.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "PHPinnacle\\Buffer\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHPinnacle", - "email": "dev@phpinnacle.com", - "homepage": "https://phpinnacle.com", - "role": "Developer" - } - ], - "description": "PHPinnacle binary buffer implementation", - "homepage": "https://github.com/phpinnacle/buffer", - "keywords": [ - "Buffer", - "binary", - "binary data", - "pack", - "phpinnacle", - "unpack" - ], - "time": "2019-03-14T14:26:32+00:00" - } - ], - "packages-dev": [ - { - "name": "beberlei/assert", - "version": "v3.2.7", - "source": { - "type": "git", - "url": "https://github.com/beberlei/assert.git", - "reference": "d63a6943fc4fd1a2aedb65994e3548715105abcf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/beberlei/assert/zipball/d63a6943fc4fd1a2aedb65994e3548715105abcf", - "reference": "d63a6943fc4fd1a2aedb65994e3548715105abcf", - "shasum": "" - }, - "require": { - "ext-ctype": "*", - "ext-json": "*", - "ext-mbstring": "*", - "ext-simplexml": "*", - "php": "^7" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "*", - "phpstan/phpstan-shim": "*", - "phpunit/phpunit": ">=6.0.0 <8" - }, - "suggest": { - "ext-intl": "Needed to allow Assertion::count(), Assertion::isCountable(), Assertion::minCount(), and Assertion::maxCount() to operate on ResourceBundles" - }, - "type": "library", - "autoload": { - "psr-4": { - "Assert\\": "lib/Assert" - }, - "files": [ - "lib/Assert/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "authors": [ - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de", - "role": "Lead Developer" - }, - { - "name": "Richard Quadling", - "email": "rquadling@gmail.com", - "role": "Collaborator" - } - ], - "description": "Thin assertion library for input validation in business models.", - "keywords": [ - "assert", - "assertion", - "validation" - ], - "time": "2019-12-19T17:51:41+00:00" - }, - { - "name": "doctrine/annotations", - "version": "1.10.4", - "source": { - "type": "git", - "url": "https://github.com/doctrine/annotations.git", - "reference": "bfe91e31984e2ba76df1c1339681770401ec262f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/bfe91e31984e2ba76df1c1339681770401ec262f", - "reference": "bfe91e31984e2ba76df1c1339681770401ec262f", - "shasum": "" - }, - "require": { - "doctrine/lexer": "1.*", - "ext-tokenizer": "*", - "php": "^7.1 || ^8.0" - }, - "require-dev": { - "doctrine/cache": "1.*", - "phpstan/phpstan": "^0.12.20", - "phpunit/phpunit": "^7.5 || ^9.1.5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.9.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Docblock Annotations Parser", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "annotations", - "docblock", - "parser" - ], - "time": "2020-08-10T19:35:50+00:00" - }, - { - "name": "doctrine/instantiator", - "version": "1.3.1", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "f350df0268e904597e3bd9c4685c53e0e333feea" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f350df0268e904597e3bd9c4685c53e0e333feea", - "reference": "f350df0268e904597e3bd9c4685c53e0e333feea", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0" - }, - "require-dev": { - "doctrine/coding-standard": "^6.0", - "ext-pdo": "*", - "ext-phar": "*", - "phpbench/phpbench": "^0.13", - "phpstan/phpstan-phpunit": "^0.11", - "phpstan/phpstan-shim": "^0.11", - "phpunit/phpunit": "^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://www.doctrine-project.org/projects/instantiator.html", - "keywords": [ - "constructor", - "instantiate" - ], - "time": "2020-05-29T17:27:14+00:00" - }, - { - "name": "doctrine/lexer", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/doctrine/lexer.git", - "reference": "e864bbf5904cb8f5bb334f99209b48018522f042" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/e864bbf5904cb8f5bb334f99209b48018522f042", - "reference": "e864bbf5904cb8f5bb334f99209b48018522f042", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "require-dev": { - "doctrine/coding-standard": "^6.0", - "phpstan/phpstan": "^0.11.8", - "phpunit/phpunit": "^8.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.", - "homepage": "https://www.doctrine-project.org/projects/lexer.html", - "keywords": [ - "annotations", - "docblock", - "lexer", - "parser", - "php" - ], - "time": "2020-05-25T17:44:05+00:00" - }, - { - "name": "lstrojny/functional-php", - "version": "1.12.0", - "source": { - "type": "git", - "url": "https://github.com/lstrojny/functional-php.git", - "reference": "11610f50323519dd38bd7b527d6730e524e5eb58" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/lstrojny/functional-php/zipball/11610f50323519dd38bd7b527d6730e524e5eb58", - "reference": "11610f50323519dd38bd7b527d6730e524e5eb58", - "shasum": "" - }, - "require": { - "php": "~7" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.14", - "phpunit/phpunit": "~7", - "squizlabs/php_codesniffer": "~3.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Functional\\": "src/Functional" - }, - "files": [ - "src/Functional/Ary.php", - "src/Functional/Average.php", - "src/Functional/ButLast.php", - "src/Functional/Capture.php", - "src/Functional/ConstFunction.php", - "src/Functional/CompareOn.php", - "src/Functional/CompareObjectHashOn.php", - "src/Functional/Compose.php", - "src/Functional/Concat.php", - "src/Functional/Contains.php", - "src/Functional/Converge.php", - "src/Functional/Curry.php", - "src/Functional/CurryN.php", - "src/Functional/Difference.php", - "src/Functional/DropFirst.php", - "src/Functional/DropLast.php", - "src/Functional/Each.php", - "src/Functional/Equal.php", - "src/Functional/ErrorToException.php", - "src/Functional/Every.php", - "src/Functional/False.php", - "src/Functional/Falsy.php", - "src/Functional/Filter.php", - "src/Functional/First.php", - "src/Functional/FirstIndexOf.php", - "src/Functional/FlatMap.php", - "src/Functional/Flatten.php", - "src/Functional/Flip.php", - "src/Functional/GreaterThan.php", - "src/Functional/GreaterThanOrEqual.php", - "src/Functional/Group.php", - "src/Functional/Head.php", - "src/Functional/Id.php", - "src/Functional/IfElse.php", - "src/Functional/Identical.php", - "src/Functional/IndexesOf.php", - "src/Functional/Intersperse.php", - "src/Functional/Invoke.php", - "src/Functional/InvokeFirst.php", - "src/Functional/InvokeIf.php", - "src/Functional/InvokeLast.php", - "src/Functional/Invoker.php", - "src/Functional/Last.php", - "src/Functional/LastIndexOf.php", - "src/Functional/LessThan.php", - "src/Functional/LessThanOrEqual.php", - "src/Functional/LexicographicCompare.php", - "src/Functional/Map.php", - "src/Functional/Match.php", - "src/Functional/Maximum.php", - "src/Functional/Memoize.php", - "src/Functional/Minimum.php", - "src/Functional/None.php", - "src/Functional/Noop.php", - "src/Functional/Not.php", - "src/Functional/OmitKeys.php", - "src/Functional/PartialAny.php", - "src/Functional/PartialLeft.php", - "src/Functional/PartialMethod.php", - "src/Functional/PartialRight.php", - "src/Functional/Partition.php", - "src/Functional/Pick.php", - "src/Functional/Pluck.php", - "src/Functional/Poll.php", - "src/Functional/Product.php", - "src/Functional/Ratio.php", - "src/Functional/ReduceLeft.php", - "src/Functional/ReduceRight.php", - "src/Functional/Reindex.php", - "src/Functional/Reject.php", - "src/Functional/Repeat.php", - "src/Functional/Retry.php", - "src/Functional/Select.php", - "src/Functional/SelectKeys.php", - "src/Functional/SequenceConstant.php", - "src/Functional/SequenceExponential.php", - "src/Functional/SequenceLinear.php", - "src/Functional/Some.php", - "src/Functional/Sort.php", - "src/Functional/Sum.php", - "src/Functional/SuppressError.php", - "src/Functional/Tap.php", - "src/Functional/Tail.php", - "src/Functional/TailRecursion.php", - "src/Functional/TakeLeft.php", - "src/Functional/TakeRight.php", - "src/Functional/True.php", - "src/Functional/Truthy.php", - "src/Functional/Unique.php", - "src/Functional/With.php", - "src/Functional/Zip.php", - "src/Functional/ZipAll.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Lars Strojny", - "email": "lstrojny@php.net", - "homepage": "http://usrportage.de" - }, - { - "name": "Max Beutel", - "email": "nash12@gmail.com" - } - ], - "description": "Functional primitives for PHP", - "keywords": [ - "functional" - ], - "time": "2020-06-16T09:17:22+00:00" - }, - { - "name": "myclabs/deep-copy", - "version": "1.10.1", - "source": { - "type": "git", - "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", - "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0" - }, - "replace": { - "myclabs/deep-copy": "self.version" - }, - "require-dev": { - "doctrine/collections": "^1.0", - "doctrine/common": "^2.6", - "phpunit/phpunit": "^7.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "DeepCopy\\": "src/DeepCopy/" - }, - "files": [ - "src/DeepCopy/deep_copy.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Create deep copies (clones) of your objects", - "keywords": [ - "clone", - "copy", - "duplicate", - "object", - "object graph" - ], - "time": "2020-06-29T13:22:24+00:00" - }, - { - "name": "phar-io/manifest", - "version": "1.0.3", - "source": { - "type": "git", - "url": "https://github.com/phar-io/manifest.git", - "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", - "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-phar": "*", - "phar-io/version": "^2.0", - "php": "^5.6 || ^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - }, - { - "name": "Sebastian Heuer", - "email": "sebastian@phpeople.de", - "role": "Developer" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "Developer" - } - ], - "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2018-07-08T19:23:20+00:00" - }, - { - "name": "phar-io/version", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/phar-io/version.git", - "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", - "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - }, - { - "name": "Sebastian Heuer", - "email": "sebastian@phpeople.de", - "role": "Developer" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "Developer" - } - ], - "description": "Library for handling version information and constraints", - "time": "2018-07-08T19:19:57+00:00" - }, - { - "name": "phpbench/container", - "version": "1.2", - "source": { - "type": "git", - "url": "https://github.com/phpbench/container.git", - "reference": "c0e3cbf1cd8f867c70b029cb6d1b0b39fe6d409d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpbench/container/zipball/c0e3cbf1cd8f867c70b029cb6d1b0b39fe6d409d", - "reference": "c0e3cbf1cd8f867c70b029cb6d1b0b39fe6d409d", - "shasum": "" - }, - "require": { - "psr/container": "^1.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.36" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "PhpBench\\DependencyInjection\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Daniel Leech", - "email": "daniel@dantleech.com" - } - ], - "description": "Simple, configurable, service container.", - "time": "2018-02-12T08:08:59+00:00" - }, - { - "name": "phpbench/dom", - "version": "0.2.0", - "source": { - "type": "git", - "url": "https://github.com/phpbench/dom.git", - "reference": "b135378dd0004c05ba5446aeddaf0b83339c1c4c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpbench/dom/zipball/b135378dd0004c05ba5446aeddaf0b83339c1c4c", - "reference": "b135378dd0004c05ba5446aeddaf0b83339c1c4c", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "php": "^5.4|^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "PhpBench\\Dom\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Daniel Leech", - "email": "daniel@dantleech.com" - } - ], - "description": "DOM wrapper to simplify working with the PHP DOM implementation", - "time": "2016-02-27T12:15:56+00:00" - }, - { - "name": "phpbench/phpbench", - "version": "0.16.10", - "source": { - "type": "git", - "url": "https://github.com/phpbench/phpbench.git", - "reference": "00c18b1ab87dbda66e8972c8602a14dd08c69914" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpbench/phpbench/zipball/00c18b1ab87dbda66e8972c8602a14dd08c69914", - "reference": "00c18b1ab87dbda66e8972c8602a14dd08c69914", - "shasum": "" - }, - "require": { - "beberlei/assert": "^2.4 || ^3.0", - "doctrine/annotations": "^1.2.7", - "ext-dom": "*", - "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "lstrojny/functional-php": "1.0 || ^1.2.3", - "php": "^7.1", - "phpbench/container": "~1.2", - "phpbench/dom": "~0.2.0", - "seld/jsonlint": "^1.1", - "symfony/console": "^3.2 || ^4.0", - "symfony/debug": "^2.4 || ^3.0 || ^4.0", - "symfony/filesystem": "^2.4 || ^3.0 || ^4.0", - "symfony/finder": "^2.4 || ^3.0 || ^4.0", - "symfony/options-resolver": "^2.6 || ^3.0 || ^4.0", - "symfony/process": "^2.1 || ^3.0 || ^4.0", - "webmozart/path-util": "^2.3" - }, - "require-dev": { - "doctrine/dbal": "^2.4", - "friendsofphp/php-cs-fixer": "^2.13.1", - "padraic/phar-updater": "^1.0", - "phpstan/phpstan": "^0.10.7", - "phpunit/phpunit": "^6.5 || ^7.0" - }, - "suggest": { - "ext-curl": "For (web) reports extension", - "ext-xdebug": "For Xdebug profiling extension." - }, - "bin": [ - "bin/phpbench" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "PhpBench\\": "lib/", - "PhpBench\\Extensions\\Dbal\\": "extensions/dbal/lib/", - "PhpBench\\Extensions\\XDebug\\": "extensions/xdebug/lib/", - "PhpBench\\Extensions\\Reports\\": "extensions/reports/lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Daniel Leech", - "email": "daniel@dantleech.com" - } - ], - "description": "PHP Benchmarking Framework", - "time": "2019-09-01T08:08:02+00:00" - }, - { - "name": "phpdocumentor/reflection-common", - "version": "2.2.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b", - "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-2.x": "2.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jaap van Otterdijk", - "email": "opensource@ijaap.nl" - } - ], - "description": "Common reflection classes used by phpdocumentor to reflect the code structure", - "homepage": "http://www.phpdoc.org", - "keywords": [ - "FQSEN", - "phpDocumentor", - "phpdoc", - "reflection", - "static analysis" - ], - "time": "2020-06-27T09:03:43+00:00" - }, - { - "name": "phpdocumentor/reflection-docblock", - "version": "5.2.1", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d870572532cd70bc3fab58f2e23ad423c8404c44", - "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44", - "shasum": "" - }, - "require": { - "ext-filter": "*", - "php": "^7.2 || ^8.0", - "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.3", - "webmozart/assert": "^1.9.1" - }, - "require-dev": { - "mockery/mockery": "~1.3.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - }, - { - "name": "Jaap van Otterdijk", - "email": "account@ijaap.nl" - } - ], - "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2020-08-15T11:14:08+00:00" - }, - { - "name": "phpdocumentor/type-resolver", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "e878a14a65245fbe78f8080eba03b47c3b705651" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e878a14a65245fbe78f8080eba03b47c3b705651", - "reference": "e878a14a65245fbe78f8080eba03b47c3b705651", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0", - "phpdocumentor/reflection-common": "^2.0" - }, - "require-dev": { - "ext-tokenizer": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - } - ], - "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2020-06-27T10:12:23+00:00" - }, - { - "name": "phpspec/prophecy", - "version": "1.11.1", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/b20034be5efcdab4fb60ca3a29cba2949aead160", - "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.2", - "php": "^7.2", - "phpdocumentor/reflection-docblock": "^5.0", - "sebastian/comparator": "^3.0 || ^4.0", - "sebastian/recursion-context": "^3.0 || ^4.0" - }, - "require-dev": { - "phpspec/phpspec": "^6.0", - "phpunit/phpunit": "^8.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.11.x-dev" - } - }, - "autoload": { - "psr-4": { - "Prophecy\\": "src/Prophecy" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "time": "2020-07-08T12:44:21+00:00" - }, - { - "name": "phpunit/php-code-coverage", - "version": "7.0.10", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f1884187926fbb755a9aaf0b3836ad3165b478bf", - "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-xmlwriter": "*", - "php": "^7.2", - "phpunit/php-file-iterator": "^2.0.2", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.1.1", - "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^4.2.2", - "sebastian/version": "^2.0.1", - "theseer/tokenizer": "^1.1.3" - }, - "require-dev": { - "phpunit/phpunit": "^8.2.2" - }, - "suggest": { - "ext-xdebug": "^2.7.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "7.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "time": "2019-11-20T13:55:58+00:00" - }, - { - "name": "phpunit/php-file-iterator", - "version": "2.0.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "050bedf145a257b1ff02746c31894800e5122946" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", - "reference": "050bedf145a257b1ff02746c31894800e5122946", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "time": "2018-09-13T20:33:42+00:00" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2015-06-21T13:50:34+00:00" - }, - { - "name": "phpunit/php-timer", - "version": "2.1.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2019-06-07T04:22:29+00:00" - }, - { - "name": "phpunit/php-token-stream", - "version": "3.1.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff", - "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": "^7.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "abandoned": true, - "time": "2019-09-17T06:23:10+00:00" - }, - { - "name": "phpunit/phpunit", - "version": "8.5.8", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "34c18baa6a44f1d1fbf0338907139e9dce95b997" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/34c18baa6a44f1d1fbf0338907139e9dce95b997", - "reference": "34c18baa6a44f1d1fbf0338907139e9dce95b997", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.2.0", - "ext-dom": "*", - "ext-json": "*", - "ext-libxml": "*", - "ext-mbstring": "*", - "ext-xml": "*", - "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.9.1", - "phar-io/manifest": "^1.0.3", - "phar-io/version": "^2.0.1", - "php": "^7.2", - "phpspec/prophecy": "^1.8.1", - "phpunit/php-code-coverage": "^7.0.7", - "phpunit/php-file-iterator": "^2.0.2", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^2.1.2", - "sebastian/comparator": "^3.0.2", - "sebastian/diff": "^3.0.2", - "sebastian/environment": "^4.2.2", - "sebastian/exporter": "^3.1.1", - "sebastian/global-state": "^3.0.0", - "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^2.0.1", - "sebastian/type": "^1.1.3", - "sebastian/version": "^2.0.1" - }, - "require-dev": { - "ext-pdo": "*" - }, - "suggest": { - "ext-soap": "*", - "ext-xdebug": "*", - "phpunit/php-invoker": "^2.0.0" - }, - "bin": [ - "phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "8.5-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "time": "2020-06-22T07:06:58+00:00" - }, - { - "name": "psr/container", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Container\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "time": "2017-02-14T16:28:37+00:00" - }, - { - "name": "psr/log", - "version": "1.1.3", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2020-03-23T09:12:05+00:00" - }, - { - "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Looks up which function or method a line of code belongs to", - "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" - }, - { - "name": "sebastian/comparator", - "version": "3.0.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", - "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", - "shasum": "" - }, - "require": { - "php": "^7.1", - "sebastian/diff": "^3.0", - "sebastian/exporter": "^3.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides the functionality to compare PHP values for equality", - "homepage": "https://github.com/sebastianbergmann/comparator", - "keywords": [ - "comparator", - "compare", - "equality" - ], - "time": "2018-07-12T15:12:46+00:00" - }, - { - "name": "sebastian/diff", - "version": "3.0.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", - "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.0", - "symfony/process": "^2 || ^3.3 || ^4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Diff implementation", - "homepage": "https://github.com/sebastianbergmann/diff", - "keywords": [ - "diff", - "udiff", - "unidiff", - "unified diff" - ], - "time": "2019-02-04T06:01:07+00:00" - }, - { - "name": "sebastian/environment", - "version": "4.2.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/464c90d7bdf5ad4e8a6aea15c091fec0603d4368", - "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.5" - }, - "suggest": { - "ext-posix": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "http://www.github.com/sebastianbergmann/environment", - "keywords": [ - "Xdebug", - "environment", - "hhvm" - ], - "time": "2019-11-20T08:46:58+00:00" - }, - { - "name": "sebastian/exporter", - "version": "3.1.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", - "shasum": "" - }, - "require": { - "php": "^7.0", - "sebastian/recursion-context": "^3.0" - }, - "require-dev": { - "ext-mbstring": "*", - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.1.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", - "keywords": [ - "export", - "exporter" - ], - "time": "2019-09-14T09:02:43+00:00" - }, - { - "name": "sebastian/global-state", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", - "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", - "shasum": "" - }, - "require": { - "php": "^7.2", - "sebastian/object-reflector": "^1.1.1", - "sebastian/recursion-context": "^3.0" - }, - "require-dev": { - "ext-dom": "*", - "phpunit/phpunit": "^8.0" - }, - "suggest": { - "ext-uopz": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", - "keywords": [ - "global state" - ], - "time": "2019-02-01T05:30:01+00:00" - }, - { - "name": "sebastian/object-enumerator", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", - "shasum": "" - }, - "require": { - "php": "^7.0", - "sebastian/object-reflector": "^1.1.1", - "sebastian/recursion-context": "^3.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Traverses array structures and object graphs to enumerate all referenced objects", - "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-08-03T12:35:26+00:00" - }, - { - "name": "sebastian/object-reflector", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "773f97c67f28de00d397be301821b06708fca0be" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", - "reference": "773f97c67f28de00d397be301821b06708fca0be", - "shasum": "" - }, - "require": { - "php": "^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Allows reflection of object attributes, including inherited and non-public ones", - "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "time": "2017-03-29T09:07:27+00:00" - }, - { - "name": "sebastian/recursion-context", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", - "shasum": "" - }, - "require": { - "php": "^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2017-03-03T06:23:57+00:00" - }, - { - "name": "sebastian/resource-operations", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", - "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides a list of PHP built-in functions that operate on resources", - "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2018-10-04T04:07:39+00:00" - }, - { - "name": "sebastian/type", - "version": "1.1.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/type.git", - "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/3aaaa15fa71d27650d62a948be022fe3b48541a3", - "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3", - "shasum": "" - }, - "require": { - "php": "^7.2" - }, - "require-dev": { - "phpunit/phpunit": "^8.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Collection of value objects that represent the types of the PHP type system", - "homepage": "https://github.com/sebastianbergmann/type", - "time": "2019-07-02T08:10:15+00:00" - }, - { - "name": "sebastian/version", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03T07:35:21+00:00" - }, - { - "name": "seld/jsonlint", - "version": "1.8.1", - "source": { - "type": "git", - "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "3d5eb71705adfa34bd34b993400622932b2f62fd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/3d5eb71705adfa34bd34b993400622932b2f62fd", - "reference": "3d5eb71705adfa34bd34b993400622932b2f62fd", - "shasum": "" - }, - "require": { - "php": "^5.3 || ^7.0 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" - }, - "bin": [ - "bin/jsonlint" - ], - "type": "library", - "autoload": { - "psr-4": { - "Seld\\JsonLint\\": "src/Seld/JsonLint/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "JSON Linter", - "keywords": [ - "json", - "linter", - "parser", - "validator" - ], - "time": "2020-08-13T09:07:59+00:00" - }, - { - "name": "symfony/console", - "version": "v4.4.11", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "55d07021da933dd0d633ffdab6f45d5b230c7e02" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/55d07021da933dd0d633ffdab6f45d5b230c7e02", - "reference": "55d07021da933dd0d633ffdab6f45d5b230c7e02", - "shasum": "" - }, - "require": { - "php": ">=7.1.3", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.8", - "symfony/polyfill-php80": "^1.15", - "symfony/service-contracts": "^1.1|^2" - }, - "conflict": { - "symfony/dependency-injection": "<3.4", - "symfony/event-dispatcher": "<4.3|>=5", - "symfony/lock": "<4.4", - "symfony/process": "<3.3" - }, - "provide": { - "psr/log-implementation": "1.0" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "^3.4|^4.0|^5.0", - "symfony/dependency-injection": "^3.4|^4.0|^5.0", - "symfony/event-dispatcher": "^4.3", - "symfony/lock": "^4.4|^5.0", - "symfony/process": "^3.4|^4.0|^5.0", - "symfony/var-dumper": "^4.3|^5.0" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/lock": "", - "symfony/process": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Console\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Console Component", - "homepage": "https://symfony.com", - "time": "2020-07-06T13:18:39+00:00" - }, - { - "name": "symfony/debug", - "version": "v4.4.11", - "source": { - "type": "git", - "url": "https://github.com/symfony/debug.git", - "reference": "47aa9064d75db36389692dd4d39895a0820f00f2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/47aa9064d75db36389692dd4d39895a0820f00f2", - "reference": "47aa9064d75db36389692dd4d39895a0820f00f2", - "shasum": "" - }, - "require": { - "php": ">=7.1.3", - "psr/log": "~1.0", - "symfony/polyfill-php80": "^1.15" - }, - "conflict": { - "symfony/http-kernel": "<3.4" - }, - "require-dev": { - "symfony/http-kernel": "^3.4|^4.0|^5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Debug\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Debug Component", - "homepage": "https://symfony.com", - "time": "2020-07-23T08:31:43+00:00" - }, - { - "name": "symfony/filesystem", - "version": "v4.4.11", - "source": { - "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "b27f491309db5757816db672b256ea2e03677d30" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/b27f491309db5757816db672b256ea2e03677d30", - "reference": "b27f491309db5757816db672b256ea2e03677d30", - "shasum": "" - }, - "require": { - "php": ">=7.1.3", - "symfony/polyfill-ctype": "~1.8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Filesystem\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Filesystem Component", - "homepage": "https://symfony.com", - "time": "2020-05-30T18:50:54+00:00" - }, - { - "name": "symfony/finder", - "version": "v4.4.11", - "source": { - "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "2727aa35fddfada1dd37599948528e9b152eb742" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/2727aa35fddfada1dd37599948528e9b152eb742", - "reference": "2727aa35fddfada1dd37599948528e9b152eb742", - "shasum": "" - }, - "require": { - "php": ">=7.1.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Finder\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Finder Component", - "homepage": "https://symfony.com", - "time": "2020-07-05T09:39:30+00:00" - }, - { - "name": "symfony/options-resolver", - "version": "v4.4.11", - "source": { - "type": "git", - "url": "https://github.com/symfony/options-resolver.git", - "reference": "376bd3a02e7946dbf90b01563361b47dde425025" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/376bd3a02e7946dbf90b01563361b47dde425025", - "reference": "376bd3a02e7946dbf90b01563361b47dde425025", - "shasum": "" - }, - "require": { - "php": ">=7.1.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\OptionsResolver\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony OptionsResolver Component", - "homepage": "https://symfony.com", - "keywords": [ - "config", - "configuration", - "options" - ], - "time": "2020-07-10T09:12:14+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.18.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "1c302646f6efc070cd46856e600e5e0684d6b454" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454", - "reference": "1c302646f6efc070cd46856e600e5e0684d6b454", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.18-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "time": "2020-07-14T12:35:20+00:00" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.18.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/a6977d63bf9a0ad4c65cd352709e230876f9904a", - "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.18-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "time": "2020-07-14T12:35:20+00:00" - }, - { - "name": "symfony/polyfill-php73", - "version": "v1.18.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "fffa1a52a023e782cdcc221d781fe1ec8f87fcca" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fffa1a52a023e782cdcc221d781fe1ec8f87fcca", - "reference": "fffa1a52a023e782cdcc221d781fe1ec8f87fcca", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.18-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php73\\": "" - }, - "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "time": "2020-07-14T12:35:20+00:00" - }, - { - "name": "symfony/polyfill-php80", - "version": "v1.18.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "d87d5766cbf48d72388a9f6b85f280c8ad51f981" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/d87d5766cbf48d72388a9f6b85f280c8ad51f981", - "reference": "d87d5766cbf48d72388a9f6b85f280c8ad51f981", - "shasum": "" - }, - "require": { - "php": ">=7.0.8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.18-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "time": "2020-07-14T12:35:20+00:00" - }, - { - "name": "symfony/process", - "version": "v4.4.11", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "65e70bab62f3da7089a8d4591fb23fbacacb3479" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/65e70bab62f3da7089a8d4591fb23fbacacb3479", - "reference": "65e70bab62f3da7089a8d4591fb23fbacacb3479", - "shasum": "" - }, - "require": { - "php": ">=7.1.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Process Component", - "homepage": "https://symfony.com", - "time": "2020-07-23T08:31:43+00:00" - }, - { - "name": "symfony/service-contracts", - "version": "v2.1.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/service-contracts.git", - "reference": "58c7475e5457c5492c26cc740cc0ad7464be9442" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/58c7475e5457c5492c26cc740cc0ad7464be9442", - "reference": "58c7475e5457c5492c26cc740cc0ad7464be9442", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "psr/container": "^1.0" - }, - "suggest": { - "symfony/service-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\Service\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to writing services", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "time": "2020-07-06T13:23:11+00:00" - }, - { - "name": "theseer/tokenizer", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/theseer/tokenizer.git", - "reference": "75a63c33a8577608444246075ea0af0d052e452a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", - "reference": "75a63c33a8577608444246075ea0af0d052e452a", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": "^7.2 || ^8.0" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - } - ], - "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2020-07-12T23:59:07+00:00" - }, - { - "name": "webmozart/assert", - "version": "1.9.1", - "source": { - "type": "git", - "url": "https://github.com/webmozart/assert.git", - "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", - "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0 || ^8.0", - "symfony/polyfill-ctype": "^1.8" - }, - "conflict": { - "phpstan/phpstan": "<0.12.20", - "vimeo/psalm": "<3.9.1" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^7.5.13" - }, - "type": "library", - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "time": "2020-07-08T17:02:28+00:00" - }, - { - "name": "webmozart/path-util", - "version": "2.3.0", - "source": { - "type": "git", - "url": "https://github.com/webmozart/path-util.git", - "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/path-util/zipball/d939f7edc24c9a1bb9c0dee5cb05d8e859490725", - "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "webmozart/assert": "~1.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\PathUtil\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "A robust cross-platform utility for normalizing, comparing and modifying file paths.", - "time": "2015-12-17T08:42:14+00:00" - } - ], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": { - "php": "^7.2" - }, - "platform-dev": [] -} From 1590abf0ffff8b5861f97835e4d403ed90bce107 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:20:14 +0100 Subject: [PATCH 03/58] migrate to php 8 --- CHANGELOG.md => .github/CHANGELOG.md | 0 CONDUCT.md => .github/CONDUCT.md | 0 CONTRIBUTING.md => .github/CONTRIBUTING.md | 0 .../ISSUE_TEMPLATE.md | 0 .../PULL_REQUEST_TEMPLATE.md | 0 .github/workflows/continuous-integration.yml | 105 ++ .scrutinizer.yml | 61 +- .travis.yml | 29 - README.md | 14 +- benchmarks/AbstractBench.php | 80 - benchmarks/ConsumeBench.php | 52 - benchmarks/ProduceBench.php | 32 - composer.json | 102 +- docker-compose.yml | 16 + phpbench.json | 3 - phpstan.neon | 13 + phpunit.xml | 42 +- psalm.xml | 25 + src/Buffer.php | 238 ++- src/Channel.php | 1329 +++++++++-------- src/Client.php | 490 +++--- src/Config.php | 278 ++-- src/Connection.php | 200 +-- src/Constants.php | 258 ++-- src/Consumer.php | 48 +- src/Events.php | 54 +- src/Exception/ChannelException.php | 51 +- src/Exception/ClassInvalid.php | 7 +- src/Exception/ClientException.php | 56 +- src/Exception/ConfigurationException.php | 29 + src/Exception/ConnectionException.php | 33 + src/Exception/MethodInvalid.php | 8 +- src/Exception/ProtocolException.php | 56 +- src/Exception/RidgeException.php | 2 +- src/Message.php | 52 +- src/MessageReceiver.php | 96 +- src/Parser.php | 352 ++--- src/Properties.php | 45 +- src/Protocol/AbstractFrame.php | 16 +- src/Protocol/AcknowledgmentFrame.php | 2 +- src/Protocol/BasicAckFrame.php | 9 +- src/Protocol/BasicCancelFrame.php | 11 +- src/Protocol/BasicCancelOkFrame.php | 11 +- src/Protocol/BasicConsumeFrame.php | 9 +- src/Protocol/BasicConsumeOkFrame.php | 17 +- src/Protocol/BasicDeliverFrame.php | 27 +- src/Protocol/BasicGetEmptyFrame.php | 11 +- src/Protocol/BasicGetFrame.php | 11 +- src/Protocol/BasicGetOkFrame.php | 11 +- src/Protocol/BasicNackFrame.php | 17 +- src/Protocol/BasicPublishFrame.php | 9 +- src/Protocol/BasicQosFrame.php | 11 +- src/Protocol/BasicRecoverAsyncFrame.php | 17 +- src/Protocol/BasicRecoverFrame.php | 11 +- src/Protocol/BasicRejectFrame.php | 7 +- src/Protocol/BasicReturnFrame.php | 9 +- src/Protocol/ChannelCloseFrame.php | 11 +- src/Protocol/ChannelFlowFrame.php | 9 +- src/Protocol/ChannelFlowOkFrame.php | 11 +- src/Protocol/ChannelOpenFrame.php | 11 +- src/Protocol/ChannelOpenOkFrame.php | 11 +- src/Protocol/ConfirmSelectFrame.php | 11 +- src/Protocol/ConnectionBlockedFrame.php | 11 +- src/Protocol/ConnectionCloseFrame.php | 9 +- src/Protocol/ConnectionOpenFrame.php | 9 +- src/Protocol/ConnectionOpenOkFrame.php | 11 +- src/Protocol/ConnectionSecureFrame.php | 9 +- src/Protocol/ConnectionSecureOkFrame.php | 11 +- src/Protocol/ConnectionStartFrame.php | 42 +- src/Protocol/ConnectionStartOkFrame.php | 9 +- src/Protocol/ConnectionTuneFrame.php | 11 +- src/Protocol/ConnectionTuneOkFrame.php | 11 +- src/Protocol/ContentBodyFrame.php | 2 +- src/Protocol/ContentHeaderFrame.php | 282 ++-- src/Protocol/ExchangeBindFrame.php | 9 +- src/Protocol/ExchangeDeclareFrame.php | 9 +- src/Protocol/ExchangeDeleteFrame.php | 11 +- src/Protocol/ExchangeUnbindFrame.php | 11 +- src/Protocol/MethodFrame.php | 18 +- src/Protocol/QueueBindFrame.php | 12 +- src/Protocol/QueueDeclareFrame.php | 11 +- src/Protocol/QueueDeclareOkFrame.php | 9 +- src/Protocol/QueueDeleteFrame.php | 11 +- src/Protocol/QueueDeleteOkFrame.php | 11 +- src/Protocol/QueuePurgeFrame.php | 11 +- src/Protocol/QueuePurgeOkFrame.php | 11 +- src/Protocol/QueueUnbindFrame.php | 7 +- src/Queue.php | 16 +- tests/AsyncTest.php | 1 + tests/BufferTest.php | 23 +- tests/ChannelTest.php | 162 +- tests/ClientConnectTest.php | 8 +- tests/ClientTest.php | 6 +- tests/ConfigTest.php | 40 +- tests/RidgeTest.php | 3 +- 95 files changed, 2405 insertions(+), 2948 deletions(-) rename CHANGELOG.md => .github/CHANGELOG.md (100%) rename CONDUCT.md => .github/CONDUCT.md (100%) rename CONTRIBUTING.md => .github/CONTRIBUTING.md (100%) rename ISSUE_TEMPLATE.md => .github/ISSUE_TEMPLATE.md (100%) rename PULL_REQUEST_TEMPLATE.md => .github/PULL_REQUEST_TEMPLATE.md (100%) create mode 100644 .github/workflows/continuous-integration.yml delete mode 100644 .travis.yml delete mode 100644 benchmarks/AbstractBench.php delete mode 100644 benchmarks/ConsumeBench.php delete mode 100644 benchmarks/ProduceBench.php create mode 100644 docker-compose.yml delete mode 100644 phpbench.json create mode 100644 phpstan.neon create mode 100644 psalm.xml create mode 100644 src/Exception/ConfigurationException.php create mode 100644 src/Exception/ConnectionException.php diff --git a/CHANGELOG.md b/.github/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to .github/CHANGELOG.md diff --git a/CONDUCT.md b/.github/CONDUCT.md similarity index 100% rename from CONDUCT.md rename to .github/CONDUCT.md diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to .github/CONTRIBUTING.md diff --git a/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md similarity index 100% rename from ISSUE_TEMPLATE.md rename to .github/ISSUE_TEMPLATE.md diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from PULL_REQUEST_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..8ded6a3 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,105 @@ +name: "Continuous Integration" + +on: [ push, pull_request ] + +jobs: + psalm: + name: Psalm + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + coverage: none + tools: composer:v2 + + - name: Install dependencies with composer + run: composer install -ov + + - name: Run vimeo/psalm + run: ./vendor/bin/psalm --config=psalm.xml --shepherd + + phpstan: + name: PHPStan + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + coverage: none + tools: composer:v2 + + - name: Install dependencies with composer + run: composer install -ov + + - name: Run phpstan/phpstan + run: ./vendor/bin/phpstan analyse src --level 7 + + phpunit: + name: PHPUnit + + runs-on: ubuntu-latest + + env: + PHP_EXTENSIONS: dom, json, mbstring, curl, tokenizer + PHP_INI_VALUES: assert.exception=1, zend.assertions=1 + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Override PHP ini values for JIT compiler + run: echo "PHP_INI_VALUES::assert.exception=1, zend.assertions=1, opcache.enable=1, opcache.enable_cli=1, opcache.optimization_level=-1, opcache.jit=1255, opcache.jit_buffer_size=32M" >> $GITHUB_ENV + + - name: Install PHP with extensions + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + extensions: ${{ env.PHP_EXTENSIONS }} + ini-values: ${{ env.PHP_INI_VALUES }} + tools: composer:v2 + + - name: Install dependencies + run: composer update --no-ansi --no-interaction --no-progress --prefer-lowest + + - name: Run tests with phpunit + run: XDEBUG_MODE=coverage php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover + + - name: Upload coverage file + uses: actions/upload-artifact@v2 + with: + name: phpunit.coverage + path: coverage.clover + + upload_coverage: + name: Upload coverage + runs-on: ubuntu-latest + needs: phpunit + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + coverage: none + tools: composer + + - name: Download coverage files + uses: actions/download-artifact@v2 + with: + path: reports + + - name: Send code coverage report to Scrutinizer + run: | + wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --format=php-clover ./reports/phpunit.coverage/coverage.clover \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml index adaad00..05385d2 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,64 +1,19 @@ +checks: + php: true + filter: - paths: [src/*] - excluded_paths: [tests/*] + paths: + - "src/*" + tools: - php_analyzer: true - php_sim: true - php_pdepend: true - sensiolabs_security_checker: true - php_changetracking: true - php_mess_detector: - enabled: true - config: - ruleset: ~ - code_size_rules: - cyclomatic_complexity: true - npath_complexity: true - excessive_method_length: true - excessive_class_length: true - excessive_parameter_list: true - excessive_public_count: true - too_many_fields: true - too_many_methods: true - excessive_class_complexity: true - design_rules: - exit_expression: true - eval_expression: true - goto_statement: true - number_of_class_children: true - depth_of_inheritance: true - coupling_between_objects: true - unused_code_rules: - unused_private_field: true - unused_local_variable: true - unused_private_method: true - unused_formal_parameter: true - naming_rules: - short_variable: - minimum: 3 - long_variable: - maximum: 20 - short_method: - minimum: 3 - constructor_conflict: true - constant_naming: true - boolean_method_name: true - controversial_rules: - superglobals: true - camel_case_class_name: true - camel_case_property_name: true - camel_case_method_name: true - camel_case_parameter_name: true - camel_case_variable_name: true external_code_coverage: timeout: 600 -checks: - php: - code_rating: true build: nodes: analysis: + environment: + php: 8.0.0 project_setup: override: true tests: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1f11046..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: php - -php: - - 7.2 - - 7.3 - -addons: - apt: - packages: - - rabbitmq-server - -cache: - directories: - - $HOME/.cache/composer - -before_script: - - mkdir -p build/logs - -install: - - travis_retry composer install --no-interaction --no-suggest - - travis_retry wget -c -nc --retry-connrefused --tries=0 https://scrutinizer-ci.com/ocular.phar - - chmod +x ocular.phar - -script: - - ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover - -after_script: - - if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then wget -c -nc --retry-connrefused --tries=0 https://scrutinizer-ci.com/ocular.phar; fi - - if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/README.md b/README.md index bb3b354..9db9a2e 100644 --- a/README.md +++ b/README.md @@ -58,24 +58,16 @@ More examples can be found in [`examples`](examples) directory. ## Testing ```bash -$ composer test -``` - -## Benchmarks - -We run benchmarks as follow: - -```bash -$ RIDGE_BENCHMARK_DSN=amqp://user:pass@localhost:5672 composer bench +$ composer tests ``` ## Change log -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. +Please see [CHANGELOG](.github/CHANGELOG.md) for more information on what has changed recently. ## Contributing -Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. ## Security diff --git a/benchmarks/AbstractBench.php b/benchmarks/AbstractBench.php deleted file mode 100644 index 6a39c0d..0000000 --- a/benchmarks/AbstractBench.php +++ /dev/null @@ -1,80 +0,0 @@ -client = Client::create($dsn); - - yield $this->client->connect(); - - $this->channel = yield $this->client->channel(); - - yield $this->channel->queueDeclare('bench_queue'); - yield $this->channel->exchangeDeclare('bench_exchange'); - yield $this->channel->queueBind('bench_queue', 'bench_exchange'); - })); - } - - /** - * @return void - * @throws \Throwable - */ - public function clear(): void - { - wait(call(function () { - yield $this->channel->queueDelete('bench_queue'); - yield $this->channel->exchangeDelete('bench_exchange'); - - yield $this->client->disconnect(); - })); - } -} diff --git a/benchmarks/ConsumeBench.php b/benchmarks/ConsumeBench.php deleted file mode 100644 index 1f7ec0b..0000000 --- a/benchmarks/ConsumeBench.php +++ /dev/null @@ -1,52 +0,0 @@ -channel->publish($this->body, 'bench_exchange'); - } - - $promises[] = $this->channel->publish('quit', 'bench_exchange'); - - yield $promises; - })); - } - - /** - * @Revs(1) - * @Iterations(10) - * - * @return void - * @throws \Throwable - */ - public function benchConsume(): void - { - wait(call(function () { - yield $this->channel->consume(function (Message $message) { - if ($message->content() === 'quit') { - yield $this->client->disconnect(); - } - }, 'bench_queue', '', false, true); - })); - } - - public function clear(): void - { - } -} diff --git a/benchmarks/ProduceBench.php b/benchmarks/ProduceBench.php deleted file mode 100644 index 1417d92..0000000 --- a/benchmarks/ProduceBench.php +++ /dev/null @@ -1,32 +0,0 @@ -channel->publish($this->body, 'bench_exchange'); - } - - yield $promises; - })); - } -} diff --git a/composer.json b/composer.json index 4593eca..5e9f8a3 100644 --- a/composer.json +++ b/composer.json @@ -1,51 +1,57 @@ { - "name": "phpinnacle/ridge", - "type": "library", - "description": "PHPinnacle async AMQP client", - "keywords": [ - "phpinnacle", "async", "amqp" - ], - "homepage": "https://github.com/phpinnacle/ridge", - "license": "MIT", - "authors": [ - { - "name": "PHPinnacle", - "email": "dev@phpinnacle.com", - "homepage": "https://phpinnacle.com", - "role": "Developer" - } - ], - "require": { - "php": "^7.2", - "amphp/amp": "v2.5.*", - "amphp/socket": "v1.1.*", - "phpinnacle/buffer": "v1.0.*" - }, - "require-dev": { - "phpbench/phpbench": "^0.16", - "phpunit/phpunit": "^8.0" - }, - "autoload": { - "psr-4": { - "PHPinnacle\\Ridge\\": "src" - } - }, - "autoload-dev": { - "psr-4": { - "PHPinnacle\\Ridge\\Tests\\": "tests", - "PHPinnacle\\Ridge\\Bench\\": "benchmarks" - } - }, - "scripts": { - "test": "phpunit", - "bench": "phpbench run benchmarks --report=aggregate" - }, - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "config": { - "sort-packages": true + "name": "phpinnacle/ridge", + "type": "library", + "description": "PHPinnacle async AMQP client", + "keywords": [ + "phpinnacle", + "async", + "amqp" + ], + "homepage": "https://github.com/phpinnacle/ridge", + "license": "MIT", + "authors": [ + { + "name": "PHPinnacle", + "email": "dev@phpinnacle.com", + "homepage": "https://phpinnacle.com", + "role": "Developer" } + ], + "require": { + "php": ">=8.0", + "amphp/amp": "v2.5.*", + "amphp/socket": "v1.1.*", + "phpinnacle/buffer": "v1.1.*" + }, + "require-dev": { + "phpunit/phpunit": "v9.5.*", + "vimeo/psalm": "v4.3.*", + "phpstan/phpstan": "v0.12.*" + }, + "prefer-stable": true, + "autoload": { + "psr-4": { + "PHPinnacle\\Ridge\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "PHPinnacle\\Ridge\\Tests\\": "tests" + } + }, + "scripts": { + "psalm": "./vendor/bin/psalm --config=psalm.xml", + "phpstan": "./vendor/bin/phpstan analyse src --level 7", + "tests": "./vendor/bin/phpunit --configuration phpunit.xml --verbose", + "coverage": "./vendor/bin/phpunit --configuration phpunit.xml --coverage-html ./coverage --verbose" + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "config": { + "sort-packages": true, + "optimize-autoloader": true + } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fac00c9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: "3" + +services: + + queue: + image: rabbitmq:3-management + container_name: service-bus-skeletone-queue + restart: always + ports: + - 5672:5672 + - 15672:15672 + environment: + RABBITMQ_VM_MEMORY_HIGH_WATERMARK: 512MiB + RABBITMQ_ERLANG_COOKIE: f6fAjy5yes + RABBITMQ_DEFAULT_USER: guest + RABBITMQ_DEFAULT_PASS: guest \ No newline at end of file diff --git a/phpbench.json b/phpbench.json deleted file mode 100644 index 466f9e5..0000000 --- a/phpbench.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "bootstrap": "vendor/autoload.php" -} \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..0d1e496 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +parameters: + checkGenericClassInNonGenericObjectType: false + checkMissingIterableValueType: false + ignoreErrors: + - + message: '#Unable to resolve the template type#' + path: %currentWorkingDirectory%/src + - + message: '#AbstractFrame given#' + path: %currentWorkingDirectory%/src/Channel.php + - + message: '#AbstractFrame given#' + path: %currentWorkingDirectory%/src/Client.php \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 1a43959..f44f4be 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,35 +1,25 @@ - + + + + ./ + + + ./tests + ./vendor + + - + - tests + ./tests/ - - - src - - - - - - - - - diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..d30e53e --- /dev/null +++ b/psalm.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + diff --git a/src/Buffer.php b/src/Buffer.php index cec8014..5e4b943 100644 --- a/src/Buffer.php +++ b/src/Buffer.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; @@ -16,63 +16,51 @@ final class Buffer extends ByteBuffer { - /** - * @param string $value - * - * @return static - */ public function appendString(string $value): self { $this ->appendUint8(\strlen($value)) - ->append($value) - ; + ->append($value); return $this; } /** - * @return string + * @throws \PHPinnacle\Buffer\BufferOverflow */ public function consumeString(): string { return $this->consume($this->consumeUint8()); } - /** - * @param string $value - * - * @return self - */ public function appendText(string $value): self { $this ->appendUint32(\strlen($value)) - ->append($value) - ; + ->append($value); return $this; } /** - * @return string + * @throws \PHPinnacle\Buffer\BufferOverflow */ public function consumeText(): string { return $this->consume($this->consumeUint32()); } - /** - * @param array $bits - * - * @return self - */ public function appendBits(array $bits): self { $value = 0; - foreach ($bits as $n => $bit) { - $bit = $bit ? 1 : 0; + /** + * @var int $n + * @var bool $bit + */ + foreach($bits as $n => $bit) + { + $bit = $bit ? 1 : 0; $value |= $bit << $n; } @@ -82,27 +70,21 @@ public function appendBits(array $bits): self } /** - * @param int $n - * - * @return bool[] + * @throws \PHPinnacle\Buffer\BufferOverflow */ public function consumeBits(int $n): array { - $bits = []; + $bits = []; $value = $this->consumeUint8(); - for ($i = 0; $i < $n; ++$i) { + for($i = 0; $i < $n; ++$i) + { $bits[] = ($value & (1 << $i)) > 0; } return $bits; } - /** - * @param \DateTimeInterface $value - * - * @return self - */ public function appendTimestamp(\DateTimeInterface $value): self { $this->appendUint64($value->getTimestamp()); @@ -110,27 +92,25 @@ public function appendTimestamp(\DateTimeInterface $value): self return $this; } - /** - * @noinspection PhpDocMissingThrowsInspection - * - * @return \DateTimeInterface - */ public function consumeTimestamp(): \DateTimeInterface { /** @noinspection PhpUnhandledExceptionInspection */ - return (new \DateTimeImmutable)->setTimestamp($this->consumeUint64()); + return new \DateTimeImmutable(\sprintf('@%s', $this->consumeUint64())); } /** - * @param array $table - * - * @return self + * @throws \PHPinnacle\Ridge\Exception\ProtocolException */ public function appendTable(array $table): self { - $buffer = new static; - - foreach ($table as $k => $v) { + $buffer = new self(); + + /** + * @var string|ByteBuffer $k + * @var mixed $v + */ + foreach($table as $k => $v) + { $k = (string) $k; $buffer->appendUint8(\strlen($k)); @@ -140,21 +120,21 @@ public function appendTable(array $table): self $this ->appendUint32($buffer->size()) - ->append($buffer) - ; + ->append($buffer); return $this; } /** - * @return array + * @throws \PHPinnacle\Buffer\BufferOverflow */ public function consumeTable(): array { $buffer = $this->shift($this->consumeUint32()); - $data = []; + $data = []; - while (!$buffer->empty()) { + while(!$buffer->empty()) + { $data[$buffer->consume($buffer->consumeUint8())] = $buffer->consumeValue(); } @@ -162,35 +142,35 @@ public function consumeTable(): array } /** - * @param array $value - * - * @return self + * @throws \PHPinnacle\Ridge\Exception\ProtocolException */ public function appendArray(array $value): self { - $buffer = new static; + $buffer = new self(); - foreach ($value as $v) { + /** @var mixed $v */ + foreach($value as $v) + { $buffer->appendValue($v); } $this ->appendUint32($buffer->size()) - ->append($buffer) - ; + ->append($buffer); return $this; } /** - * @return array + * @throws \PHPinnacle\Buffer\BufferOverflow */ public function consumeArray(): array { $buffer = $this->shift($this->consumeUint32()); - $data = []; + $data = []; - while (!$buffer->empty()) { + while(!$buffer->empty()) + { $data[] = $buffer->consumeValue(); } @@ -198,7 +178,7 @@ public function consumeArray(): array } /** - * @return int + * @throws \PHPinnacle\Buffer\BufferOverflow */ public function consumeDecimal(): int { @@ -209,87 +189,105 @@ public function consumeDecimal(): int } /** - * @return mixed - * @throws Exception\ProtocolException + * @throws \PHPinnacle\Buffer\BufferOverflow + * @throws \PHPinnacle\Ridge\Exception\ProtocolException */ - private function consumeValue() + private function consumeValue(): float|\DateTimeInterface|null|array|bool|int|string { $fieldType = $this->consumeUint8(); - switch ($fieldType) { - case Constants::FIELD_BOOLEAN: - return $this->consumeUint8() > 0; - case Constants::FIELD_SHORT_SHORT_INT: - return $this->consumeInt8(); - case Constants::FIELD_SHORT_SHORT_UINT: - return $this->consumeUint8(); - case Constants::FIELD_SHORT_INT: - return $this->consumeInt16(); - case Constants::FIELD_SHORT_UINT: - return $this->consumeUint16(); - case Constants::FIELD_LONG_INT: - return $this->consumeInt32(); - case Constants::FIELD_LONG_UINT: - return $this->consumeUint32(); - case Constants::FIELD_LONG_LONG_INT: - return $this->consumeInt64(); - case Constants::FIELD_LONG_LONG_UINT: - return $this->consumeUint64(); - case Constants::FIELD_FLOAT: - return $this->consumeFloat(); - case Constants::FIELD_DOUBLE: - return $this->consumeDouble(); - case Constants::FIELD_DECIMAL: - return $this->consumeDecimal(); - case Constants::FIELD_SHORT_STRING: - return $this->consume($this->consumeUint8()); - case Constants::FIELD_LONG_STRING: - return $this->consume($this->consumeUint32()); - case Constants::FIELD_TIMESTAMP: - return $this->consumeTimestamp(); - case Constants::FIELD_ARRAY: - return $this->consumeArray(); - case Constants::FIELD_TABLE: - return $this->consumeTable(); - case Constants::FIELD_NULL: - return null; - default: - throw Exception\ProtocolException::unknownFieldType($fieldType); - } + return match ($fieldType) + { + Constants::FIELD_BOOLEAN => $this->consumeUint8() > 0, + Constants::FIELD_SHORT_SHORT_INT => $this->consumeInt8(), + Constants::FIELD_SHORT_SHORT_UINT => $this->consumeUint8(), + Constants::FIELD_SHORT_INT => $this->consumeInt16(), + Constants::FIELD_SHORT_UINT => $this->consumeUint16(), + Constants::FIELD_LONG_INT => $this->consumeInt32(), + Constants::FIELD_LONG_UINT => $this->consumeUint32(), + Constants::FIELD_LONG_LONG_INT => $this->consumeInt64(), + Constants::FIELD_LONG_LONG_UINT => $this->consumeUint64(), + Constants::FIELD_FLOAT => $this->consumeFloat(), + Constants::FIELD_DOUBLE => $this->consumeDouble(), + Constants::FIELD_DECIMAL => $this->consumeDecimal(), + Constants::FIELD_SHORT_STRING => $this->consume($this->consumeUint8()), + Constants::FIELD_LONG_STRING => $this->consume($this->consumeUint32()), + Constants::FIELD_TIMESTAMP => $this->consumeTimestamp(), + Constants::FIELD_ARRAY => $this->consumeArray(), + Constants::FIELD_TABLE => $this->consumeTable(), + Constants::FIELD_NULL => null, + default => throw Exception\ProtocolException::unknownFieldType($fieldType), + }; } /** - * @param mixed $value + * @throws \PHPinnacle\Ridge\Exception\ProtocolException */ - private function appendValue($value) + private function appendValue(mixed $value): void { - if (\is_string($value)) { + if(\is_string($value)) + { $this->appendUint8(Constants::FIELD_LONG_STRING); $this->appendText($value); - } elseif (\is_int($value)) { + + return; + } + + if(\is_int($value)) + { $this->appendUint8(Constants::FIELD_LONG_INT); $this->appendInt32($value); - } elseif (\is_bool($value)) { + + return; + } + + if(\is_bool($value)) + { $this->appendUint8(Constants::FIELD_BOOLEAN); - $this->appendUint8(\intval($value)); - } elseif (\is_float($value)) { + $this->appendUint8((int) $value); + + return; + } + + if(\is_float($value)) + { $this->appendUint8(Constants::FIELD_DOUBLE); $this->appendDouble($value); - } elseif (\is_array($value)) { - if (\array_keys($value) === \range(0, \count($value) - 1)) { + + return; + } + + if(\is_array($value)) + { + if(\array_keys($value) === \range(0, \count($value) - 1)) + { $this->appendUint8(Constants::FIELD_ARRAY); $this->appendArray($value); - } else { + } + else + { $this->appendUint8(Constants::FIELD_TABLE); $this->appendTable($value); } - } elseif (\is_null($value)) { + + return; + } + + if(\is_null($value)) + { $this->appendUint8(Constants::FIELD_NULL); - } elseif ($value instanceof \DateTime) { + + return; + } + + if($value instanceof \DateTimeInterface) + { $this->appendUint8(Constants::FIELD_TIMESTAMP); $this->appendTimestamp($value); - } else { - throw Exception\ProtocolException::unknownValueType($value); + + return; } + + throw Exception\ProtocolException::unknownValueType($value); } -} \ No newline at end of file +} diff --git a/src/Channel.php b/src/Channel.php index c188745..f1b7300 100644 --- a/src/Channel.php +++ b/src/Channel.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; @@ -18,19 +18,18 @@ final class Channel { - private const - STATE_READY = 1, - STATE_OPEN = 2, - STATE_CLOSING = 3, - STATE_CLOSED = 4, - STATE_ERROR = 5 - ; - - private const - MODE_REGULAR = 1, // Regular AMQP guarantees of published messages delivery. - MODE_TRANSACTIONAL = 2, // Messages are published after 'tx.commit'. - MODE_CONFIRM = 3 // Broker sends asynchronously 'basic.ack's for delivered messages. - ; + private const STATE_READY = 1; + private const STATE_OPEN = 2; + private const STATE_CLOSING = 3; + private const STATE_CLOSED = 4; + private const STATE_ERROR = 5; + + /** Regular AMQP guarantees of published messages delivery. */ + private const MODE_REGULAR = 1; + /** Messages are published after 'tx.commit'. */ + private const MODE_TRANSACTIONAL = 2; + /** Broker sends asynchronously 'basic.ack's for delivered messages. */ + private const MODE_CONFIRM = 3; /** * @var int @@ -77,11 +76,6 @@ final class Channel */ private $deliveryTag = 0; - /** - * @param int $id - * @param Connection $connection - * @param Properties $properties - */ public function __construct(int $id, Connection $connection, Properties $properties) { $this->id = $id; @@ -92,132 +86,124 @@ public function __construct(int $id, Connection $connection, Properties $propert $this->events = new Events($this, $this->receiver); } - /** - * @return int - */ public function id(): int { return $this->id; } - /** - * @return Events - */ public function events(): Events { return $this->events; } /** - * @param string $outOfBand - * * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ChannelException */ public function open(string $outOfBand = ''): Promise { - return call(function () use ($outOfBand) { - if ($this->state !== self::STATE_READY) { - throw Exception\ChannelException::notReady($this->id); - } + return call( + function() use ($outOfBand) + { + if($this->state !== self::STATE_READY) + { + throw Exception\ChannelException::notReady($this->id); + } - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(5 + \strlen($outOfBand)) - ->appendUint16(20) - ->appendUint16(10) - ->appendString($outOfBand) - ->appendUint8(206) - ); + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(5 + \strlen($outOfBand)) + ->appendUint16(20) + ->appendUint16(10) + ->appendString($outOfBand) + ->appendUint8(206) + ); - yield $this->await(Protocol\ChannelOpenOkFrame::class); + yield $this->await(Protocol\ChannelOpenOkFrame::class); - $this->receiver->start(); - $this->consumer->start(); + $this->receiver->start(); + $this->consumer->start(); - $this->state = self::STATE_OPEN; - }); + $this->state = self::STATE_OPEN; + } + ); } /** - * @param int $code - * @param string $reason - * * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ChannelException */ public function close(int $code = 0, string $reason = ''): Promise { - return call(function () use ($code, $reason) { - if ($this->state === self::STATE_CLOSED) { - throw Exception\ChannelException::alreadyClosed($this->id); - } + return call( + function() use ($code, $reason) + { + if($this->state === self::STATE_CLOSED) + { + throw Exception\ChannelException::alreadyClosed($this->id); + } - if ($this->state === self::STATE_CLOSING) { - return; - } + if($this->state === self::STATE_CLOSING) + { + return; + } - $this->state = self::STATE_CLOSING; + $this->state = self::STATE_CLOSING; - $this->receiver->stop(); - $this->consumer->stop(); + $this->receiver->stop(); + $this->consumer->stop(); - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(11 + \strlen($reason)) - ->appendUint16(20) - ->appendUint16(40) - ->appendInt16($code) - ->appendString($reason) - ->appendInt16(0) - ->appendInt16(0) - ->appendUint8(206) - ); + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(11 + \strlen($reason)) + ->appendUint16(20) + ->appendUint16(40) + ->appendInt16($code) + ->appendString($reason) + ->appendInt16(0) + ->appendInt16(0) + ->appendUint8(206) + ); - yield $this->await(Protocol\ChannelCloseOkFrame::class); - - $this->connection->cancel($this->id); + yield $this->await(Protocol\ChannelCloseOkFrame::class); - $this->state = self::STATE_CLOSED; - }); + $this->connection->cancel($this->id); + + $this->state = self::STATE_CLOSED; + } + ); } /** - * @param int $prefetchSize - * @param int $prefetchCount - * @param bool $global - * * @return Promise */ public function qos(int $prefetchSize = 0, int $prefetchCount = 0, bool $global = false): Promise { - return call(function () use ($prefetchSize, $prefetchCount, $global) { - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(11) - ->appendUint16(60) - ->appendUint16(10) - ->appendInt32($prefetchSize) - ->appendInt16($prefetchCount) - ->appendBits([$global]) - ->appendUint8(206) - ); + return call( + function() use ($prefetchSize, $prefetchCount, $global) + { + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(11) + ->appendUint16(60) + ->appendUint16(10) + ->appendInt32($prefetchSize) + ->appendInt16($prefetchCount) + ->appendBits([$global]) + ->appendUint8(206) + ); - yield $this->await(Protocol\BasicQosOkFrame::class); - }); + yield $this->await(Protocol\BasicQosOkFrame::class); + } + ); } /** - * @param callable $callback - * @param string $queue - * @param string $consumerTag - * @param bool $noLocal - * @param bool $noAck - * @param bool $exclusive - * @param bool $noWait - * @param array $arguments - * * @return Promise */ public function consume @@ -230,125 +216,128 @@ public function consume bool $exclusive = false, bool $noWait = false, array $arguments = [] - ) : Promise + ): Promise { $flags = [$noLocal, $noAck, $exclusive, $noWait]; - return call(function () use ($callback, $queue, $consumerTag, $flags, $noWait, $arguments) { - yield $this->connection->method($this->id, (new Buffer) - ->appendUint16(60) - ->appendUint16(20) - ->appendInt16(0) - ->appendString($queue) - ->appendString($consumerTag) - ->appendBits($flags) - ->appendTable($arguments) - ); - - if ($noWait === false) { - /** @var Protocol\BasicConsumeOkFrame $frame */ - $frame = yield $this->await(Protocol\BasicConsumeOkFrame::class); - - if ('' === $consumerTag) { - $consumerTag = $frame->consumerTag; + return call( + function() use ($callback, $queue, $consumerTag, $flags, $noWait, $arguments) + { + yield $this->connection->method($this->id, (new Buffer) + ->appendUint16(60) + ->appendUint16(20) + ->appendInt16(0) + ->appendString($queue) + ->appendString($consumerTag) + ->appendBits($flags) + ->appendTable($arguments) + ); + + if($noWait === false) + { + /** @var Protocol\BasicConsumeOkFrame $frame */ + $frame = yield $this->await(Protocol\BasicConsumeOkFrame::class); + + if('' === $consumerTag) + { + $consumerTag = $frame->consumerTag; + } } - } - $this->consumer->subscribe($consumerTag, $callback); + $this->consumer->subscribe($consumerTag, $callback); - return $consumerTag; - }); + return $consumerTag; + } + ); } /** - * @param string $consumerTag - * @param bool $noWait - * * @return Promise */ public function cancel(string $consumerTag, bool $noWait = false): Promise { - return call(function () use ($consumerTag, $noWait) { - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(6 + \strlen($consumerTag)) - ->appendUint16(60) - ->appendUint16(30) - ->appendString($consumerTag) - ->appendBits([$noWait]) - ->appendUint8(206) - ); + return call( + function() use ($consumerTag, $noWait) + { + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(6 + \strlen($consumerTag)) + ->appendUint16(60) + ->appendUint16(30) + ->appendString($consumerTag) + ->appendBits([$noWait]) + ->appendUint8(206) + ); - if ($noWait === false) { - yield $this->await(Protocol\BasicCancelOkFrame::class); - } + if($noWait === false) + { + yield $this->await(Protocol\BasicCancelOkFrame::class); + } - $this->consumer->cancel($consumerTag); - }); + $this->consumer->cancel($consumerTag); + } + ); } /** - * @param Message $message - * @param bool $multiple - * * @return Promise */ public function ack(Message $message, bool $multiple = false): Promise { - return call(function () use ($message, $multiple) { - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(13) - ->appendUint16(60) - ->appendUint16(80) - ->appendInt64($message->deliveryTag()) - ->appendBits([$multiple]) - ->appendUint8(206) - ); - }); + return call( + function() use ($message, $multiple) + { + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(13) + ->appendUint16(60) + ->appendUint16(80) + ->appendInt64((int) $message->deliveryTag()) + ->appendBits([$multiple]) + ->appendUint8(206) + ); + } + ); } /** - * @param Message $message - * @param bool $multiple - * @param bool $requeue - * * @return Promise */ public function nack(Message $message, bool $multiple = false, bool $requeue = true): Promise { - return call(function () use ($message, $multiple, $requeue) { - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(13) - ->appendUint16(60) - ->appendUint16(120) - ->appendInt64($message->deliveryTag()) - ->appendBits([$multiple, $requeue]) - ->appendUint8(206) - ); - }); + return call( + function() use ($message, $multiple, $requeue) + { + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(13) + ->appendUint16(60) + ->appendUint16(120) + ->appendInt64((int) $message->deliveryTag()) + ->appendBits([$multiple, $requeue]) + ->appendUint8(206) + ); + } + ); } /** - * @param Message $message - * @param bool $requeue - * * @return Promise */ public function reject(Message $message, bool $requeue = true): Promise { - return call(function () use ($message, $requeue) { + return call(function() use ($message, $requeue) + { yield $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) ->appendUint32(13) ->appendUint16(60) ->appendUint16(90) - ->appendInt64($message->deliveryTag()) + ->appendInt64((int) $message->deliveryTag()) ->appendBits([$requeue]) ->appendUint8(206) ); @@ -356,132 +345,110 @@ public function reject(Message $message, bool $requeue = true): Promise } /** - * @param bool $requeue - * * @return Promise */ public function recover(bool $requeue = false): Promise { - return call(function () use ($requeue) { - $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(5) - ->appendUint16(60) - ->appendUint16(110) - ->appendBits([$requeue]) - ->appendUint8(206) - ); - - yield $this->await(Protocol\BasicRecoverOkFrame::class); - }); - } + return call( + function() use ($requeue) + { + $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(5) + ->appendUint16(60) + ->appendUint16(110) + ->appendBits([$requeue]) + ->appendUint8(206) + ); - /** - * @param bool $requeue - * - * @return Promise - * @deprecated This method is deprecated in favour of the synchronous Recover/Recover-Ok. - */ - public function recoverAsync(bool $requeue = false): Promise - { - return call(function () use ($requeue) { - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(5) - ->appendUint16(60) - ->appendUint16(100) - ->appendBits([$requeue]) - ->appendUint8(206) - ); - }); + yield $this->await(Protocol\BasicRecoverOkFrame::class); + } + ); } /** - * @param string $queue - * @param bool $noAck - * * @return Promise */ public function get(string $queue = '', bool $noAck = false): Promise { static $getting = false; - return call(function () use ($queue, $noAck, &$getting) { - if ($getting) { - throw Exception\ChannelException::getInProgress(); - } + return call( + function() use ($queue, $noAck, &$getting) + { + if($getting) + { + throw Exception\ChannelException::getInProgress(); + } - $getting = true; + $getting = true; - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(8 + \strlen($queue)) - ->appendUint16(60) - ->appendUint16(70) - ->appendInt16(0) - ->appendString($queue) - ->appendBits([$noAck]) - ->appendUint8(206) - ); + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(8 + \strlen($queue)) + ->appendUint16(60) + ->appendUint16(70) + ->appendInt16(0) + ->appendString($queue) + ->appendBits([$noAck]) + ->appendUint8(206) + ); - $frame = yield Promise\first([ - $this->await(Protocol\BasicGetOkFrame::class), - $this->await(Protocol\BasicGetEmptyFrame::class) - ]); + /** @var Protocol\BasicGetOkFrame|Protocol\BasicGetEmptyFrame $frame */ + $frame = yield Promise\first([ + $this->await(Protocol\BasicGetOkFrame::class), + $this->await(Protocol\BasicGetEmptyFrame::class) + ]); - if ($frame instanceof Protocol\BasicGetEmptyFrame) { - $getting = false; + if($frame instanceof Protocol\BasicGetEmptyFrame) + { + $getting = false; - return null; - } + return null; + } - /** @var Protocol\ContentHeaderFrame $header */ - $header = yield $this->await(Protocol\ContentHeaderFrame::class); + /** @var Protocol\ContentHeaderFrame $header */ + $header = yield $this->await(Protocol\ContentHeaderFrame::class); - $buffer = new Buffer; - $remaining = $header->bodySize; + $buffer = new Buffer; + $remaining = $header->bodySize; - while ($remaining > 0) { - /** @var Protocol\ContentBodyFrame $body */ - $body = yield $this->await(Protocol\ContentBodyFrame::class); + while($remaining > 0) + { + /** @var Protocol\ContentBodyFrame $body */ + $body = yield $this->await(Protocol\ContentBodyFrame::class); - $buffer->append($body->payload); + $buffer->append((string) $body->payload); - $remaining -= $body->size; + $remaining -= (int) $body->size; - if ($remaining < 0) { - $this->state = self::STATE_ERROR; + if($remaining < 0) + { + $this->state = self::STATE_ERROR; - throw Exception\ChannelException::bodyOverflow($remaining); + throw Exception\ChannelException::bodyOverflow($remaining); + } } - } - $getting = false; - - return new Message( - $buffer->flush(), - $frame->exchange, - $frame->routingKey, - null, - $frame->deliveryTag, - $frame->redelivered, - false, - $header->toArray() - ); - }); + $getting = false; + + return new Message( + $buffer->flush(), + $frame->exchange, + $frame->routingKey, + null, + $frame->deliveryTag, + $frame->redelivered, + false, + $header->toArray() + ); + } + ); } /** - * @param string $body - * @param string $exchange - * @param string $routingKey - * @param array $headers - * @param bool $mandatory - * @param bool $immediate - * * @return Promise */ public function publish @@ -494,124 +461,142 @@ public function publish bool $immediate = false ): Promise { - return call(function () use ($body, $exchange, $routingKey, $headers, $mandatory, $immediate) { - yield $this->doPublish($body, $exchange, $routingKey, $headers, $mandatory, $immediate); + return call( + function() use ($body, $exchange, $routingKey, $headers, $mandatory, $immediate) + { + yield $this->doPublish($body, $exchange, $routingKey, $headers, $mandatory, $immediate); - return $this->mode === self::MODE_CONFIRM ? ++$this->deliveryTag : null; - }); + return $this->mode === self::MODE_CONFIRM ? ++$this->deliveryTag : null; + } + ); } /** * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ChannelException */ public function txSelect(): Promise { - return call(function () { - if ($this->mode !== self::MODE_REGULAR) { - throw Exception\ChannelException::notRegularFor("transactional"); - } + return call( + function() + { + if($this->mode !== self::MODE_REGULAR) + { + throw Exception\ChannelException::notRegularFor("transactional"); + } - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(4) - ->appendUint16(90) - ->appendUint16(10) - ->appendUint8(206) - ); + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(4) + ->appendUint16(90) + ->appendUint16(10) + ->appendUint8(206) + ); - yield $this->await(Protocol\TxSelectOkFrame::class); + yield $this->await(Protocol\TxSelectOkFrame::class); - $this->mode = self::MODE_TRANSACTIONAL; - }); + $this->mode = self::MODE_TRANSACTIONAL; + } + ); } /** * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ChannelException */ public function txCommit(): Promise { - return call(function () { - if ($this->mode !== self::MODE_TRANSACTIONAL) { - throw Exception\ChannelException::notTransactional(); - } + return call( + function() + { + if($this->mode !== self::MODE_TRANSACTIONAL) + { + throw Exception\ChannelException::notTransactional(); + } - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(4) - ->appendUint16(90) - ->appendUint16(20) - ->appendUint8(206) - ); + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(4) + ->appendUint16(90) + ->appendUint16(20) + ->appendUint8(206) + ); - yield $this->await(Protocol\TxCommitOkFrame::class); - }); + yield $this->await(Protocol\TxCommitOkFrame::class); + } + ); } /** * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ChannelException */ public function txRollback(): Promise { - return call(function () { - if ($this->mode !== self::MODE_TRANSACTIONAL) { - throw Exception\ChannelException::notTransactional(); - } + return call( + function() + { + if($this->mode !== self::MODE_TRANSACTIONAL) + { + throw Exception\ChannelException::notTransactional(); + } - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(4) - ->appendUint16(90) - ->appendUint16(30) - ->appendUint8(206) - ); + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(4) + ->appendUint16(90) + ->appendUint16(30) + ->appendUint8(206) + ); - yield $this->await(Protocol\TxRollbackOkFrame::class); - }); + yield $this->await(Protocol\TxRollbackOkFrame::class); + } + ); } /** - * @param bool $noWait - * * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ChannelException */ - public function confirmSelect(bool $noWait = false) + public function confirmSelect(bool $noWait = false): Promise { - return call(function () use ($noWait) { - if ($this->mode !== self::MODE_REGULAR) { - throw Exception\ChannelException::notRegularFor("confirm"); - } + return call( + function() use ($noWait) + { + if($this->mode !== self::MODE_REGULAR) + { + throw Exception\ChannelException::notRegularFor("confirm"); + } - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(5) - ->appendUint16(85) - ->appendUint16(10) - ->appendBits([$noWait]) - ->appendUint8(206) - ); + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(5) + ->appendUint16(85) + ->appendUint16(10) + ->appendBits([$noWait]) + ->appendUint8(206) + ); - if ($noWait === false) { - yield $this->await(Protocol\ConfirmSelectOkFrame::class); - } + if($noWait === false) + { + yield $this->await(Protocol\ConfirmSelectOkFrame::class); + } - $this->mode = self::MODE_CONFIRM; - $this->deliveryTag = 0; - }); + $this->mode = self::MODE_CONFIRM; + $this->deliveryTag = 0; + } + ); } /** - * @param string $queue - * @param bool $passive - * @param bool $durable - * @param bool $exclusive - * @param bool $autoDelete - * @param bool $noWait - * @param array $arguments - * * @return Promise */ public function queueDeclare @@ -627,34 +612,32 @@ public function queueDeclare { $flags = [$passive, $durable, $exclusive, $autoDelete, $noWait]; - return call(function () use ($queue, $flags, $noWait, $arguments) { - yield $this->connection->method($this->id, (new Buffer) - ->appendUint16(50) - ->appendUint16(10) - ->appendInt16(0) - ->appendString($queue) - ->appendBits($flags) - ->appendTable($arguments) - ); - - if ($noWait) { - return null; - } + return call( + function() use ($queue, $flags, $noWait, $arguments) + { + yield $this->connection->method($this->id, (new Buffer) + ->appendUint16(50) + ->appendUint16(10) + ->appendInt16(0) + ->appendString($queue) + ->appendBits($flags) + ->appendTable($arguments) + ); + + if($noWait) + { + return null; + } - /** @var Protocol\QueueDeclareOkFrame $frame */ - $frame = yield $this->await(Protocol\QueueDeclareOkFrame::class); + /** @var Protocol\QueueDeclareOkFrame $frame */ + $frame = yield $this->await(Protocol\QueueDeclareOkFrame::class); - return new Queue($frame->queue, $frame->messageCount, $frame->consumerCount); - }); + return new Queue($frame->queue, $frame->messageCount, $frame->consumerCount); + } + ); } /** - * @param string $queue - * @param string $exchange - * @param string $routingKey - * @param bool $noWait - * @param array $arguments - * * @return Promise */ public function queueBind @@ -666,33 +649,31 @@ public function queueBind array $arguments = [] ): Promise { - return call(function () use ($queue, $exchange, $routingKey, $noWait, $arguments) { - yield $this->connection->method($this->id, (new Buffer) - ->appendUint16(50) - ->appendUint16(20) - ->appendInt16(0) - ->appendString($queue) - ->appendString($exchange) - ->appendString($routingKey) - ->appendBits([$noWait]) - ->appendTable($arguments) - ); + return call( + function() use ($queue, $exchange, $routingKey, $noWait, $arguments) + { + yield $this->connection->method($this->id, (new Buffer) + ->appendUint16(50) + ->appendUint16(20) + ->appendInt16(0) + ->appendString($queue) + ->appendString($exchange) + ->appendString($routingKey) + ->appendBits([$noWait]) + ->appendTable($arguments) + ); + + if($noWait) + { + return; + } - if ($noWait) { - return; + yield $this->await(Protocol\QueueBindOkFrame::class); } - - yield $this->await(Protocol\QueueBindOkFrame::class); - }); + ); } /** - * @param string $queue - * @param string $exchange - * @param string $routingKey - * @param bool $noWait - * @param array $arguments - * * @return Promise */ public function queueUnbind @@ -704,63 +685,63 @@ public function queueUnbind array $arguments = [] ): Promise { - return call(function () use ($queue, $exchange, $routingKey, $noWait, $arguments) { - yield $this->connection->method($this->id, (new Buffer) - ->appendUint16(50) - ->appendUint16(50) - ->appendInt16(0) - ->appendString($queue) - ->appendString($exchange) - ->appendString($routingKey) - ->appendTable($arguments) - ); + return call( + function() use ($queue, $exchange, $routingKey, $noWait, $arguments) + { + yield $this->connection->method($this->id, (new Buffer) + ->appendUint16(50) + ->appendUint16(50) + ->appendInt16(0) + ->appendString($queue) + ->appendString($exchange) + ->appendString($routingKey) + ->appendTable($arguments) + ); + + if($noWait) + { + return; + } - if ($noWait) { - return; + yield $this->await(Protocol\QueueUnbindOkFrame::class); } - - yield $this->await(Protocol\QueueUnbindOkFrame::class); - }); + ); } /** - * @param string $queue - * @param bool $noWait - * * @return Promise */ public function queuePurge(string $queue = '', bool $noWait = false): Promise { - return call(function () use ($queue, $noWait) { - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(8 + \strlen($queue)) - ->appendUint16(50) - ->appendUint16(30) - ->appendInt16(0) - ->appendString($queue) - ->appendBits([$noWait]) - ->appendUint8(206) - ); + return call( + function() use ($queue, $noWait) + { + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(8 + \strlen($queue)) + ->appendUint16(50) + ->appendUint16(30) + ->appendInt16(0) + ->appendString($queue) + ->appendBits([$noWait]) + ->appendUint8(206) + ); - if ($noWait) { - return 0; - } + if($noWait) + { + return 0; + } - /** @var Protocol\QueuePurgeOkFrame $frame */ - $frame = yield $this->await(Protocol\QueuePurgeOkFrame::class); + /** @var Protocol\QueuePurgeOkFrame $frame */ + $frame = yield $this->await(Protocol\QueuePurgeOkFrame::class); - return $frame->messageCount; - }); + return $frame->messageCount; + } + ); } /** - * @param string $queue - * @param bool $ifUnused - * @param bool $ifEmpty - * @param bool $noWait - * * @return Promise */ public function queueDelete @@ -773,41 +754,36 @@ public function queueDelete { $flags = [$ifUnused, $ifEmpty, $noWait]; - return call(function () use ($queue, $flags, $noWait) { - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(8 + strlen($queue)) - ->appendUint16(50) - ->appendUint16(40) - ->appendInt16(0) - ->appendString($queue) - ->appendBits($flags) - ->appendUint8(206) - ); + return call( + function() use ($queue, $flags, $noWait) + { + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(8 + strlen($queue)) + ->appendUint16(50) + ->appendUint16(40) + ->appendInt16(0) + ->appendString($queue) + ->appendBits($flags) + ->appendUint8(206) + ); - if ($noWait) { - return 0; - } + if($noWait) + { + return 0; + } - /** @var Protocol\QueueDeleteOkFrame $frame */ - $frame = yield $this->await(Protocol\QueueDeleteOkFrame::class); + /** @var Protocol\QueueDeleteOkFrame $frame */ + $frame = yield $this->await(Protocol\QueueDeleteOkFrame::class); - return $frame->messageCount; - }); + return $frame->messageCount; + } + ); } /** - * @param string $exchange - * @param string $exchangeType - * @param bool $passive - * @param bool $durable - * @param bool $autoDelete - * @param bool $internal - * @param bool $noWait - * @param array $arguments - * - * @return Promise + * @return Promise */ public function exchangeDeclare ( @@ -823,32 +799,30 @@ public function exchangeDeclare { $flags = [$passive, $durable, $autoDelete, $internal, $noWait]; - return call(function () use ($exchange, $exchangeType, $flags, $noWait, $arguments) { - yield $this->connection->method($this->id, (new Buffer) - ->appendUint16(40) - ->appendUint16(10) - ->appendInt16(0) - ->appendString($exchange) - ->appendString($exchangeType) - ->appendBits($flags) - ->appendTable($arguments) - ); + return call( + function() use ($exchange, $exchangeType, $flags, $noWait, $arguments) + { + yield $this->connection->method($this->id, (new Buffer) + ->appendUint16(40) + ->appendUint16(10) + ->appendInt16(0) + ->appendString($exchange) + ->appendString($exchangeType) + ->appendBits($flags) + ->appendTable($arguments) + ); + + if($noWait) + { + return; + } - if ($noWait) { - return; + yield $this->await(Protocol\ExchangeDeclareOkFrame::class); } - - yield $this->await(Protocol\ExchangeDeclareOkFrame::class); - }); + ); } /** - * @param string $destination - * @param string $source - * @param string $routingKey - * @param bool $noWait - * @param array $arguments - * * @return Promise */ public function exchangeBind @@ -860,33 +834,31 @@ public function exchangeBind array $arguments = [] ): Promise { - return call(function () use ($destination, $source, $routingKey, $noWait, $arguments) { - yield $this->connection->method($this->id, (new Buffer) - ->appendUint16(40) - ->appendUint16(30) - ->appendInt16(0) - ->appendString($destination) - ->appendString($source) - ->appendString($routingKey) - ->appendBits([$noWait]) - ->appendTable($arguments) - ); + return call( + function() use ($destination, $source, $routingKey, $noWait, $arguments) + { + yield $this->connection->method($this->id, (new Buffer) + ->appendUint16(40) + ->appendUint16(30) + ->appendInt16(0) + ->appendString($destination) + ->appendString($source) + ->appendString($routingKey) + ->appendBits([$noWait]) + ->appendTable($arguments) + ); + + if($noWait) + { + return; + } - if ($noWait) { - return; + yield $this->await(Protocol\ExchangeBindOkFrame::class); } - - yield $this->await(Protocol\ExchangeBindOkFrame::class); - }); + ); } /** - * @param string $destination - * @param string $source - * @param string $routingKey - * @param bool $noWait - * @param array $arguments - * * @return Promise */ public function exchangeUnbind @@ -898,66 +870,60 @@ public function exchangeUnbind array $arguments = [] ): Promise { - return call(function () use ($destination, $source, $routingKey, $noWait, $arguments) { - yield $this->connection->method($this->id, (new Buffer) - ->appendUint16(40) - ->appendUint16(40) - ->appendInt16(0) - ->appendString($destination) - ->appendString($source) - ->appendString($routingKey) - ->appendBits([$noWait]) - ->appendTable($arguments) - ); + return call( + function() use ($destination, $source, $routingKey, $noWait, $arguments) + { + yield $this->connection->method($this->id, (new Buffer) + ->appendUint16(40) + ->appendUint16(40) + ->appendInt16(0) + ->appendString($destination) + ->appendString($source) + ->appendString($routingKey) + ->appendBits([$noWait]) + ->appendTable($arguments) + ); + + if($noWait) + { + return; + } - if ($noWait) { - return; + yield $this->await(Protocol\ExchangeUnbindOkFrame::class); } - - yield $this->await(Protocol\ExchangeUnbindOkFrame::class); - }); + ); } /** - * @param string $exchange - * @param bool $unused - * @param bool $noWait - * * @return Promise */ public function exchangeDelete(string $exchange, bool $unused = false, bool $noWait = false): Promise { - return call(function () use ($exchange, $unused, $noWait) { - yield $this->connection->write((new Buffer) - ->appendUint8(1) - ->appendUint16($this->id) - ->appendUint32(8 + \strlen($exchange)) - ->appendUint16(40) - ->appendUint16(20) - ->appendInt16(0) - ->appendString($exchange) - ->appendBits([$unused, $noWait]) - ->appendUint8(206) - ); + return call( + function() use ($exchange, $unused, $noWait) + { + yield $this->connection->write((new Buffer) + ->appendUint8(1) + ->appendUint16($this->id) + ->appendUint32(8 + \strlen($exchange)) + ->appendUint16(40) + ->appendUint16(20) + ->appendInt16(0) + ->appendString($exchange) + ->appendBits([$unused, $noWait]) + ->appendUint8(206) + ); - if ($noWait) { - return; - } + if($noWait) + { + return; + } - yield $this->await(Protocol\ExchangeDeleteOkFrame::class); - }); + yield $this->await(Protocol\ExchangeDeleteOkFrame::class); + } + ); } - /** - * @param string $body - * @param string $exchange - * @param string $routingKey - * @param array $headers - * @param bool $mandatory - * @param bool $immediate - * - * @return Promise - */ public function doPublish ( string $body, @@ -968,21 +934,21 @@ public function doPublish bool $immediate = false ): Promise { - $flags = 0; - $contentType = ''; + $flags = 0; + $contentType = ''; $contentEncoding = ''; - $type = ''; - $replyTo = ''; - $expiration = ''; - $messageId = ''; - $correlationId = ''; - $userId = ''; - $appId = ''; - $clusterId = ''; + $type = ''; + $replyTo = ''; + $expiration = ''; + $messageId = ''; + $correlationId = ''; + $userId = ''; + $appId = ''; + $clusterId = ''; $deliveryMode = null; - $priority = null; - $timestamp = null; + $priority = null; + $timestamp = null; $headersBuffer = null; @@ -997,104 +963,130 @@ public function doPublish ->appendString($exchange) ->appendString($routingKey) ->appendBits([$mandatory, $immediate]) - ->appendUint8(206) - ; + ->appendUint8(206); $size = 14; - if (isset($headers['content-type'])) { - $flags |= 32768; - $contentType = $headers['content-type']; - $size += 1 + \strlen($contentType); + if(isset($headers['content-type'])) + { + $flags |= 32768; + $contentType = (string) $headers['content-type']; + $size += 1 + \strlen($contentType); + unset($headers['content-type']); } - if (isset($headers['content-encoding'])) { - $flags |= 16384; - $contentEncoding = $headers['content-encoding']; - $size += 1 + \strlen($contentEncoding); + if(isset($headers['content-encoding'])) + { + $flags |= 16384; + $contentEncoding = (string) $headers['content-encoding']; + $size += 1 + \strlen($contentEncoding); + unset($headers['content-encoding']); } - if (isset($headers['delivery-mode'])) { - $flags |= 4096; + if(isset($headers['delivery-mode'])) + { + $flags |= 4096; $deliveryMode = (int) $headers['delivery-mode']; - $size += 1; + ++$size; + unset($headers['delivery-mode']); } - if (isset($headers['priority'])) { - $flags |= 2048; + if(isset($headers['priority'])) + { + $flags |= 2048; $priority = (int) $headers['priority']; - $size += 1; + ++$size; + unset($headers['priority']); } - if (isset($headers['correlation-id'])) { - $flags |= 1024; - $correlationId = $headers['correlation-id']; - $size += 1 + \strlen($correlationId); + if(isset($headers['correlation-id'])) + { + $flags |= 1024; + $correlationId = (string) $headers['correlation-id']; + $size += 1 + \strlen($correlationId); + unset($headers['correlation-id']); } - if (isset($headers['reply-to'])) { - $flags |= 512; - $replyTo = $headers['reply-to']; - $size += 1 + \strlen($replyTo); + if(isset($headers['reply-to'])) + { + $flags |= 512; + $replyTo = (string) $headers['reply-to']; + $size += 1 + \strlen($replyTo); + unset($headers['reply-to']); } - if (isset($headers['expiration'])) { - $flags |= 256; - $expiration = $headers['expiration']; - $size += 1 + \strlen($expiration); + if(isset($headers['expiration'])) + { + $flags |= 256; + $expiration = (string) $headers['expiration']; + $size += 1 + \strlen($expiration); + unset($headers['expiration']); } - if (isset($headers['message-id'])) { - $flags |= 128; - $messageId = $headers['message-id']; - $size += 1 + \strlen($messageId); + if(isset($headers['message-id'])) + { + $flags |= 128; + $messageId = (string) $headers['message-id']; + $size += 1 + \strlen($messageId); + unset($headers['message-id']); } - if (isset($headers['timestamp'])) { - $flags |= 64; - $timestamp = $headers['timestamp']; - $size += 8; + if(isset($headers['timestamp'])) + { + $flags |= 64; + $timestamp = (int) $headers['timestamp']; + $size += 8; + unset($headers['timestamp']); } - if (isset($headers['type'])) { + if(isset($headers['type'])) + { $flags |= 32; - $type = $headers['type']; - $size += 1 + \strlen($type); + $type = (string) $headers['type']; + $size += 1 + \strlen($type); + unset($headers['type']); } - if (isset($headers['user-id'])) { - $flags |= 16; - $userId = $headers['user-id']; - $size += 1 + \strlen($userId); + if(isset($headers['user-id'])) + { + $flags |= 16; + $userId = (string) $headers['user-id']; + $size += 1 + \strlen($userId); + unset($headers['user-id']); } - if (isset($headers['app-id'])) { + if(isset($headers['app-id'])) + { $flags |= 8; - $appId = $headers['app-id']; - $size += 1 + \strlen($appId); + $appId = (string) $headers['app-id']; + $size += 1 + \strlen($appId); + unset($headers['app-id']); } - if (isset($headers['cluster-id'])) { - $flags |= 4; - $clusterId = $headers['cluster-id']; - $size += 1 + \strlen($clusterId); + if(isset($headers['cluster-id'])) + { + $flags |= 4; + $clusterId = (string) $headers['cluster-id']; + $size += 1 + \strlen($clusterId); + unset($headers['cluster-id']); } - if (!empty($headers)) { - $flags |= 8192; + if(!empty($headers)) + { + $flags |= 8192; $headersBuffer = new Buffer; $headersBuffer->appendTable($headers); $size += $headersBuffer->size(); @@ -1107,98 +1099,125 @@ public function doPublish ->appendUint16(60) ->appendUint16(0) ->appendUint64(\strlen($body)) - ->appendUint16($flags) - ; + ->appendUint16($flags); - if ($flags & 32768) { + if($flags & 32768) + { $buffer->appendString($contentType); } - if ($flags & 16384) { + if($flags & 16384) + { $buffer->appendString($contentEncoding); } - if ($flags & 8192) { + if($flags & 8192 && $headersBuffer !== null) + { $buffer->append($headersBuffer); } - if ($flags & 4096) { - $buffer->appendUint8($deliveryMode); + if($flags & 4096) + { + $buffer->appendUint8((int) $deliveryMode); } - if ($flags & 2048) { - $buffer->appendUint8($priority); + if($flags & 2048) + { + $buffer->appendUint8((int) $priority); } - if ($flags & 1024) { + if($flags & 1024) + { $buffer->appendString($correlationId); } - if ($flags & 512) { + if($flags & 512) + { $buffer->appendString($replyTo); } - if ($flags & 256) { + if($flags & 256) + { $buffer->appendString($expiration); } - if ($flags & 128) { + if($flags & 128) + { $buffer->appendString($messageId); } - if ($flags & 64) { - $buffer->appendTimestamp($timestamp); + if($flags & 64 && $timestamp !== null) + { + $buffer->appendTimestamp(new \DateTimeImmutable(\sprintf('@%s', $timestamp))); } - if ($flags & 32) { + if($flags & 32) + { $buffer->appendString($type); } - if ($flags & 16) { + if($flags & 16) + { $buffer->appendString($userId); } - if ($flags & 8) { + if($flags & 8) + { $buffer->appendString($appId); } - if ($flags & 4) { + if($flags & 4) + { $buffer->appendString($clusterId); } $buffer->appendUint8(206); - if (!empty($body)) { + if(!empty($body)) + { $chunks = \str_split($body, $this->properties->maxFrame()); - foreach ($chunks as $chunk) { - $buffer - ->appendUint8(3) - ->appendUint16($this->id) - ->appendUint32(\strlen($chunk)) - ->append($chunk) - ->appendUint8(206) - ; + if($chunks !== false) + { + foreach($chunks as $chunk) + { + $buffer + ->appendUint8(3) + ->appendUint16($this->id) + ->appendUint32(\strlen($chunk)) + ->append($chunk) + ->appendUint8(206); + } } } return $this->connection->write($buffer); } - + /** - * @param string $frame + * @template T + * @psalm-param class-string $frame + * @psalm-return Promise * * @return Promise */ private function await(string $frame): Promise { + /** @psalm-var Deferred $deferred */ $deferred = new Deferred; - $this->connection->subscribe($this->id, $frame, function (Protocol\AbstractFrame $frame) use ($deferred) { - $deferred->resolve($frame); + /** @psalm-var class-string $frame */ - return true; - }); + $this->connection->subscribe( + $this->id, + $frame, + static function(Protocol\AbstractFrame $frame) use ($deferred) + { + $deferred->resolve($frame); + + return true; + } + ); return $deferred->promise(); } diff --git a/src/Client.php b/src/Client.php index 63f7555..1d63099 100644 --- a/src/Client.php +++ b/src/Client.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; @@ -21,10 +21,9 @@ final class Client { private const STATE_NOT_CONNECTED = 0, - STATE_CONNECTING = 1, - STATE_CONNECTED = 2, - STATE_DISCONNECTING = 3 - ; + STATE_CONNECTING = 1, + STATE_CONNECTED = 2, + STATE_DISCONNECTING = 3; /** * @var Config @@ -56,30 +55,23 @@ final class Client */ private $properties; - /** - * @param Config $config - */ public function __construct(Config $config) { $this->config = $config; } - /** - * @param string $dsn - * - * @return self - */ public static function create(string $dsn): self { return new self(Config::parse($dsn)); } /** - * @return Properties + * @throws \PHPinnacle\Ridge\Exception\ClientException */ public function properties(): Properties { - if ($this->state !== self::STATE_CONNECTED) { + if($this->state !== self::STATE_CONNECTED) + { throw Exception\ClientException::notConnected(); } @@ -88,153 +80,172 @@ public function properties(): Properties /** * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ClientException */ public function connect(): Promise { - return call(function () { - if ($this->state !== self::STATE_NOT_CONNECTED) { - throw Exception\ClientException::alreadyConnected(); - } - - $this->state = self::STATE_CONNECTING; - - $this->connection = new Connection($this->config->uri()); - - $timeout = $this->config->timeout() * 1000; - - yield $this->connection->open( - $timeout, - $this->config->tcpAttempts(), - $this->config->tcpNoDelay() - ); + return call( + function() + { + if($this->state !== self::STATE_NOT_CONNECTED) + { + throw Exception\ClientException::alreadyConnected(); + } - $buffer = new Buffer; - $buffer - ->append('AMQP') - ->appendUint8(0) - ->appendUint8(0) - ->appendUint8(9) - ->appendUint8(1) - ; + $this->state = self::STATE_CONNECTING; - yield $this->connection->write($buffer); + $this->connection = new Connection($this->config->uri()); - yield $this->connectionStart(); - yield $this->connectionTune(); - yield $this->connectionOpen(); + $timeout = $this->config->timeout; - asyncCall(function () { - yield $this->await(Protocol\ConnectionCloseFrame::class); + yield $this->connection->open( + $timeout, + $this->config->tcpAttempts, + $this->config->tcpNoDelay + ); $buffer = new Buffer; $buffer - ->appendUint8(1) - ->appendUint16(0) - ->appendUint32(4) - ->appendUint16(10) - ->appendUint16(51) - ->appendUint8(206) - ; - - $this->connection->write($buffer); - $this->connection->close(); - }); + ->append('AMQP') + ->appendUint8(0) + ->appendUint8(0) + ->appendUint8(9) + ->appendUint8(1); + + yield $this->connection->write($buffer); + + yield $this->connectionStart(); + yield $this->connectionTune(); + yield $this->connectionOpen(); + + asyncCall(function() + { + yield $this->await(Protocol\ConnectionCloseFrame::class); + + $buffer = new Buffer; + $buffer + ->appendUint8(1) + ->appendUint16(0) + ->appendUint32(4) + ->appendUint16(10) + ->appendUint16(51) + ->appendUint8(206); + + $this->connection->write($buffer); + $this->connection->close(); + }); - $this->state = self::STATE_CONNECTED; - }); + $this->state = self::STATE_CONNECTED; + } + ); } /** - * @param int $code - * @param string $reason - * * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ClientException */ public function disconnect(int $code = 0, string $reason = ''): Promise { - return call(function() use ($code, $reason) { - if (\in_array($this->state, [self::STATE_NOT_CONNECTED, self::STATE_DISCONNECTING])) { - return; - } + return call( + function() use ($code, $reason) + { + if(\in_array($this->state, [self::STATE_NOT_CONNECTED, self::STATE_DISCONNECTING])) + { + return; + } - if ($this->state !== self::STATE_CONNECTED) { - throw Exception\ClientException::notConnected(); - } + if($this->state !== self::STATE_CONNECTED) + { + throw Exception\ClientException::notConnected(); + } - $this->state = self::STATE_DISCONNECTING; + $this->state = self::STATE_DISCONNECTING; - if ($code === 0) { - $promises = []; + if($code === 0) + { + $promises = []; - foreach($this->channels as $id => $channel) { - $promises[] = $channel->close($code, $reason); - } + foreach($this->channels as $id => $channel) + { + $promises[] = $channel->close($code, $reason); + } - yield $promises; - } + yield $promises; + } - yield $this->connectionClose($code, $reason); + yield $this->connectionClose($code, $reason); - $this->connection->close(); + $this->connection->close(); - $this->state = self::STATE_NOT_CONNECTED; - }); + $this->state = self::STATE_NOT_CONNECTED; + } + ); } /** * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ClientException */ public function channel(): Promise { - return call(function() { - if ($this->state !== self::STATE_CONNECTED) { - throw Exception\ClientException::notConnected(); - } + return call( + function() + { + if($this->state !== self::STATE_CONNECTED) + { + throw Exception\ClientException::notConnected(); + } - try { - $id = $this->findChannelId(); - $channel = new Channel($id, $this->connection, $this->properties); + try + { + $id = $this->findChannelId(); + $channel = new Channel($id, $this->connection, $this->properties); - $this->channels[$id] = $channel; + $this->channels[$id] = $channel; - yield $channel->open(); - yield $channel->qos($this->config->qosSize(), $this->config->qosCount(), $this->config->qosGlobal()); + yield $channel->open(); + yield $channel->qos($this->config->qosSize, $this->config->qosCount, $this->config->qosGlobal); - asyncCall(function () use ($id) { - $frame = yield Promise\first([ - $this->await(Protocol\ChannelCloseFrame::class, $id), - $this->await(Protocol\ChannelCloseOkFrame::class, $id) - ]); + asyncCall(function() use ($id) + { + /** @var Protocol\ChannelCloseFrame|Protocol\ChannelCloseOkFrame $frame */ + $frame = yield Promise\first([ + $this->await(Protocol\ChannelCloseFrame::class, $id), + $this->await(Protocol\ChannelCloseOkFrame::class, $id) + ]); - $this->connection->cancel($id); + $this->connection->cancel($id); - if ($frame instanceof Protocol\ChannelCloseFrame) { - $buffer = new Buffer; - $buffer - ->appendUint8(1) - ->appendUint16($id) - ->appendUint32(4) - ->appendUint16(20) - ->appendUint16(41) - ->appendUint8(206) - ; + if($frame instanceof Protocol\ChannelCloseFrame) + { + $buffer = new Buffer; + $buffer + ->appendUint8(1) + ->appendUint16($id) + ->appendUint32(4) + ->appendUint16(20) + ->appendUint16(41) + ->appendUint8(206); - yield $this->connection->write($buffer); - } + yield $this->connection->write($buffer); + } - unset($this->channels[$id]); - }); + unset($this->channels[$id]); + }); - return $channel; - } catch (\Throwable $error) { - throw Exception\ClientException::unexpectedResponse($error); + return $channel; + } + catch(\Throwable $error) + { + throw Exception\ClientException::unexpectedResponse($error); + } } - }); + ); } - /** - * @return bool - */ public function isConnected(): bool { return $this->state === self::STATE_CONNECTED; @@ -242,40 +253,44 @@ public function isConnected(): bool /** * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ClientException */ private function connectionStart(): Promise { - return call(function () { - /** @var Protocol\ConnectionStartFrame $start */ - $start = yield $this->await(Protocol\ConnectionStartFrame::class); + return call( + function() + { + /** @var Protocol\ConnectionStartFrame $start */ + $start = yield $this->await(Protocol\ConnectionStartFrame::class); + + if(!\str_contains($start->mechanisms, 'AMQPLAIN')) + { + throw Exception\ClientException::notSupported($start->mechanisms); + } - if (\strpos($start->mechanisms, "AMQPLAIN") === false) { - throw Exception\ClientException::notSupported($start->mechanisms); - } + $this->properties = Properties::create($start->serverProperties); + + $buffer = new Buffer; + $buffer + ->appendTable([ + 'LOGIN' => $this->config->user, + 'PASSWORD' => $this->config->pass, + ]) + ->discard(4); + + $frameBuffer = new Buffer; + $frameBuffer + ->appendUint16(10) + ->appendUint16(11) + ->appendTable([]) + ->appendString('AMQPLAIN') + ->appendText((string) $buffer) + ->appendString('en_US'); - $this->properties = Properties::create($start->serverProperties); - - $buffer = new Buffer; - $buffer - ->appendTable([ - "LOGIN" => $this->config->user(), - "PASSWORD" => $this->config->password(), - ]) - ->discard(4) - ; - - $frameBuffer = new Buffer; - $frameBuffer - ->appendUint16(10) - ->appendUint16(11) - ->appendTable([]) - ->appendString("AMQPLAIN") - ->appendText((string) $buffer) - ->appendString("en_US") - ; - - return $this->connection->method(0, $frameBuffer); - }); + return $this->connection->method(0, $frameBuffer); + } + ); } /** @@ -283,39 +298,44 @@ private function connectionStart(): Promise */ private function connectionTune(): Promise { - return call(function () { - /** @var Protocol\ConnectionTuneFrame $tune */ - $tune = yield $this->await(Protocol\ConnectionTuneFrame::class); + return call( + function() + { + /** @var Protocol\ConnectionTuneFrame $tune */ + $tune = yield $this->await(Protocol\ConnectionTuneFrame::class); - $heartbeat = $this->config->heartbeat(); + $heartbeat = $this->config->heartbeat; - if ($heartbeat !== 0) { - $heartbeat = \min($heartbeat, $tune->heartbeat); - } + if($heartbeat !== 0) + { + $heartbeat = \min($heartbeat, $tune->heartbeat); + } - $maxChannel = \min($this->config->maxChannel(), $tune->channelMax); - $maxFrame = \min($this->config->maxFrame(), $tune->frameMax); + $maxChannel = \min($this->config->maxChannel, $tune->channelMax); + $maxFrame = \min($this->config->maxFrame, $tune->frameMax); - $buffer = new Buffer; - $buffer - ->appendUint8(1) - ->appendUint16(0) - ->appendUint32(12) - ->appendUint16(10) - ->appendUint16(31) - ->appendInt16($maxChannel) - ->appendInt32($maxFrame) - ->appendInt16($heartbeat) - ->appendUint8(206); + $buffer = new Buffer; + $buffer + ->appendUint8(1) + ->appendUint16(0) + ->appendUint32(12) + ->appendUint16(10) + ->appendUint16(31) + ->appendInt16($maxChannel) + ->appendInt32($maxFrame) + ->appendInt16($heartbeat) + ->appendUint8(206); - yield $this->connection->write($buffer); + yield $this->connection->write($buffer); - $this->properties->tune($maxChannel, $maxFrame); + $this->properties->tune($maxChannel, $maxFrame); - if ($heartbeat > 0) { - $this->connection->heartbeat($heartbeat); + if($heartbeat > 0) + { + $this->connection->heartbeat($heartbeat); + } } - }); + ); } /** @@ -323,57 +343,58 @@ private function connectionTune(): Promise */ private function connectionOpen(): Promise { - return call(function () { - $vhost = $this->config->vhost(); - $capabilities = ''; - $insist = false; - - $buffer = new Buffer; - $buffer - ->appendUint8(1) - ->appendUint16(0) - ->appendUint32(7 + \strlen($vhost) + \strlen($capabilities)) - ->appendUint16(10) - ->appendUint16(40) - ->appendString($vhost) - ->appendString($capabilities) // TODO: process server capabilities - ->appendBits([$insist]) - ->appendUint8(206) - ; - - yield $this->connection->write($buffer); - - return $this->await(Protocol\ConnectionOpenOkFrame::class); - }); + return call( + function() + { + $vhost = $this->config->vhost; + $capabilities = ''; + $insist = false; + + $buffer = new Buffer; + $buffer + ->appendUint8(1) + ->appendUint16(0) + ->appendUint32(7 + \strlen($vhost) + \strlen($capabilities)) + ->appendUint16(10) + ->appendUint16(40) + ->appendString($vhost) + ->appendString($capabilities) // TODO: process server capabilities + ->appendBits([$insist]) + ->appendUint8(206); + + yield $this->connection->write($buffer); + + return $this->await(Protocol\ConnectionOpenOkFrame::class); + } + ); } /** - * @param int $code - * @param string $reason - * * @return Promise */ private function connectionClose(int $code, string $reason): Promise { - return call(function () use ($code, $reason) { - $buffer = new Buffer; - $buffer - ->appendUint8(1) - ->appendUint16(0) - ->appendUint32(11 + \strlen($reason)) - ->appendUint16(10) - ->appendUint16(50) - ->appendInt16($code) - ->appendString($reason) - ->appendInt16(0) - ->appendInt16(0) - ->appendUint8(206) - ; - - yield $this->connection->write($buffer); - - return $this->await(Protocol\ConnectionCloseOkFrame::class); - }); + return call( + function() use ($code, $reason) + { + $buffer = new Buffer; + $buffer + ->appendUint8(1) + ->appendUint16(0) + ->appendUint32(11 + \strlen($reason)) + ->appendUint16(10) + ->appendUint16(50) + ->appendInt16($code) + ->appendString($reason) + ->appendInt16(0) + ->appendInt16(0) + ->appendUint8(206); + + yield $this->connection->write($buffer); + + return $this->await(Protocol\ConnectionCloseOkFrame::class); + } + ); } /** @@ -381,18 +402,22 @@ private function connectionClose(int $code, string $reason): Promise */ private function findChannelId(): int { - // first check in range [next, max] ... - for ($id = $this->nextChannelId; $id <= $this->config->maxChannel(); ++$id) { - if (!isset($this->channels[$id])) { + /** first check in range [next, max] ... */ + for($id = $this->nextChannelId; $id <= $this->config->maxChannel; ++$id) + { + if(!isset($this->channels[$id])) + { $this->nextChannelId = $id + 1; return $id; } } - // then check in range [min, next) ... - for ($id = 1; $id < $this->nextChannelId; ++$id) { - if (!isset($this->channels[$id])) { + /** then check in range [min, next) ... */ + for($id = 1; $id < $this->nextChannelId; ++$id) + { + if(!isset($this->channels[$id])) + { $this->nextChannelId = $id + 1; return $id; @@ -403,20 +428,27 @@ private function findChannelId(): int } /** - * @param string $frame - * @param int $channel - * - * @return Promise + * @template T + * @psalm-param class-string $frame + * @psalm-return Promise */ private function await(string $frame, int $channel = 0): Promise { + /** @psalm-var Deferred $deferred */ $deferred = new Deferred; - $this->connection->subscribe($channel, $frame, function (Protocol\AbstractFrame $frame) use ($deferred) { - $deferred->resolve($frame); + /** @psalm-var class-string $frame */ - return true; - }); + $this->connection->subscribe( + $channel, + $frame, + static function(Protocol\AbstractFrame $frame) use ($deferred) + { + $deferred->resolve($frame); + + return true; + } + ); return $deferred->promise(); } diff --git a/src/Config.php b/src/Config.php index 65c66db..877b801 100644 --- a/src/Config.php +++ b/src/Config.php @@ -8,116 +8,102 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; +use PHPinnacle\Ridge\Exception\ConfigurationException; + final class Config { - private const - DEFAULT_HOST = 'localhost', - DEFAULT_PORT = 5672, - DEFAULT_VHOST = '/', - DEFAULT_USER = 'guest', - DEFAULT_PASS = 'guest' - ; - - private const OPTIONS = [ - 'timeout' => 1000, - 'heartbeat' => 1000, - 'qos_count' => 0, - 'qos_size' => 0, - 'qos_global' => false, - 'tcp_nodelay' => false, - 'tcp_attempts' => 2, - 'max_frame' => 0xFFFF, - 'max_channel' => 0xFFFF, - ]; + private const DEFAULT_HOST = 'localhost'; + private const DEFAULT_PORT = 5672; + private const DEFAULT_VHOST = '/'; + private const DEFAULT_USER = 'guest'; + private const DEFAULT_PASS = 'guest'; /** * @var string */ - private $host; + public $host; /** * @var int */ - private $port; + public $port; /** * @var string */ - private $user; + public $user; /** * @var string */ - private $pass; + public $pass; /** * @var string */ - private $vhost; + public $vhost; /** + * Connection timeout (in milliseconds) + * * @var int */ - private $timeout = 1; + public $timeout = 1000; /** + * Heartbeat interval (in milliseconds) + * * @var int */ - private $heartbeat = 60; + public $heartbeat = 60000; /** * @var int */ - private $qosSize = 0; + public $qosSize = 0; /** * @var int */ - private $qosCount = 0; + public $qosCount = 0; /** * @var bool */ - private $qosGlobal = false; + public $qosGlobal = false; /** * @var bool */ - private $tcpNoDelay = false; + public $tcpNoDelay = false; /** * @var int */ - private $tcpAttempts = 2; + public $tcpAttempts = 2; /** * @var int */ - private $maxChannel = 0xFFFF; + public $maxChannel = 0xFFFF; /** * @var int */ - private $maxFrame = 0xFFFF; + public $maxFrame = 0xFFFF; - /** - * @param string $host - * @param int $port - * @param string $user - * @param string $pass - * @param string $vhost - */ public function __construct( string $host = self::DEFAULT_HOST, int $port = self::DEFAULT_PORT, string $user = self::DEFAULT_USER, string $pass = self::DEFAULT_PASS, string $vhost = null - ) { + ) + { $this->host = $host; $this->port = $port; $this->user = $user; @@ -126,20 +112,33 @@ public function __construct( } /** - * @param string $dsn - * - * @return self + * @throws \PHPinnacle\Ridge\Exception\ConfigurationException */ public static function parse(string $dsn): self { + if($dsn === '') + { + throw ConfigurationException::emptyDSN(); + } + $parts = \parse_url($dsn); - \parse_str($parts['query'] ?? '', $query); + if($parts === false) + { + throw ConfigurationException::incorrectDSN($dsn); + } + + \parse_str($parts['query'] ?? '', $options); - $options = \array_replace(self::OPTIONS, $query); + if(isset($parts['path']) && $parts['path'] !== '') + { + /** @var string|false $vhost */ + $vhost = \substr($parts['path'], 1); - if (!empty($parts['path'])) { - $parts['path'] = \substr($parts['path'], 1); + if($vhost !== false) + { + $parts['path'] = $vhost; + } } $self = new self( @@ -147,160 +146,59 @@ public static function parse(string $dsn): self $parts['port'] ?? self::DEFAULT_PORT, $parts['user'] ?? self::DEFAULT_USER, $parts['pass'] ?? self::DEFAULT_PASS, - $parts['path'] ?? self::DEFAULT_VHOST + $parts['path'] ?? self::DEFAULT_VHOST, ); - $self->timeout = \filter_var($options['timeout'], FILTER_VALIDATE_INT); - $self->heartbeat = \filter_var($options['heartbeat'], FILTER_VALIDATE_INT); - - $self->maxFrame = \filter_var($options['max_frame'], FILTER_VALIDATE_INT); - $self->maxChannel = \filter_var($options['max_channel'], FILTER_VALIDATE_INT); - - $self->qosSize = \filter_var($options['qos_size'], FILTER_VALIDATE_INT); - $self->qosCount = \filter_var($options['qos_count'], FILTER_VALIDATE_INT); - $self->qosGlobal = \filter_var($options['qos_global'], FILTER_VALIDATE_BOOLEAN); - - $self->tcpNoDelay = \filter_var($options['tcp_nodelay'], FILTER_VALIDATE_BOOLEAN); - $self->tcpAttempts = \filter_var($options['tcp_attempts'], FILTER_VALIDATE_INT); - - return $self; - } - - /** - * @return string - */ - public function uri(): string - { - return \sprintf('tcp://%s:%d', $this->host, $this->port); - } - - /** - * @return string - */ - public function host(): string - { - return $this->host; - } - - /** - * @return int - */ - public function port(): int - { - return $this->port; - } - - /** - * @return string - */ - public function vhost(): string - { - return $this->vhost; - } - - /** - * @return string - */ - public function user(): string - { - return $this->user; - } + if(isset($options['timeout'])) + { + $self->timeout = (int) $options['timeout']; + } - /** - * @return string - */ - public function password(): string - { - return $this->pass; - } + if(isset($options['heartbeat'])) + { + $self->heartbeat = (int) $options['heartbeat']; + } - /** - * @param int|null $value - * - * @return int - */ - public function timeout(int $value = null): int - { - return \is_null($value) ? $this->timeout : $this->timeout = $value; - } + if(isset($options['max_frame'])) + { + $self->maxFrame = (int) $options['max_frame']; + } - /** - * @param int|null $value - * - * @return int - */ - public function heartbeat(int $value = null): int - { - return \is_null($value) ? $this->heartbeat : $this->heartbeat = $value; - } + if(isset($options['max_channel'])) + { + $self->maxChannel = (int) $options['max_channel']; + } - /** - * @param int|null $value - * - * @return int - */ - public function qosSize(int $value = null): int - { - return \is_null($value) ? $this->qosSize : $this->qosSize = $value; - } + if(isset($options['qos_size'])) + { + $self->qosSize = (int) $options['qos_size']; + } - /** - * @param int|null $value - * - * @return int - */ - public function qosCount(int $value = null): int - { - return \is_null($value) ? $this->qosCount : $this->qosCount = $value; - } + if(isset($options['qos_count'])) + { + $self->qosCount = (int) $options['qos_count']; + } - /** - * @param bool|null $value - * - * @return bool - */ - public function qosGlobal(bool $value = null): bool - { - return \is_null($value) ? $this->qosGlobal : $this->qosGlobal = $value; - } + if(isset($options['qos_global'])) + { + $self->qosGlobal = (bool) $options['qos_global']; + } - /** - * @param bool|null $value - * - * @return bool - */ - public function tcpNoDelay(bool $value = null): bool - { - return \is_null($value) ? $this->tcpNoDelay : $this->tcpNoDelay = $value; - } + if(isset($options['tcp_nodelay'])) + { + $self->tcpNoDelay = (bool) $options['tcp_nodelay']; + } - /** - * @param int|null $value - * - * @return int - */ - public function tcpAttempts(int $value = null): int - { - return \is_null($value) ? $this->tcpAttempts : $this->tcpAttempts = $value; - } + if(isset($options['tcp_attempts'])) + { + $self->tcpAttempts = (int) $options['tcp_attempts']; + } - /** - * @param int|null $value - * - * @return int - */ - public function maxChannel(int $value = null): int - { - return \is_null($value) ? $this->maxChannel : $this->maxChannel = $value; + return $self; } - /** - * @param int|null $value - * - * @return int - */ - public function maxFrame(int $value = null): int + public function uri(): string { - return \is_null($value) ? $this->maxFrame : $this->maxFrame = $value; + return \sprintf('tcp://%s:%d', $this->host, $this->port); } } diff --git a/src/Connection.php b/src/Connection.php index f225287..ae26edc 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -8,16 +8,17 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; +use PHPinnacle\Ridge\Exception\ConnectionException; use function Amp\asyncCall, Amp\call, Amp\Socket\connect; use Amp\Socket\ConnectContext; -use Amp\Deferred; use Amp\Loop; use Amp\Promise; use Amp\Socket\Socket; +use PHPinnacle\Ridge\Protocol\AbstractFrame; final class Connection { @@ -37,7 +38,8 @@ final class Connection private $socket; /** - * @var Deferred[][][] + * @var callable[][][] + * @psalm-var array, array>> */ private $callbacks = []; @@ -47,13 +49,10 @@ final class Connection private $lastWrite = 0; /** - * @var string + * @var string|null */ - private $heartbeat; + private $heartbeatWatcherId; - /** - * @param string $uri - */ public function __construct(string $uri) { $this->uri = $uri; @@ -61,25 +60,29 @@ public function __construct(string $uri) } /** - * @noinspection PhpDocMissingThrowsInspection - * - * @param Buffer $payload - * - * @return Promise + * @throws \PHPinnacle\Ridge\Exception\ConnectionException */ public function write(Buffer $payload): Promise { $this->lastWrite = Loop::now(); - /** @noinspection PhpUnhandledExceptionInspection */ - return $this->socket->write($payload->flush()); + if($this->socket !== null) + { + try + { + return $this->socket->write($payload->flush()); + } + catch(\Throwable $throwable) + { + throw ConnectionException::writeFailed($throwable); + } + } + + throw ConnectionException::socketClosed(); } /** - * @param int $channel - * @param Buffer $payload - * - * @return Promise + * @throws \PHPinnacle\Ridge\Exception\ConnectionException */ public function method(int $channel, Buffer $payload): Promise { @@ -93,119 +96,136 @@ public function method(int $channel, Buffer $payload): Promise } /** - * @param int $channel - * @param string $frame - * @param callable $callback + * @psalm-param class-string $frame */ public function subscribe(int $channel, string $frame, callable $callback): void { $this->callbacks[$channel][$frame][] = $callback; } - /** - * @param int $channel - * - * @return void - */ public function cancel(int $channel): void { unset($this->callbacks[$channel]); } /** - * @param int $timeout - * @param int $maxAttempts - * @param bool $noDelay - * - * @return Promise + * @throws \PHPinnacle\Ridge\Exception\ConnectionException */ public function open(int $timeout, int $maxAttempts, bool $noDelay): Promise { - return call(function () use ($timeout, $maxAttempts, $noDelay) { - $context = new ConnectContext(); - - if ($maxAttempts > 0) { - $context = $context->withMaxAttempts($maxAttempts); - } - - if ($timeout > 0) { - $context = $context->withConnectTimeout($timeout); - } + return call( + function() use ($timeout, $maxAttempts, $noDelay) + { + $context = new ConnectContext(); + + if($maxAttempts > 0) + { + $context = $context->withMaxAttempts($maxAttempts); + } - if ($noDelay) { - $context = $context->withTcpNoDelay(); - } + if($timeout > 0) + { + $context = $context->withConnectTimeout($timeout); + } - $this->socket = yield connect($this->uri, $context); + if($noDelay) + { + $context = $context->withTcpNoDelay(); + } - asyncCall(function () { - while (null !== $chunk = yield $this->socket->read()) { - $this->parser->append($chunk); + $this->socket = yield connect($this->uri, $context); - while ($frame = $this->parser->parse()) { - $class = \get_class($frame); + asyncCall( + function() + { + if($this->socket === null) + { + throw ConnectionException::socketClosed(); + } - foreach ($this->callbacks[$frame->channel][$class] ?? [] as $i => $callback) { - if (yield call($callback, $frame)) { - unset($this->callbacks[$frame->channel][$class][$i]); + while(null !== $chunk = yield $this->socket->read()) + { + $this->parser->append($chunk); + + while($frame = $this->parser->parse()) + { + /** @var AbstractFrame $frame */ + + $class = \get_class($frame); + + /** + * @psalm-var int $i + * @psalm-var callable(AbstractFrame):Promise $callback + */ + foreach($this->callbacks[(int) $frame->channel][$class] ?? [] as $i => $callback) + { + $result = yield call($callback, $frame); + + if($result) + { + unset($this->callbacks[(int) $frame->channel][$class][$i]); + } + } } } - } - } - $this->socket = null; - }); - }); + $this->socket = null; + } + ); + } + ); } - /** - * @param int $interval - * - * @return void - */ public function heartbeat(int $interval): void { $milliseconds = $interval * 1000; - $this->heartbeat = Loop::repeat($milliseconds, function($watcher) use ($milliseconds) { - if (null === $this->socket) { - Loop::cancel($watcher); + $this->heartbeatWatcherId = Loop::repeat( + $milliseconds, + function(string $watcherId) use ($milliseconds) + { + if($this->socket === null) + { + Loop::cancel($watcherId); - return; - } + return; + } - $currentTime = Loop::now(); - $lastWrite = $this->lastWrite ?: $currentTime; + $currentTime = Loop::now(); + $lastWrite = $this->lastWrite ?: $currentTime; - /** @var int $nextHeartbeat */ - $nextHeartbeat = $lastWrite + $milliseconds; + /** @var int $nextHeartbeat */ + $nextHeartbeat = $lastWrite + $milliseconds; - if ($currentTime >= $nextHeartbeat) { - yield $this->write((new Buffer) - ->appendUint8(8) - ->appendUint16(0) - ->appendUint32(0) - ->appendUint8(206) - ); - } + if($currentTime >= $nextHeartbeat) + { + yield $this->write((new Buffer) + ->appendUint8(8) + ->appendUint16(0) + ->appendUint32(0) + ->appendUint8(206) + ); + } - unset($currentTime, $lastWrite, $nextHeartbeat); - }); + unset($currentTime, $lastWrite, $nextHeartbeat); + } + ); } - /** - * @return void - */ public function close(): void { $this->callbacks = []; - if ($this->heartbeat !== null) { - Loop::cancel($this->heartbeat); + if($this->heartbeatWatcherId !== null) + { + Loop::cancel($this->heartbeatWatcherId); - $this->heartbeat = null; + $this->heartbeatWatcherId = null; } - $this->socket->close(); + if($this->socket !== null) + { + $this->socket->close(); + } } } diff --git a/src/Constants.php b/src/Constants.php index c6fd638..965ea88 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -8,162 +8,138 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; final class Constants { - const CONNECTION_CHANNEL = 0; + public const CONNECTION_CHANNEL = 0; - const - FRAME_METHOD = 1, - FRAME_HEADER = 2, - FRAME_BODY = 3, - FRAME_HEARTBEAT = 8, - FRAME_MIN_SIZE = 4096, - FRAME_END = 0xCE - ; + public const FRAME_METHOD = 1; + public const FRAME_HEADER = 2; + public const FRAME_BODY = 3; + public const FRAME_HEARTBEAT = 8; + public const FRAME_MIN_SIZE = 4096; + public const FRAME_END = 0xCE; - const - STATUS_REPLY_SUCCESS = 200, - STATUS_CONTENT_TOO_LARGE = 311, - STATUS_NO_ROUTE = 312, - STATUS_NO_CONSUMERS = 313, - STATUS_CONNECTION_FORCED = 320, - STATUS_INVALID_PATH = 402, - STATUS_ACCESS_REFUSED = 403, - STATUS_NOT_FOUND = 404, - STATUS_RESOURCE_LOCKED = 405, - STATUS_PRECONDITION_FAILED = 406, - STATUS_FRAME_ERROR = 501, - STATUS_SYNTAX_ERROR = 502, - STATUS_COMMAND_INVALID = 503, - STATUS_CHANNEL_ERROR = 504, - STATUS_UNEXPECTED_FRAME = 505, - STATUS_RESOURCE_ERROR = 506, - STATUS_NOT_ALLOWED = 530, - STATUS_NOT_IMPLEMENTED = 540, - STATUS_INTERNAL_ERROR = 541 - ; + public const STATUS_REPLY_SUCCESS = 200; + public const STATUS_CONTENT_TOO_LARGE = 311; + public const STATUS_NO_ROUTE = 312; + public const STATUS_NO_CONSUMERS = 313; + public const STATUS_CONNECTION_FORCED = 320; + public const STATUS_INVALID_PATH = 402; + public const STATUS_ACCESS_REFUSED = 403; + public const STATUS_NOT_FOUND = 404; + public const STATUS_RESOURCE_LOCKED = 405; + public const STATUS_PRECONDITION_FAILED = 406; + public const STATUS_FRAME_ERROR = 501; + public const STATUS_SYNTAX_ERROR = 502; + public const STATUS_COMMAND_INVALID = 503; + public const STATUS_CHANNEL_ERROR = 504; + public const STATUS_UNEXPECTED_FRAME = 505; + public const STATUS_RESOURCE_ERROR = 506; + public const STATUS_NOT_ALLOWED = 530; + public const STATUS_NOT_IMPLEMENTED = 540; + public const STATUS_INTERNAL_ERROR = 541; - const - CLASS_CONNECTION = 10, - CLASS_CHANNEL = 20, - CLASS_ACCESS = 30, - CLASS_EXCHANGE = 40, - CLASS_QUEUE = 50, - CLASS_BASIC = 60, - CLASS_TX = 90, - CLASS_CONFIRM = 85 // RabbitMQ extension - ; + public const CLASS_CONNECTION = 10; + public const CLASS_CHANNEL = 20; + public const CLASS_ACCESS = 30; + public const CLASS_EXCHANGE = 40; + public const CLASS_QUEUE = 50; + public const CLASS_BASIC = 60; + public const CLASS_TX = 90; + public const CLASS_CONFIRM = 85; - const - METHOD_CONNECTION_START = 10, - METHOD_CONNECTION_START_OK = 11, - METHOD_CONNECTION_SECURE = 20, - METHOD_CONNECTION_SECURE_OK = 21, - METHOD_CONNECTION_TUNE = 30, - METHOD_CONNECTION_TUNE_OK = 31, - METHOD_CONNECTION_OPEN = 40, - METHOD_CONNECTION_OPEN_OK = 41, - METHOD_CONNECTION_CLOSE = 50, - METHOD_CONNECTION_CLOSE_OK = 51, - METHOD_CONNECTION_BLOCKED = 60, // RabbitMQ extension - METHOD_CONNECTION_UNBLOCKED = 61 // RabbitMQ extension - ; + public const METHOD_CONNECTION_START = 10; + public const METHOD_CONNECTION_START_OK = 11; + public const METHOD_CONNECTION_SECURE = 20; + public const METHOD_CONNECTION_SECURE_OK = 21; + public const METHOD_CONNECTION_TUNE = 30; + public const METHOD_CONNECTION_TUNE_OK = 31; + public const METHOD_CONNECTION_OPEN = 40; + public const METHOD_CONNECTION_OPEN_OK = 41; + public const METHOD_CONNECTION_CLOSE = 50; + public const METHOD_CONNECTION_CLOSE_OK = 51; + public const METHOD_CONNECTION_BLOCKED = 60; + public const METHOD_CONNECTION_UNBLOCKED = 61; - const - METHOD_CHANNEL_OPEN = 10, - METHOD_CHANNEL_OPEN_OK = 11, - METHOD_CHANNEL_FLOW = 20, - METHOD_CHANNEL_FLOW_OK = 21, - METHOD_CHANNEL_CLOSE = 40, - METHOD_CHANNEL_CLOSE_OK = 41 - ; + public const METHOD_CHANNEL_OPEN = 10; + public const METHOD_CHANNEL_OPEN_OK = 11; + public const METHOD_CHANNEL_FLOW = 20; + public const METHOD_CHANNEL_FLOW_OK = 21; + public const METHOD_CHANNEL_CLOSE = 40; + public const METHOD_CHANNEL_CLOSE_OK = 41; - const - METHOD_ACCESS_REQUEST = 10, - METHOD_ACCESS_REQUEST_OK = 11 - ; + public const METHOD_ACCESS_REQUEST = 10; + public const METHOD_ACCESS_REQUEST_OK = 11; - const - METHOD_EXCHANGE_DECLARE = 10, - METHOD_EXCHANGE_DECLARE_OK = 11, - METHOD_EXCHANGE_DELETE = 20, - METHOD_EXCHANGE_DELETE_OK = 21, - METHOD_EXCHANGE_BIND = 30, // RabbitMQ extension - METHOD_EXCHANGE_BIND_OK = 31, // RabbitMQ extension - METHOD_EXCHANGE_UNBIND = 40, // RabbitMQ extension - METHOD_EXCHANGE_UNBIND_OK = 51 // RabbitMQ extension - ; + public const METHOD_EXCHANGE_DECLARE = 10; + public const METHOD_EXCHANGE_DECLARE_OK = 11; + public const METHOD_EXCHANGE_DELETE = 20; + public const METHOD_EXCHANGE_DELETE_OK = 21; + public const METHOD_EXCHANGE_BIND = 30; + public const METHOD_EXCHANGE_BIND_OK = 31; + public const METHOD_EXCHANGE_UNBIND = 40; + public const METHOD_EXCHANGE_UNBIND_OK = 51; - const - METHOD_QUEUE_DECLARE = 10, - METHOD_QUEUE_DECLARE_OK = 11, - METHOD_QUEUE_BIND = 20, - METHOD_QUEUE_BIND_OK = 21, - METHOD_QUEUE_PURGE = 30, - METHOD_QUEUE_PURGE_OK = 31, - METHOD_QUEUE_DELETE = 40, - METHOD_QUEUE_DELETE_OK = 41, - METHOD_QUEUE_UNBIND = 50, - METHOD_QUEUE_UNBIND_OK = 51 - ; + public const METHOD_QUEUE_DECLARE = 10; + public const METHOD_QUEUE_DECLARE_OK = 11; + public const METHOD_QUEUE_BIND = 20; + public const METHOD_QUEUE_BIND_OK = 21; + public const METHOD_QUEUE_PURGE = 30; + public const METHOD_QUEUE_PURGE_OK = 31; + public const METHOD_QUEUE_DELETE = 40; + public const METHOD_QUEUE_DELETE_OK = 41; + public const METHOD_QUEUE_UNBIND = 50; + public const METHOD_QUEUE_UNBIND_OK = 51; - const - METHOD_BASIC_QOS = 10, - METHOD_BASIC_QOS_OK = 11, - METHOD_BASIC_CONSUME = 20, - METHOD_BASIC_CONSUME_OK = 21, - METHOD_BASIC_CANCEL = 30, - METHOD_BASIC_CANCEL_OK = 31, - METHOD_BASIC_PUBLISH = 40, - METHOD_BASIC_RETURN = 50, - METHOD_BASIC_DELIVER = 60, - METHOD_BASIC_GET = 70, - METHOD_BASIC_GET_OK = 71, - METHOD_BASIC_GET_EMPTY = 72, - METHOD_BASIC_ACK = 80, - METHOD_BASIC_REJECT = 90, - METHOD_BASIC_RECOVER_ASYNC = 100, - METHOD_BASIC_RECOVER = 110, - METHOD_BASIC_RECOVER_OK = 111, - METHOD_BASIC_NACK = 120 // RabbitMQ extension - ; + public const METHOD_BASIC_QOS = 10; + public const METHOD_BASIC_QOS_OK = 11; + public const METHOD_BASIC_CONSUME = 20; + public const METHOD_BASIC_CONSUME_OK = 21; + public const METHOD_BASIC_CANCEL = 30; + public const METHOD_BASIC_CANCEL_OK = 31; + public const METHOD_BASIC_PUBLISH = 40; + public const METHOD_BASIC_RETURN = 50; + public const METHOD_BASIC_DELIVER = 60; + public const METHOD_BASIC_GET = 70; + public const METHOD_BASIC_GET_OK = 71; + public const METHOD_BASIC_GET_EMPTY = 72; + public const METHOD_BASIC_ACK = 80; + public const METHOD_BASIC_REJECT = 90; + public const METHOD_BASIC_RECOVER_ASYNC = 100; + public const METHOD_BASIC_RECOVER = 110; + public const METHOD_BASIC_RECOVER_OK = 111; + public const METHOD_BASIC_NACK = 120; - const - METHOD_TX_SELECT = 10, - METHOD_TX_SELECT_OK = 11, - METHOD_TX_COMMIT = 20, - METHOD_TX_COMMIT_OK = 21, - METHOD_TX_ROLLBACK = 30, - METHOD_TX_ROLLBACK_OK = 31 - ; + public const METHOD_TX_SELECT = 10; + public const METHOD_TX_SELECT_OK = 11; + public const METHOD_TX_COMMIT = 20; + public const METHOD_TX_COMMIT_OK = 21; + public const METHOD_TX_ROLLBACK = 30; + public const METHOD_TX_ROLLBACK_OK = 31; - const - METHOD_CONFIRM_SELECT = 10, // RabbitMQ extension - METHOD_CONFIRM_SELECT_OK = 11 // RabbitMQ extension - ; + public const METHOD_CONFIRM_SELECT = 10; + public const METHOD_CONFIRM_SELECT_OK = 11; - const - FIELD_BOOLEAN = 0x74, // 't' - FIELD_SHORT_SHORT_INT = 0x62, // 'b' - FIELD_SHORT_SHORT_UINT = 0x42, // 'B' - FIELD_SHORT_INT = 0x55, // 'U' - FIELD_SHORT_UINT = 0x75, // 'u' - FIELD_LONG_INT = 0x49, // 'I' - FIELD_LONG_UINT = 0x69, // 'i' - FIELD_LONG_LONG_INT = 0x4C, // 'L' - FIELD_LONG_LONG_UINT = 0x6C, // 'l' - FIELD_FLOAT = 0x66, // 'f' - FIELD_DOUBLE = 0x64, // 'd' - FIELD_DECIMAL = 0x44, // 'D' - FIELD_SHORT_STRING = 0x73, // 's' - FIELD_LONG_STRING = 0x53, // 'S' - FIELD_ARRAY = 0x41, // 'A' - FIELD_TIMESTAMP = 0x54, // 'T' - FIELD_TABLE = 0x46, // 'F' - FIELD_NULL = 0x56 // 'V' - ; + public const FIELD_BOOLEAN = 0x74; // 't' + public const FIELD_SHORT_SHORT_INT = 0x62; // 'b' + public const FIELD_SHORT_SHORT_UINT = 0x42; // 'B' + public const FIELD_SHORT_INT = 0x55; // 'U' + public const FIELD_SHORT_UINT = 0x75; // 'u' + public const FIELD_LONG_INT = 0x49; // 'I' + public const FIELD_LONG_UINT = 0x69; // 'i' + public const FIELD_LONG_LONG_INT = 0x4C; // 'L' + public const FIELD_LONG_LONG_UINT = 0x6C; // 'l' + public const FIELD_FLOAT = 0x66; // 'f' + public const FIELD_DOUBLE = 0x64; // 'd' + public const FIELD_DECIMAL = 0x44; // 'D' + public const FIELD_SHORT_STRING = 0x73; // 's' + public const FIELD_LONG_STRING = 0x53; // 'S' + public const FIELD_ARRAY = 0x41; // 'A' + public const FIELD_TIMESTAMP = 0x54; // 'T' + public const FIELD_TABLE = 0x46; // 'F' + public const FIELD_NULL = 0x56; // 'V' } diff --git a/src/Consumer.php b/src/Consumer.php index bea0468..5fac714 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; @@ -28,61 +28,47 @@ final class Consumer /** * @var callable[] + * @psalm-var array */ private $listeners = []; - /** - * @param Channel $channel - * @param MessageReceiver $receiver - */ public function __construct(Channel $channel, MessageReceiver $receiver) { $this->channel = $channel; $this->receiver = $receiver; } - /** - * @return void - */ public function start(): void { - $this->receiver->onMessage(function (Message $message) { - if (!$tag = $message->consumerTag()) { - return; - } + $this->receiver->onMessage( + function(Message $message) + { + if(!$tag = $message->consumerTag()) + { + return; + } - if (!isset($this->listeners[$tag])) { - return; - } + if(!isset($this->listeners[$tag])) + { + return; + } - asyncCall($this->listeners[$tag], $message, $this->channel); - }); + /** @psalm-suppress MixedArgumentTypeCoercion */ + asyncCall($this->listeners[$tag], $message, $this->channel); + } + ); } - /** - * @return void - */ public function stop(): void { $this->listeners = []; } - /** - * @param string $tag - * @param callable $listener - * - * @return void - */ public function subscribe(string $tag, callable $listener): void { $this->listeners[$tag] = $listener; } - /** - * @param string $tag - * - * @return void - */ public function cancel(string $tag): void { unset($this->listeners[$tag]); diff --git a/src/Events.php b/src/Events.php index d4f20e7..d0ee600 100644 --- a/src/Events.php +++ b/src/Events.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; @@ -26,21 +26,12 @@ final class Events */ private $receiver; - /** - * @param Channel $channel - * @param MessageReceiver $receiver - */ public function __construct(Channel $channel, MessageReceiver $receiver) { $this->channel = $channel; $this->receiver = $receiver; } - /** - * @param callable $listener - * - * @return self - */ public function onAck(callable $listener): self { $this->onFrame(Protocol\BasicAckFrame::class, $listener); @@ -48,11 +39,6 @@ public function onAck(callable $listener): self return $this; } - /** - * @param callable $listener - * - * @return self - */ public function onNack(callable $listener): self { $this->onFrame(Protocol\BasicNackFrame::class, $listener); @@ -60,34 +46,36 @@ public function onNack(callable $listener): self return $this; } - /** - * @param callable $listener - * - * @return self - */ public function onReturn(callable $listener): self { - $this->receiver->onMessage(function (Message $message) use ($listener) { - if (!$message->returned()) { - return; - } + $this->receiver->onMessage( + function(Message $message) use ($listener) + { + if(!$message->returned()) + { + return; + } - asyncCall($listener, $message, $this->channel); - }); + /** @psalm-suppress MixedArgumentTypeCoercion */ + asyncCall($listener, $message, $this->channel); + } + ); return $this; } /** - * @param string $frame - * @param callable $callback - * - * @return void + * @psalm-param class-string $frame */ private function onFrame(string $frame, callable $callback): void { - $this->receiver->onFrame($frame, function (Protocol\AcknowledgmentFrame $frame) use ($callback) { - asyncCall($callback, $frame->deliveryTag, $frame->multiple, $this->channel); - }); + $this->receiver->onFrame( + $frame, + function(Protocol\AcknowledgmentFrame $frame) use ($callback) + { + /** @psalm-suppress MixedArgumentTypeCoercion */ + asyncCall($callback, $frame->deliveryTag, $frame->multiple, $this->channel); + } + ); } } diff --git a/src/Exception/ChannelException.php b/src/Exception/ChannelException.php index 54ade30..74c3931 100644 --- a/src/Exception/ChannelException.php +++ b/src/Exception/ChannelException.php @@ -8,73 +8,46 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge\Exception; final class ChannelException extends RidgeException { - /** - * @param int $id - * - * @return self - */ public static function notReady(int $id): self { - return new self("Trying to open not ready channel #{$id}."); + return new self(\sprintf('Trying to open not ready channel #%d.', $id)); } - - /** - * @param int $id - * - * @return self - */ + public static function alreadyClosed(int $id): self { - return new self("Trying to close already closed channel #{$id}."); + return new self(\sprintf('Trying to close already closed channel #%d.', $id)); } - /** - * @param string $mode - * - * @return self - */ public static function notRegularFor(string $mode): self { - return new self("Channel not in regular mode, cannot change to {$mode} mode."); + return new self(\sprintf('Channel not in regular mode, cannot change to %s mode.', $mode)); } - - /** - * @return self - */ + public static function notTransactional(): self { - return new self("Channel not in transactional mode."); + return new self('Channel not in transactional mode.'); } - /** - * @return self - */ public static function getInProgress(): self { - return new self("Another 'basic.get' already in progress. You should use 'basic.consume' instead of multiple 'basic.get'."); + return new self( + 'Another `basic.get` already in progress. You should use `basic.consume` instead of multiple `basic.get`.' + ); } - /** - * @return self - */ public static function frameOrder(): self { - return new self("Consume frames order malformed."); + return new self('Consume frames order malformed.'); } - /** - * @param int $remaining - * - * @return self - */ public static function bodyOverflow(int $remaining): self { - return new self("Body overflow, received {$remaining} more bytes."); + return new self(\sprintf('Body overflow, received %d more bytes.', $remaining)); } } diff --git a/src/Exception/ClassInvalid.php b/src/Exception/ClassInvalid.php index 3556ce8..8024ffd 100644 --- a/src/Exception/ClassInvalid.php +++ b/src/Exception/ClassInvalid.php @@ -8,17 +8,14 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge\Exception; final class ClassInvalid extends ProtocolException { - /** - * @param int $classId - */ public function __construct(int $classId) { - parent::__construct("Unhandled method frame class '{$classId}'."); + parent::__construct(\sprintf('Unhandled method frame class `%d`.', $classId)); } } diff --git a/src/Exception/ClientException.php b/src/Exception/ClientException.php index 916d3fe..c422f23 100644 --- a/src/Exception/ClientException.php +++ b/src/Exception/ClientException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge\Exception; @@ -16,77 +16,43 @@ final class ClientException extends RidgeException { - /** - * @param \Throwable $error - * - * @return self - */ public static function unexpectedResponse(\Throwable $error): self { - return new self("Unexpected response.", $error->getCode(), $error); + return new self('Unexpected response.', (int) $error->getCode(), $error); } - /** - * @return self - */ public static function notConnected(): self { - return new self("Client is not connected to server."); + return new self('Client is not connected to server.'); } - /** - * @return self - */ public static function alreadyConnected(): self { - return new self("Client is already connected/connecting."); + return new self('Client is already connected/connecting.'); } - - /** - * @param string $available - * - * @return self - */ + public static function notSupported(string $available): self { - return new self("Server does not support AMQPLAIN mechanism (supported: {$available})."); + return new self(\sprintf('Server does not support AMQPLAIN mechanism (supported: %s).', $available)); } - - /** - * @return self - */ + public static function noChannelsAvailable(): self { - return new self("No available channels."); + return new self('No available channels.'); } - /** - * @param Protocol\ConnectionCloseFrame $frame - * - * @return self - */ public static function connectionClosed(Protocol\ConnectionCloseFrame $frame): self { - return new self("Connection closed by server: {$frame->replyText}.", $frame->replyCode); + return new self(\sprintf('Connection closed by server: %s.', $frame->replyText), $frame->replyCode); } - /** - * @param Protocol\AbstractFrame $frame - * - * @return self - */ public static function unknownFrameClass(Protocol\AbstractFrame $frame): self { - return new self("Unhandled frame '" . \get_class($frame) . "'."); + return new self(\sprintf('Unhandled frame `%s`.', \get_class($frame))); } - /** - * @param Protocol\AbstractFrame $frame - * - * @return self - */ public static function unknownMethodFrame(Protocol\AbstractFrame $frame): self { - return new self("Unhandled method frame '" . \get_class($frame) . "'."); + return new self(\sprintf('Unhandled method frame `%s`.', \get_class($frame))); } } diff --git a/src/Exception/ConfigurationException.php b/src/Exception/ConfigurationException.php new file mode 100644 index 0000000..36ee67f --- /dev/null +++ b/src/Exception/ConfigurationException.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types = 1); + +namespace PHPinnacle\Ridge\Exception; + +/** + * + */ +final class ConfigurationException extends RidgeException +{ + public static function emptyDSN(): self + { + return new self('Connection DSN can\'t be empty'); + } + + public static function incorrectDSN(string $dsn): self + { + return new self(\sprintf('Can\'t parse specified connection DSN (%s)', $dsn)); + } +} diff --git a/src/Exception/ConnectionException.php b/src/Exception/ConnectionException.php new file mode 100644 index 0000000..d036ed1 --- /dev/null +++ b/src/Exception/ConnectionException.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types = 1); + +namespace PHPinnacle\Ridge\Exception; + +/** + * + */ +final class ConnectionException extends RidgeException +{ + public static function writeFailed(\Throwable $previous): self + { + return new self( + \sprintf('Error writing to socket: %s', $previous->getMessage()), + (int) $previous->getCode(), + $previous + ); + } + + public static function socketClosed(): self + { + return new self('Attempting to write to a closed socket'); + } +} diff --git a/src/Exception/MethodInvalid.php b/src/Exception/MethodInvalid.php index 0231fed..4eaf265 100644 --- a/src/Exception/MethodInvalid.php +++ b/src/Exception/MethodInvalid.php @@ -8,18 +8,14 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge\Exception; final class MethodInvalid extends ProtocolException { - /** - * @param int $classId - * @param int $methodId - */ public function __construct(int $classId, int $methodId) { - parent::__construct("Unhandled method frame method '{$methodId}' in class '{$classId}'."); + parent::__construct(\sprintf('Unhandled method frame method `%d` in class `%d`.', $methodId, $classId)); } } diff --git a/src/Exception/ProtocolException.php b/src/Exception/ProtocolException.php index 44ffe51..cb4c584 100644 --- a/src/Exception/ProtocolException.php +++ b/src/Exception/ProtocolException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge\Exception; @@ -17,67 +17,43 @@ class ProtocolException extends RidgeException { - /** - * @param int $frameEnd - * - * @return self - */ public static function invalidFrameEnd(int $frameEnd): self { - $message = \sprintf("Frame end byte invalid - expected 0x%02x, got 0x%02x.", Constants::FRAME_END, $frameEnd); - - return new self($message); + return new self( + \sprintf( + 'Frame end byte invalid - expected 0x%02x, got 0x%02x.', + Constants::FRAME_END, + $frameEnd + ) + ); } - /** - * @param int $type - * - * @return self - */ public static function unknownFrameType(int $type): self { - return new self("Unhandled frame type '{$type}'."); + return new self(\sprintf('Unhandled frame type `%d`.', $type)); } - /** - * @param AbstractFrame $frame - * - * @return self - */ public static function unknownFrameClass(AbstractFrame $frame): self { - return new self("Unhandled frame '" . get_class($frame) . "'."); + return new self(\sprintf('Unhandled frame `%s`', \get_class($frame))); } - /** - * @return self - */ public static function notEmptyHeartbeat(): self { - return new self("Heartbeat frame must be empty."); + return new self('Heartbeat frame must be empty.'); } - /** - * @param int $fieldType - * - * @return self - */ public static function unknownFieldType(int $fieldType): self { - $cType = \ctype_print(\chr($fieldType)) ? " ('" . \chr($fieldType) . "')" : ""; + $cType = \ctype_print(\chr($fieldType)) ? ' (`' . \chr($fieldType) . '`)' : ''; - return new self(\sprintf("Unhandled field type 0x%02x%s.", $fieldType, $cType)); + return new self(\sprintf('Unhandled field type 0x%02x%s.', $fieldType, $cType)); } - /** - * @param int $fieldType - * - * @return self - */ - public static function unknownValueType($value): self + public static function unknownValueType(mixed $value): self { - $class = (\is_object($value) ? " (class " . \get_class($value) . ")" : ""); + $class = (\is_object($value) ? ' (class `' . \get_class($value) . '`)' : ''); - return new self(\sprintf("Unhandled value type '%s'%s.", \gettype($value), $class)); + return new self(\sprintf('Unhandled value type `%s`%s.', \gettype($value), $class)); } } diff --git a/src/Exception/RidgeException.php b/src/Exception/RidgeException.php index a1fd0ab..c7a2c1e 100644 --- a/src/Exception/RidgeException.php +++ b/src/Exception/RidgeException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge\Exception; diff --git a/src/Message.php b/src/Message.php index f3606ac..104d3ac 100644 --- a/src/Message.php +++ b/src/Message.php @@ -30,12 +30,12 @@ final class Message private $routingKey; /** - * @var string + * @var string|null */ private $consumerTag; /** - * @var int + * @var int|null */ private $deliveryTag; @@ -54,22 +54,12 @@ final class Message */ private $headers; - /** - * @param string $content - * @param string $exchange - * @param string $routingKey - * @param string $consumerTag - * @param int $deliveryTag - * @param bool $redelivered - * @param bool $returned - * @param array $headers - */ public function __construct( string $content, string $exchange, string $routingKey, - string $consumerTag = null, - int $deliveryTag = null, + ?string $consumerTag = null, + ?int $deliveryTag = null, bool $redelivered = false, bool $returned = false, array $headers = [] @@ -84,79 +74,47 @@ public function __construct( $this->headers = $headers; } - /** - * @return string - */ public function content(): string { return $this->content; } - /** - * @return string - */ public function exchange(): string { return $this->exchange; } - /** - * @return string - */ public function routingKey(): string { return $this->routingKey; } - /** - * @return string - */ public function consumerTag(): ?string { return $this->consumerTag; } - /** - * @return int - */ public function deliveryTag(): ?int { return $this->deliveryTag; } - /** - * @return bool - */ public function redelivered(): bool { return $this->redelivered; } - /** - * @return bool - */ public function returned(): bool { return $this->returned; } - /** - * @return array - */ public function headers(): array { return $this->headers; } - /** - * Returns header or default value. - * - * @param string $name - * @param mixed $default - * - * @return mixed - */ - public function header(string $name, $default = null) + public function header(string $name, mixed $default = null): mixed { return $this->headers[$name] ?? $default; } diff --git a/src/MessageReceiver.php b/src/MessageReceiver.php index 991790e..a8e2707 100644 --- a/src/MessageReceiver.php +++ b/src/MessageReceiver.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; @@ -16,11 +16,10 @@ final class MessageReceiver { - const + public const STATE_WAIT = 0, STATE_HEAD = 1, - STATE_BODY = 2 - ; + STATE_BODY = 2; /** * @var Channel @@ -53,24 +52,20 @@ final class MessageReceiver private $callbacks = []; /** - * @var Protocol\BasicDeliverFrame + * @var Protocol\BasicDeliverFrame|null */ private $deliver; /** - * @var Protocol\BasicReturnFrame + * @var Protocol\BasicReturnFrame|null */ private $return; /** - * @var Protocol\ContentHeaderFrame + * @var Protocol\ContentHeaderFrame|null */ private $header; - /** - * @param Channel $channel - * @param Connection $connection - */ public function __construct(Channel $channel, Connection $connection) { $this->channel = $channel; @@ -78,9 +73,6 @@ public function __construct(Channel $channel, Connection $connection) $this->buffer = new Buffer; } - /** - * @return void - */ public function start(): void { $this->onFrame(Protocol\BasicReturnFrame::class, [$this, 'receiveReturn']); @@ -89,43 +81,28 @@ public function start(): void $this->onFrame(Protocol\ContentBodyFrame::class, [$this, 'receiveBody']); } - /** - * @return void - */ public function stop(): void { $this->callbacks = []; } - /** - * @param callable $callback - * - * @return void - */ public function onMessage(callable $callback): void { $this->callbacks[] = $callback; } /** - * @param string $frame - * @param callable $callback - * - * @return void + * @psalm-param class-string $frame */ public function onFrame(string $frame, callable $callback): void { $this->connection->subscribe($this->channel->id(), $frame, $callback); } - /** - * @param Protocol\BasicReturnFrame $frame - * - * @return void - */ public function receiveReturn(Protocol\BasicReturnFrame $frame): void { - if ($this->state !== self::STATE_WAIT) { + if($this->state !== self::STATE_WAIT) + { return; } @@ -133,14 +110,10 @@ public function receiveReturn(Protocol\BasicReturnFrame $frame): void $this->state = self::STATE_HEAD; } - /** - * @param Protocol\BasicDeliverFrame $frame - * - * @return void - */ public function receiveDeliver(Protocol\BasicDeliverFrame $frame): void { - if ($this->state !== self::STATE_WAIT) { + if($this->state !== self::STATE_WAIT) + { return; } @@ -148,14 +121,10 @@ public function receiveDeliver(Protocol\BasicDeliverFrame $frame): void $this->state = self::STATE_HEAD; } - /** - * @param Protocol\ContentHeaderFrame $frame - * - * @return void - */ public function receiveHeader(Protocol\ContentHeaderFrame $frame): void { - if ($this->state !== self::STATE_HEAD) { + if($this->state !== self::STATE_HEAD) + { return; } @@ -166,22 +135,19 @@ public function receiveHeader(Protocol\ContentHeaderFrame $frame): void $this->runCallbacks(); } - /** - * @param Protocol\ContentBodyFrame $frame - * - * @return void - */ public function receiveBody(Protocol\ContentBodyFrame $frame): void { - if ($this->state !== self::STATE_BODY) { + if($this->state !== self::STATE_BODY) + { return; } - $this->buffer->append($frame->payload); + $this->buffer->append((string) $frame->payload); - $this->remaining -= $frame->size; + $this->remaining -= (int) $frame->size; - if ($this->remaining < 0) { + if($this->remaining < 0) + { throw Exception\ChannelException::bodyOverflow($this->remaining); } @@ -189,15 +155,17 @@ public function receiveBody(Protocol\ContentBodyFrame $frame): void } /** - * @return void + * @throws \PHPinnacle\Ridge\Exception\ChannelException */ private function runCallbacks(): void { - if ($this->remaining !== 0) { + if($this->remaining !== 0) + { return; } - if ($this->return) { + if($this->return) + { $message = new Message( $this->buffer->flush(), $this->return->exchange, @@ -206,9 +174,11 @@ private function runCallbacks(): void null, false, true, - $this->header->toArray() + $this->header !== null ? $this->header->toArray() : [] ); - } elseif ($this->deliver) { + } + else if($this->deliver) + { $message = new Message( $this->buffer->flush(), $this->deliver->exchange, @@ -217,9 +187,11 @@ private function runCallbacks(): void $this->deliver->deliveryTag, $this->deliver->redelivered, false, - $this->header->toArray() + $this->header !== null ? $this->header->toArray() : [] ); - } else { + } + else + { throw Exception\ChannelException::frameOrder(); } @@ -227,7 +199,9 @@ private function runCallbacks(): void $this->deliver = null; $this->header = null; - foreach ($this->callbacks as $callback) { + foreach($this->callbacks as $callback) + { + /** @psalm-suppress MixedArgumentTypeCoercion */ asyncCall($callback, $message); } diff --git a/src/Parser.php b/src/Parser.php index 822e20c..80959c8 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -22,11 +22,6 @@ public function __construct() $this->buffer = new Buffer; } - /** - * @param string $chunk - * - * @return void - */ public function append(string $chunk): void { $this->buffer->append($chunk); @@ -37,39 +32,44 @@ public function append(string $chunk): void * * Returns NULL if there are not enough data to construct whole frame. * - * @return Protocol\AbstractFrame + * @throws \PHPinnacle\Buffer\BufferOverflow + * @throws \PHPinnacle\Ridge\Exception\ProtocolException */ public function parse(): ?Protocol\AbstractFrame { - if ($this->buffer->size() < 7) { + if($this->buffer->size() < 7) + { return null; } $size = $this->buffer->readUint32(3); $length = $size + 8; - if ($this->buffer->size() < $length) { + if($this->buffer->size() < $length) + { return null; } - $type = $this->buffer->readUint8(0); + $type = $this->buffer->readUint8(); $channel = $this->buffer->readUint16(1); $payload = $this->buffer->read($size, 7); $frameEnd = $this->buffer->readUint8($length - 1); $this->buffer->discard($length); - if ($frameEnd !== Constants::FRAME_END) { + if($frameEnd !== Constants::FRAME_END) + { throw Exception\ProtocolException::invalidFrameEnd($frameEnd); } - switch ($type) { + switch($type) + { case Constants::FRAME_HEADER: $frame = Protocol\ContentHeaderFrame::unpack(new Buffer($payload)); break; case Constants::FRAME_BODY: - $frame = new Protocol\ContentBodyFrame; + $frame = new Protocol\ContentBodyFrame; $frame->payload = $payload; break; @@ -96,253 +96,179 @@ public function parse(): ?Protocol\AbstractFrame /** * Consumes AMQP method frame. * - * @param Buffer $buffer - * - * @return Protocol\MethodFrame + * @throws \PHPinnacle\Buffer\BufferOverflow + * @throws \PHPinnacle\Ridge\Exception\ClassInvalid */ private function consumeMethodFrame(Buffer $buffer): Protocol\MethodFrame { $classId = $buffer->consumeUint16(); $methodId = $buffer->consumeUint16(); - switch ($classId) { - case Constants::CLASS_BASIC: - return $this->consumeBasicFrame($methodId, $buffer); - case Constants::CLASS_CONNECTION: - return $this->consumeConnectionFrame($methodId, $buffer); - case Constants::CLASS_CHANNEL: - return $this->consumeChannelFrame($methodId, $buffer); - case Constants::CLASS_EXCHANGE: - return $this->consumeExchangeFrame($methodId, $buffer); - case Constants::CLASS_QUEUE: - return $this->consumeQueueFrame($methodId, $buffer); - case Constants::CLASS_TX: - return $this->consumeTxFrame($methodId); - case Constants::CLASS_CONFIRM: - return $this->consumeConfirmFrame($methodId, $buffer); - default: - throw new Exception\ClassInvalid($classId); - } + return match ($classId) + { + Constants::CLASS_BASIC => $this->consumeBasicFrame($methodId, $buffer), + Constants::CLASS_CONNECTION => $this->consumeConnectionFrame($methodId, $buffer), + Constants::CLASS_CHANNEL => $this->consumeChannelFrame($methodId, $buffer), + Constants::CLASS_EXCHANGE => $this->consumeExchangeFrame($methodId, $buffer), + Constants::CLASS_QUEUE => $this->consumeQueueFrame($methodId, $buffer), + Constants::CLASS_TX => $this->consumeTxFrame($methodId), + Constants::CLASS_CONFIRM => $this->consumeConfirmFrame($methodId, $buffer), + default => throw new Exception\ClassInvalid($classId), + }; } - + /** - * @param int $methodId - * @param Buffer $buffer - * * @return Protocol\MethodFrame + * + * @throws \PHPinnacle\Ridge\Exception\MethodInvalid + * @throws \PHPinnacle\Buffer\BufferOverflow */ private function consumeBasicFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - switch ($methodId) { - case Constants::METHOD_BASIC_DELIVER: - return Protocol\BasicDeliverFrame::unpack($buffer); - case Constants::METHOD_BASIC_GET: - return Protocol\BasicGetFrame::unpack($buffer); - case Constants::METHOD_BASIC_GET_OK: - return Protocol\BasicGetOkFrame::unpack($buffer); - case Constants::METHOD_BASIC_GET_EMPTY: - return Protocol\BasicGetEmptyFrame::unpack($buffer); - case Constants::METHOD_BASIC_PUBLISH: - return Protocol\BasicPublishFrame::unpack($buffer); - case Constants::METHOD_BASIC_RETURN: - return Protocol\BasicReturnFrame::unpack($buffer); - case Constants::METHOD_BASIC_ACK: - return Protocol\BasicAckFrame::unpack($buffer); - case Constants::METHOD_BASIC_NACK: - return Protocol\BasicNackFrame::unpack($buffer); - case Constants::METHOD_BASIC_REJECT: - return Protocol\BasicRejectFrame::unpack($buffer); - case Constants::METHOD_BASIC_QOS: - return Protocol\BasicQosFrame::unpack($buffer); - case Constants::METHOD_BASIC_QOS_OK: - return new Protocol\BasicQosOkFrame; - case Constants::METHOD_BASIC_CONSUME: - return Protocol\BasicConsumeFrame::unpack($buffer); - case Constants::METHOD_BASIC_CONSUME_OK: - return Protocol\BasicConsumeOkFrame::unpack($buffer); - case Constants::METHOD_BASIC_CANCEL: - return Protocol\BasicCancelFrame::unpack($buffer); - case Constants::METHOD_BASIC_CANCEL_OK: - return Protocol\BasicCancelOkFrame::unpack($buffer); - case Constants::METHOD_BASIC_RECOVER: - return Protocol\BasicRecoverFrame::unpack($buffer); - case Constants::METHOD_BASIC_RECOVER_OK: - return new Protocol\BasicRecoverOkFrame; - case Constants::METHOD_BASIC_RECOVER_ASYNC: - return Protocol\BasicRecoverAsyncFrame::unpack($buffer); - default: - throw new Exception\MethodInvalid(Constants::CLASS_BASIC, $methodId); - } + return match ($methodId) + { + Constants::METHOD_BASIC_DELIVER => Protocol\BasicDeliverFrame::unpack($buffer), + Constants::METHOD_BASIC_GET => Protocol\BasicGetFrame::unpack($buffer), + Constants::METHOD_BASIC_GET_OK => Protocol\BasicGetOkFrame::unpack($buffer), + Constants::METHOD_BASIC_GET_EMPTY => Protocol\BasicGetEmptyFrame::unpack($buffer), + Constants::METHOD_BASIC_PUBLISH => Protocol\BasicPublishFrame::unpack($buffer), + Constants::METHOD_BASIC_RETURN => Protocol\BasicReturnFrame::unpack($buffer), + Constants::METHOD_BASIC_ACK => Protocol\BasicAckFrame::unpack($buffer), + Constants::METHOD_BASIC_NACK => Protocol\BasicNackFrame::unpack($buffer), + Constants::METHOD_BASIC_REJECT => Protocol\BasicRejectFrame::unpack($buffer), + Constants::METHOD_BASIC_QOS => Protocol\BasicQosFrame::unpack($buffer), + Constants::METHOD_BASIC_QOS_OK => new Protocol\BasicQosOkFrame, + Constants::METHOD_BASIC_CONSUME => Protocol\BasicConsumeFrame::unpack($buffer), + Constants::METHOD_BASIC_CONSUME_OK => Protocol\BasicConsumeOkFrame::unpack($buffer), + Constants::METHOD_BASIC_CANCEL => Protocol\BasicCancelFrame::unpack($buffer), + Constants::METHOD_BASIC_CANCEL_OK => Protocol\BasicCancelOkFrame::unpack($buffer), + Constants::METHOD_BASIC_RECOVER => Protocol\BasicRecoverFrame::unpack($buffer), + Constants::METHOD_BASIC_RECOVER_OK => new Protocol\BasicRecoverOkFrame, + Constants::METHOD_BASIC_RECOVER_ASYNC => Protocol\BasicRecoverAsyncFrame::unpack($buffer), + default => throw new Exception\MethodInvalid(Constants::CLASS_BASIC, $methodId), + }; } - + /** - * @param int $methodId - * @param Buffer $buffer - * * @return Protocol\MethodFrame + * + * @throws \PHPinnacle\Ridge\Exception\MethodInvalid + * @throws \PHPinnacle\Buffer\BufferOverflow */ private function consumeConnectionFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - switch ($methodId) { - case Constants::METHOD_CONNECTION_START: - return Protocol\ConnectionStartFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_START_OK: - return Protocol\ConnectionStartOkFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_SECURE: - return Protocol\ConnectionSecureFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_SECURE_OK: - return Protocol\ConnectionSecureOkFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_TUNE: - return Protocol\ConnectionTuneFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_TUNE_OK: - return Protocol\ConnectionTuneOkFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_OPEN: - return Protocol\ConnectionOpenFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_OPEN_OK: - return Protocol\ConnectionOpenOkFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_CLOSE: - return Protocol\ConnectionCloseFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_CLOSE_OK: - return new Protocol\ConnectionCloseOkFrame; - case Constants::METHOD_CONNECTION_BLOCKED: - return Protocol\ConnectionBlockedFrame::unpack($buffer); - case Constants::METHOD_CONNECTION_UNBLOCKED: - return new Protocol\ConnectionUnblockedFrame; - default: - throw new Exception\MethodInvalid(Constants::CLASS_CONNECTION, $methodId); - } + return match ($methodId) + { + Constants::METHOD_CONNECTION_START => Protocol\ConnectionStartFrame::unpack($buffer), + Constants::METHOD_CONNECTION_START_OK => Protocol\ConnectionStartOkFrame::unpack($buffer), + Constants::METHOD_CONNECTION_SECURE => Protocol\ConnectionSecureFrame::unpack($buffer), + Constants::METHOD_CONNECTION_SECURE_OK => Protocol\ConnectionSecureOkFrame::unpack($buffer), + Constants::METHOD_CONNECTION_TUNE => Protocol\ConnectionTuneFrame::unpack($buffer), + Constants::METHOD_CONNECTION_TUNE_OK => Protocol\ConnectionTuneOkFrame::unpack($buffer), + Constants::METHOD_CONNECTION_OPEN => Protocol\ConnectionOpenFrame::unpack($buffer), + Constants::METHOD_CONNECTION_OPEN_OK => Protocol\ConnectionOpenOkFrame::unpack($buffer), + Constants::METHOD_CONNECTION_CLOSE => Protocol\ConnectionCloseFrame::unpack($buffer), + Constants::METHOD_CONNECTION_CLOSE_OK => new Protocol\ConnectionCloseOkFrame, + Constants::METHOD_CONNECTION_BLOCKED => Protocol\ConnectionBlockedFrame::unpack($buffer), + Constants::METHOD_CONNECTION_UNBLOCKED => new Protocol\ConnectionUnblockedFrame, + default => throw new Exception\MethodInvalid(Constants::CLASS_CONNECTION, $methodId), + }; } - + /** - * @param int $methodId - * @param Buffer $buffer - * * @return Protocol\MethodFrame + * + * @throws \PHPinnacle\Ridge\Exception\MethodInvalid + * @throws \PHPinnacle\Buffer\BufferOverflow */ private function consumeChannelFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - switch ($methodId) { - case Constants::METHOD_CHANNEL_OPEN: - return Protocol\ChannelOpenFrame::unpack($buffer); - case Constants::METHOD_CHANNEL_OPEN_OK: - return Protocol\ChannelOpenOkFrame::unpack($buffer); - case Constants::METHOD_CHANNEL_FLOW: - return Protocol\ChannelFlowFrame::unpack($buffer); - case Constants::METHOD_CHANNEL_FLOW_OK: - return Protocol\ChannelFlowOkFrame::unpack($buffer); - case Constants::METHOD_CHANNEL_CLOSE: - return Protocol\ChannelCloseFrame::unpack($buffer); - case Constants::METHOD_CHANNEL_CLOSE_OK: - return new Protocol\ChannelCloseOkFrame; - default: - throw new Exception\MethodInvalid(Constants::CLASS_CHANNEL, $methodId); - } + return match ($methodId) + { + Constants::METHOD_CHANNEL_OPEN => Protocol\ChannelOpenFrame::unpack($buffer), + Constants::METHOD_CHANNEL_OPEN_OK => Protocol\ChannelOpenOkFrame::unpack($buffer), + Constants::METHOD_CHANNEL_FLOW => Protocol\ChannelFlowFrame::unpack($buffer), + Constants::METHOD_CHANNEL_FLOW_OK => Protocol\ChannelFlowOkFrame::unpack($buffer), + Constants::METHOD_CHANNEL_CLOSE => Protocol\ChannelCloseFrame::unpack($buffer), + Constants::METHOD_CHANNEL_CLOSE_OK => new Protocol\ChannelCloseOkFrame, + default => throw new Exception\MethodInvalid(Constants::CLASS_CHANNEL, $methodId), + }; } - + /** - * @param int $methodId - * @param Buffer $buffer - * * @return Protocol\MethodFrame + * + * @throws \PHPinnacle\Ridge\Exception\MethodInvalid + * @throws \PHPinnacle\Buffer\BufferOverflow */ private function consumeExchangeFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - switch ($methodId) { - case Constants::METHOD_EXCHANGE_DECLARE: - return Protocol\ExchangeDeclareFrame::unpack($buffer); - case Constants::METHOD_EXCHANGE_DECLARE_OK: - return new Protocol\ExchangeDeclareOkFrame; - case Constants::METHOD_EXCHANGE_DELETE: - return Protocol\ExchangeDeleteFrame::unpack($buffer); - case Constants::METHOD_EXCHANGE_DELETE_OK: - return new Protocol\ExchangeDeleteOkFrame; - case Constants::METHOD_EXCHANGE_BIND: - return Protocol\ExchangeBindFrame::unpack($buffer); - case Constants::METHOD_EXCHANGE_BIND_OK: - return new Protocol\ExchangeBindOkFrame; - case Constants::METHOD_EXCHANGE_UNBIND: - return Protocol\ExchangeUnbindFrame::unpack($buffer); - case Constants::METHOD_EXCHANGE_UNBIND_OK: - return new Protocol\ExchangeUnbindOkFrame; - default: - throw new Exception\MethodInvalid(Constants::CLASS_EXCHANGE, $methodId); - } + return match ($methodId) + { + Constants::METHOD_EXCHANGE_DECLARE => Protocol\ExchangeDeclareFrame::unpack($buffer), + Constants::METHOD_EXCHANGE_DECLARE_OK => new Protocol\ExchangeDeclareOkFrame, + Constants::METHOD_EXCHANGE_DELETE => Protocol\ExchangeDeleteFrame::unpack($buffer), + Constants::METHOD_EXCHANGE_DELETE_OK => new Protocol\ExchangeDeleteOkFrame, + Constants::METHOD_EXCHANGE_BIND => Protocol\ExchangeBindFrame::unpack($buffer), + Constants::METHOD_EXCHANGE_BIND_OK => new Protocol\ExchangeBindOkFrame, + Constants::METHOD_EXCHANGE_UNBIND => Protocol\ExchangeUnbindFrame::unpack($buffer), + Constants::METHOD_EXCHANGE_UNBIND_OK => new Protocol\ExchangeUnbindOkFrame, + default => throw new Exception\MethodInvalid(Constants::CLASS_EXCHANGE, $methodId), + }; } /** - * @param int $methodId - * @param Buffer $buffer - * * @return Protocol\MethodFrame + * + * @throws \PHPinnacle\Ridge\Exception\MethodInvalid + * @throws \PHPinnacle\Buffer\BufferOverflow */ private function consumeQueueFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - switch ($methodId) { - case Constants::METHOD_QUEUE_DECLARE: - return Protocol\QueueDeclareFrame::unpack($buffer); - case Constants::METHOD_QUEUE_DECLARE_OK: - return Protocol\QueueDeclareOkFrame::unpack($buffer); - case Constants::METHOD_QUEUE_BIND: - return Protocol\QueueBindFrame::unpack($buffer); - case Constants::METHOD_QUEUE_BIND_OK: - return new Protocol\QueueBindOkFrame; - case Constants::METHOD_QUEUE_UNBIND: - return Protocol\QueueUnbindFrame::unpack($buffer); - case Constants::METHOD_QUEUE_UNBIND_OK: - return new Protocol\QueueUnbindOkFrame; - case Constants::METHOD_QUEUE_PURGE: - return Protocol\QueuePurgeFrame::unpack($buffer); - case Constants::METHOD_QUEUE_PURGE_OK: - return Protocol\QueuePurgeOkFrame::unpack($buffer); - case Constants::METHOD_QUEUE_DELETE: - return Protocol\QueueDeleteFrame::unpack($buffer); - case Constants::METHOD_QUEUE_DELETE_OK: - return Protocol\QueueDeleteOkFrame::unpack($buffer); - default: - throw new Exception\MethodInvalid(Constants::CLASS_QUEUE, $methodId); - } + return match ($methodId) + { + Constants::METHOD_QUEUE_DECLARE => Protocol\QueueDeclareFrame::unpack($buffer), + Constants::METHOD_QUEUE_DECLARE_OK => Protocol\QueueDeclareOkFrame::unpack($buffer), + Constants::METHOD_QUEUE_BIND => Protocol\QueueBindFrame::unpack($buffer), + Constants::METHOD_QUEUE_BIND_OK => new Protocol\QueueBindOkFrame, + Constants::METHOD_QUEUE_UNBIND => Protocol\QueueUnbindFrame::unpack($buffer), + Constants::METHOD_QUEUE_UNBIND_OK => new Protocol\QueueUnbindOkFrame, + Constants::METHOD_QUEUE_PURGE => Protocol\QueuePurgeFrame::unpack($buffer), + Constants::METHOD_QUEUE_PURGE_OK => Protocol\QueuePurgeOkFrame::unpack($buffer), + Constants::METHOD_QUEUE_DELETE => Protocol\QueueDeleteFrame::unpack($buffer), + Constants::METHOD_QUEUE_DELETE_OK => Protocol\QueueDeleteOkFrame::unpack($buffer), + default => throw new Exception\MethodInvalid(Constants::CLASS_QUEUE, $methodId), + }; } - + /** - * @param int $methodId - * - * @return Protocol\MethodFrame + * @throws \PHPinnacle\Ridge\Exception\MethodInvalid */ private function consumeTxFrame(int $methodId): Protocol\MethodFrame { - switch ($methodId) { - case Constants::METHOD_TX_SELECT: - return new Protocol\TxSelectFrame; - case Constants::METHOD_TX_SELECT_OK: - return new Protocol\TxSelectOkFrame; - case Constants::METHOD_TX_COMMIT: - return new Protocol\TxCommitFrame; - case Constants::METHOD_TX_COMMIT_OK: - return new Protocol\TxCommitOkFrame; - case Constants::METHOD_TX_ROLLBACK: - return new Protocol\TxRollbackFrame; - case Constants::METHOD_TX_ROLLBACK_OK: - return new Protocol\TxRollbackOkFrame; - default: - throw new Exception\MethodInvalid(Constants::CLASS_TX, $methodId); - } + return match ($methodId) + { + Constants::METHOD_TX_SELECT => new Protocol\TxSelectFrame, + Constants::METHOD_TX_SELECT_OK => new Protocol\TxSelectOkFrame, + Constants::METHOD_TX_COMMIT => new Protocol\TxCommitFrame, + Constants::METHOD_TX_COMMIT_OK => new Protocol\TxCommitOkFrame, + Constants::METHOD_TX_ROLLBACK => new Protocol\TxRollbackFrame, + Constants::METHOD_TX_ROLLBACK_OK => new Protocol\TxRollbackOkFrame, + default => throw new Exception\MethodInvalid(Constants::CLASS_TX, $methodId), + }; } - + /** - * @param int $methodId - * @param Buffer $buffer - * - * @return Protocol\MethodFrame + * @throws \PHPinnacle\Ridge\Exception\MethodInvalid + * @throws \PHPinnacle\Buffer\BufferOverflow */ private function consumeConfirmFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - switch ($methodId) { - case Constants::METHOD_CONFIRM_SELECT: - return Protocol\ConfirmSelectFrame::unpack($buffer); - case Constants::METHOD_CONFIRM_SELECT_OK: - return new Protocol\ConfirmSelectOkFrame; - default: - throw new Exception\MethodInvalid(Constants::CLASS_CONFIRM, $methodId); - } + return match ($methodId) + { + Constants::METHOD_CONFIRM_SELECT => Protocol\ConfirmSelectFrame::unpack($buffer), + Constants::METHOD_CONFIRM_SELECT_OK => new Protocol\ConfirmSelectOkFrame, + default => throw new Exception\MethodInvalid(Constants::CLASS_CONFIRM, $methodId), + }; } } diff --git a/src/Properties.php b/src/Properties.php index 684c481..645f1e6 100644 --- a/src/Properties.php +++ b/src/Properties.php @@ -8,13 +8,13 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; final class Properties { - const UNKNOWN = 'unknown'; + public const UNKNOWN = 'unknown'; /** * @var string @@ -44,8 +44,9 @@ final class Properties * direct_reply_to * * @var bool[] + * @psalm-var array */ - private $capabilities = []; + private $capabilities; /** * @var int @@ -58,10 +59,7 @@ final class Properties private $maxFrame = 0xFFFF; /** - * @param string $platform - * @param string $product - * @param string $version - * @param array $capabilities + * @psalm-param array $capabilities */ public function __construct(string $platform, string $product, string $version, array $capabilities) { @@ -72,9 +70,12 @@ public function __construct(string $platform, string $product, string $version, } /** - * @param array $config - * - * @return self + * @psalm-param array{ + * platform: string, + * product: string, + * version: string, + * capabilities: array + * } $config */ public static function create(array $config): self { @@ -86,61 +87,37 @@ public static function create(array $config): self ); } - /** - * @param int $maxChannel - * @param int $maxFrame - */ public function tune(int $maxChannel, int $maxFrame): void { $this->maxChannel = $maxChannel; $this->maxFrame = $maxFrame; } - /** - * @param string $ability - * - * @return bool - */ public function capable(string $ability): bool { return $this->capabilities[$ability] ?? false; } - /** - * @return string - */ public function platform(): string { return $this->platform; } - /** - * @return string - */ public function product(): string { return $this->product; } - /** - * @return string - */ public function version(): string { return $this->version; } - /** - * @return int - */ public function maxFrame(): int { return $this->maxFrame; } - /** - * @return int - */ public function maxChannel(): int { return $this->maxChannel; diff --git a/src/Protocol/AbstractFrame.php b/src/Protocol/AbstractFrame.php index 850c389..bda45fb 100644 --- a/src/Protocol/AbstractFrame.php +++ b/src/Protocol/AbstractFrame.php @@ -15,32 +15,26 @@ abstract class AbstractFrame { /** - * @var int + * @var int|null */ public $type; /** - * @var int + * @var int|null */ public $channel; /** - * @var int + * @var int|null */ public $size; /** - * @var string + * @var string|null */ public $payload; - /** - * @param int $type - * @param int $channel - * @param int $size - * @param string $payload - */ - public function __construct(int $type = null, int $channel = null, int $size = null, string $payload = null) + public function __construct(?int $type = null, ?int $channel = null, ?int $size = null, ?string $payload = null) { $this->type = $type; $this->channel = $channel; diff --git a/src/Protocol/AcknowledgmentFrame.php b/src/Protocol/AcknowledgmentFrame.php index 2ea4412..01370e2 100644 --- a/src/Protocol/AcknowledgmentFrame.php +++ b/src/Protocol/AcknowledgmentFrame.php @@ -18,7 +18,7 @@ abstract class AcknowledgmentFrame extends MethodFrame public $deliveryTag = 0; /** - * @var int + * @var bool */ public $multiple = false; } diff --git a/src/Protocol/BasicAckFrame.php b/src/Protocol/BasicAckFrame.php index 554b42e..d81353d 100644 --- a/src/Protocol/BasicAckFrame.php +++ b/src/Protocol/BasicAckFrame.php @@ -19,11 +19,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_ACK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -34,9 +32,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicCancelFrame.php b/src/Protocol/BasicCancelFrame.php index a683010..5214c97 100644 --- a/src/Protocol/BasicCancelFrame.php +++ b/src/Protocol/BasicCancelFrame.php @@ -29,11 +29,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_CANCEL); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -43,10 +41,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicCancelOkFrame.php b/src/Protocol/BasicCancelOkFrame.php index 9f5d980..597ce9f 100644 --- a/src/Protocol/BasicCancelOkFrame.php +++ b/src/Protocol/BasicCancelOkFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_CANCEL_OK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -37,10 +35,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicConsumeFrame.php b/src/Protocol/BasicConsumeFrame.php index a27efe4..2c7f23d 100644 --- a/src/Protocol/BasicConsumeFrame.php +++ b/src/Protocol/BasicConsumeFrame.php @@ -59,11 +59,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_CONSUME); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -79,9 +77,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicConsumeOkFrame.php b/src/Protocol/BasicConsumeOkFrame.php index 5781b8b..bcaf863 100644 --- a/src/Protocol/BasicConsumeOkFrame.php +++ b/src/Protocol/BasicConsumeOkFrame.php @@ -24,28 +24,23 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_CONSUME_OK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { - $self = new self; + $self = new self; $self->consumerTag = $buffer->consumeString(); - + return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendString($this->consumerTag); - + return $buffer; } } diff --git a/src/Protocol/BasicDeliverFrame.php b/src/Protocol/BasicDeliverFrame.php index 7c0f886..1dd628a 100644 --- a/src/Protocol/BasicDeliverFrame.php +++ b/src/Protocol/BasicDeliverFrame.php @@ -19,32 +19,27 @@ class BasicDeliverFrame extends MessageFrame * @var string */ public $consumerTag; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_DELIVER); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { - $self = new self; - $self->consumerTag = $buffer->consumeString(); - $self->deliveryTag = $buffer->consumeInt64(); + $self = new self; + $self->consumerTag = $buffer->consumeString(); + $self->deliveryTag = $buffer->consumeInt64(); [$self->redelivered] = $buffer->consumeBits(1); - $self->exchange = $buffer->consumeString(); - $self->routingKey = $buffer->consumeString(); - + $self->exchange = $buffer->consumeString(); + $self->routingKey = $buffer->consumeString(); + return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); @@ -53,7 +48,7 @@ public function pack(): Buffer $buffer->appendBits([$this->redelivered]); $buffer->appendString($this->exchange); $buffer->appendString($this->routingKey); - + return $buffer; } } diff --git a/src/Protocol/BasicGetEmptyFrame.php b/src/Protocol/BasicGetEmptyFrame.php index 6c89baa..6c44571 100644 --- a/src/Protocol/BasicGetEmptyFrame.php +++ b/src/Protocol/BasicGetEmptyFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_GET_EMPTY); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -37,10 +35,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicGetFrame.php b/src/Protocol/BasicGetFrame.php index 9320b1c..bad4ea1 100644 --- a/src/Protocol/BasicGetFrame.php +++ b/src/Protocol/BasicGetFrame.php @@ -34,11 +34,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_GET); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -49,10 +47,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicGetOkFrame.php b/src/Protocol/BasicGetOkFrame.php index cb4a124..cb31fda 100644 --- a/src/Protocol/BasicGetOkFrame.php +++ b/src/Protocol/BasicGetOkFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_GET_OK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -41,10 +39,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicNackFrame.php b/src/Protocol/BasicNackFrame.php index f989388..02c2b6e 100644 --- a/src/Protocol/BasicNackFrame.php +++ b/src/Protocol/BasicNackFrame.php @@ -24,25 +24,20 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_NACK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { - $self = new self; + $self = new self; $self->deliveryTag = $buffer->consumeInt64(); - + [$self->multiple, $self->requeue] = $buffer->consumeBits(2); - + return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicPublishFrame.php b/src/Protocol/BasicPublishFrame.php index 8905481..a8ff2d7 100644 --- a/src/Protocol/BasicPublishFrame.php +++ b/src/Protocol/BasicPublishFrame.php @@ -44,11 +44,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_PUBLISH); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -62,9 +60,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicQosFrame.php b/src/Protocol/BasicQosFrame.php index 573f11c..24dda12 100644 --- a/src/Protocol/BasicQosFrame.php +++ b/src/Protocol/BasicQosFrame.php @@ -34,11 +34,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_QOS); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -49,10 +47,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicRecoverAsyncFrame.php b/src/Protocol/BasicRecoverAsyncFrame.php index 711c7ab..9e65159 100644 --- a/src/Protocol/BasicRecoverAsyncFrame.php +++ b/src/Protocol/BasicRecoverAsyncFrame.php @@ -19,33 +19,28 @@ class BasicRecoverAsyncFrame extends MethodFrame * @var bool */ public $requeue = false; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_RECOVER_ASYNC); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { $self = new self; [$self->requeue] = $buffer->consumeBits(1); - + return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendBits([$this->requeue]); - + return $buffer; } } diff --git a/src/Protocol/BasicRecoverFrame.php b/src/Protocol/BasicRecoverFrame.php index d4bdd0f..737346b 100644 --- a/src/Protocol/BasicRecoverFrame.php +++ b/src/Protocol/BasicRecoverFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_RECOVER); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -37,10 +35,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicRejectFrame.php b/src/Protocol/BasicRejectFrame.php index 8d0b593..46ff9fb 100644 --- a/src/Protocol/BasicRejectFrame.php +++ b/src/Protocol/BasicRejectFrame.php @@ -26,9 +26,7 @@ public function __construct() } /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -39,9 +37,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/BasicReturnFrame.php b/src/Protocol/BasicReturnFrame.php index 4dcd0cb..5c904cc 100644 --- a/src/Protocol/BasicReturnFrame.php +++ b/src/Protocol/BasicReturnFrame.php @@ -39,11 +39,9 @@ public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_RETURN); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -56,9 +54,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ChannelCloseFrame.php b/src/Protocol/ChannelCloseFrame.php index 9c27987..c40a913 100644 --- a/src/Protocol/ChannelCloseFrame.php +++ b/src/Protocol/ChannelCloseFrame.php @@ -39,11 +39,9 @@ public function __construct() { parent::__construct(Constants::CLASS_CHANNEL, Constants::METHOD_CHANNEL_CLOSE); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -56,10 +54,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ChannelFlowFrame.php b/src/Protocol/ChannelFlowFrame.php index 9ef592e..6f9f356 100644 --- a/src/Protocol/ChannelFlowFrame.php +++ b/src/Protocol/ChannelFlowFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_CHANNEL, Constants::METHOD_CHANNEL_FLOW); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -38,9 +36,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ChannelFlowOkFrame.php b/src/Protocol/ChannelFlowOkFrame.php index c205a94..cf97f4d 100644 --- a/src/Protocol/ChannelFlowOkFrame.php +++ b/src/Protocol/ChannelFlowOkFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_CHANNEL, Constants::METHOD_CHANNEL_FLOW_OK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -37,10 +35,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ChannelOpenFrame.php b/src/Protocol/ChannelOpenFrame.php index b12af9f..f49967c 100644 --- a/src/Protocol/ChannelOpenFrame.php +++ b/src/Protocol/ChannelOpenFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_CHANNEL, Constants::METHOD_CHANNEL_OPEN); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -38,10 +36,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ChannelOpenOkFrame.php b/src/Protocol/ChannelOpenOkFrame.php index 76fad73..665a9da 100644 --- a/src/Protocol/ChannelOpenOkFrame.php +++ b/src/Protocol/ChannelOpenOkFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_CHANNEL, Constants::METHOD_CHANNEL_OPEN_OK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -37,10 +35,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConfirmSelectFrame.php b/src/Protocol/ConfirmSelectFrame.php index f3dd55d..e7d5651 100644 --- a/src/Protocol/ConfirmSelectFrame.php +++ b/src/Protocol/ConfirmSelectFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_CONFIRM, Constants::METHOD_CONFIRM_SELECT); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -37,10 +35,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConnectionBlockedFrame.php b/src/Protocol/ConnectionBlockedFrame.php index e33426a..c65666f 100644 --- a/src/Protocol/ConnectionBlockedFrame.php +++ b/src/Protocol/ConnectionBlockedFrame.php @@ -26,11 +26,9 @@ public function __construct() $this->channel = Constants::CONNECTION_CHANNEL; } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -39,10 +37,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConnectionCloseFrame.php b/src/Protocol/ConnectionCloseFrame.php index 815e4f1..110e6a6 100644 --- a/src/Protocol/ConnectionCloseFrame.php +++ b/src/Protocol/ConnectionCloseFrame.php @@ -41,11 +41,9 @@ public function __construct() $this->channel = Constants::CONNECTION_CHANNEL; } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -58,9 +56,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConnectionOpenFrame.php b/src/Protocol/ConnectionOpenFrame.php index 663ddd0..2392b8a 100644 --- a/src/Protocol/ConnectionOpenFrame.php +++ b/src/Protocol/ConnectionOpenFrame.php @@ -36,11 +36,9 @@ public function __construct() $this->channel = Constants::CONNECTION_CHANNEL; } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -52,9 +50,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConnectionOpenOkFrame.php b/src/Protocol/ConnectionOpenOkFrame.php index 2f2e882..5b3946d 100644 --- a/src/Protocol/ConnectionOpenOkFrame.php +++ b/src/Protocol/ConnectionOpenOkFrame.php @@ -26,11 +26,9 @@ public function __construct() $this->channel = Constants::CONNECTION_CHANNEL; } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -39,10 +37,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConnectionSecureFrame.php b/src/Protocol/ConnectionSecureFrame.php index 8afdd4d..e518e87 100644 --- a/src/Protocol/ConnectionSecureFrame.php +++ b/src/Protocol/ConnectionSecureFrame.php @@ -26,11 +26,9 @@ public function __construct() $this->channel = Constants::CONNECTION_CHANNEL; } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -40,9 +38,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConnectionSecureOkFrame.php b/src/Protocol/ConnectionSecureOkFrame.php index 38928bb..d20f358 100644 --- a/src/Protocol/ConnectionSecureOkFrame.php +++ b/src/Protocol/ConnectionSecureOkFrame.php @@ -26,11 +26,9 @@ public function __construct() $this->channel = Constants::CONNECTION_CHANNEL; } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -39,10 +37,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConnectionStartFrame.php b/src/Protocol/ConnectionStartFrame.php index ff21ba8..69874a2 100644 --- a/src/Protocol/ConnectionStartFrame.php +++ b/src/Protocol/ConnectionStartFrame.php @@ -27,8 +27,14 @@ class ConnectionStartFrame extends MethodFrame /** * @var array + * @psalm-var array{ + * platform: string, + * product: string, + * version: string, + * capabilities: array + * } */ - public $serverProperties = []; + public $serverProperties; /** * @var string @@ -39,34 +45,40 @@ class ConnectionStartFrame extends MethodFrame * @var string */ public $locales = 'en_US'; - + public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_START); - + $this->channel = Constants::CONNECTION_CHANNEL; } /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { - $self = new self; - $self->versionMajor = $buffer->consumeUint8(); - $self->versionMinor = $buffer->consumeUint8(); - $self->serverProperties = $buffer->consumeTable(); + $self = new self; + $self->versionMajor = $buffer->consumeUint8(); + $self->versionMinor = $buffer->consumeUint8(); + + /** + * @psalm-var array{ + * platform: string, + * product: string, + * version: string, + * capabilities: array + * } $serverProperties + */ + $serverProperties = $buffer->consumeTable(); + + $self->serverProperties = $serverProperties; $self->mechanisms = $buffer->consumeText(); $self->locales = $buffer->consumeText(); - + return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); @@ -75,7 +87,7 @@ public function pack(): Buffer $buffer->appendTable($this->serverProperties); $buffer->appendText($this->mechanisms); $buffer->appendText($this->locales); - + return $buffer; } } diff --git a/src/Protocol/ConnectionStartOkFrame.php b/src/Protocol/ConnectionStartOkFrame.php index 585a575..647b088 100644 --- a/src/Protocol/ConnectionStartOkFrame.php +++ b/src/Protocol/ConnectionStartOkFrame.php @@ -41,11 +41,9 @@ public function __construct() $this->channel = Constants::CONNECTION_CHANNEL; } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -58,9 +56,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConnectionTuneFrame.php b/src/Protocol/ConnectionTuneFrame.php index b434afd..af534f2 100644 --- a/src/Protocol/ConnectionTuneFrame.php +++ b/src/Protocol/ConnectionTuneFrame.php @@ -36,11 +36,9 @@ public function __construct() $this->channel = Constants::CONNECTION_CHANNEL; } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -51,10 +49,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ConnectionTuneOkFrame.php b/src/Protocol/ConnectionTuneOkFrame.php index 7f6e7b8..8637a4c 100644 --- a/src/Protocol/ConnectionTuneOkFrame.php +++ b/src/Protocol/ConnectionTuneOkFrame.php @@ -36,11 +36,9 @@ public function __construct() $this->channel = Constants::CONNECTION_CHANNEL; } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -51,10 +49,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ContentBodyFrame.php b/src/Protocol/ContentBodyFrame.php index f0e188c..a2d6150 100644 --- a/src/Protocol/ContentBodyFrame.php +++ b/src/Protocol/ContentBodyFrame.php @@ -14,7 +14,7 @@ class ContentBodyFrame extends AbstractFrame { - public function __construct($channel = null, $payloadSize = null, $payload = null) + public function __construct(?int $channel = null, ?int $payloadSize = null, ?string $payload = null) { parent::__construct(Constants::FRAME_BODY, $channel, $payloadSize, $payload); } diff --git a/src/Protocol/ContentHeaderFrame.php b/src/Protocol/ContentHeaderFrame.php index 55f0a03..065183d 100644 --- a/src/Protocol/ContentHeaderFrame.php +++ b/src/Protocol/ContentHeaderFrame.php @@ -15,22 +15,20 @@ class ContentHeaderFrame extends AbstractFrame { - const - FLAG_CONTENT_TYPE = 0x8000, - FLAG_CONTENT_ENCODING = 0x4000, - FLAG_HEADERS = 0x2000, - FLAG_DELIVERY_MODE = 0x1000, - FLAG_PRIORITY = 0x0800, - FLAG_CORRELATION_ID = 0x0400, - FLAG_REPLY_TO = 0x0200, - FLAG_EXPIRATION = 0x0100, - FLAG_MESSAGE_ID = 0x0080, - FLAG_TIMESTAMP = 0x0040, - FLAG_TYPE = 0x0020, - FLAG_USER_ID = 0x0010, - FLAG_APP_ID = 0x0008, - FLAG_CLUSTER_ID = 0x0004 - ; + private const FLAG_CONTENT_TYPE = 0x8000; + private const FLAG_CONTENT_ENCODING = 0x4000; + private const FLAG_HEADERS = 0x2000; + private const FLAG_DELIVERY_MODE = 0x1000; + private const FLAG_PRIORITY = 0x0800; + private const FLAG_CORRELATION_ID = 0x0400; + private const FLAG_REPLY_TO = 0x0200; + private const FLAG_EXPIRATION = 0x0100; + private const FLAG_MESSAGE_ID = 0x0080; + private const FLAG_TIMESTAMP = 0x0040; + private const FLAG_TYPE = 0x0020; + private const FLAG_USER_ID = 0x0010; + private const FLAG_APP_ID = 0x0008; + private const FLAG_CLUSTER_ID = 0x0004; /** * @var int @@ -53,12 +51,12 @@ class ContentHeaderFrame extends AbstractFrame public $flags = 0; /** - * @var string + * @var string|null */ public $contentType; /** - * @var string + * @var string|null */ public $contentEncoding; @@ -68,57 +66,57 @@ class ContentHeaderFrame extends AbstractFrame public $headers; /** - * @var int + * @var int|null */ public $deliveryMode; /** - * @var int + * @var int|null */ public $priority; /** - * @var string + * @var string|null */ public $correlationId; /** - * @var string + * @var string|null */ public $replyTo; /** - * @var string + * @var string|null */ public $expiration; /** - * @var string + * @var string|null */ public $messageId; /** - * @var \DateTimeInterface + * @var \DateTimeInterface|null */ public $timestamp; /** - * @var string + * @var string|null */ public $typeHeader; /** - * @var string + * @var string|null */ public $userId; /** - * @var string + * @var string|null */ public $appId; /** - * @var string + * @var string|null */ public $clusterId; @@ -128,9 +126,7 @@ public function __construct() } /** - * @param Buffer $buffer - * - * @return ContentHeaderFrame + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -140,197 +136,231 @@ public static function unpack(Buffer $buffer): self $self->weight = $buffer->consumeUint16(); $self->bodySize = $buffer->consumeUint64(); $self->flags = $flags = $buffer->consumeUint16(); - - if ($flags & self::FLAG_CONTENT_TYPE) { + + if($flags & self::FLAG_CONTENT_TYPE) + { $self->contentType = $buffer->consumeString(); } - - if ($flags & self::FLAG_CONTENT_ENCODING) { + + if($flags & self::FLAG_CONTENT_ENCODING) + { $self->contentEncoding = $buffer->consumeString(); } - - if ($flags & self::FLAG_HEADERS) { + + if($flags & self::FLAG_HEADERS) + { $self->headers = $buffer->consumeTable(); } - - if ($flags & self::FLAG_DELIVERY_MODE) { + + if($flags & self::FLAG_DELIVERY_MODE) + { $self->deliveryMode = $buffer->consumeUint8(); } - - if ($flags & self::FLAG_PRIORITY) { + + if($flags & self::FLAG_PRIORITY) + { $self->priority = $buffer->consumeUint8(); } - - if ($flags & self::FLAG_CORRELATION_ID) { + + if($flags & self::FLAG_CORRELATION_ID) + { $self->correlationId = $buffer->consumeString(); } - - if ($flags & self::FLAG_REPLY_TO) { + + if($flags & self::FLAG_REPLY_TO) + { $self->replyTo = $buffer->consumeString(); } - - if ($flags & self::FLAG_EXPIRATION) { + + if($flags & self::FLAG_EXPIRATION) + { $self->expiration = $buffer->consumeString(); } - - if ($flags & self::FLAG_MESSAGE_ID) { + + if($flags & self::FLAG_MESSAGE_ID) + { $self->messageId = $buffer->consumeString(); } - - if ($flags & self::FLAG_TIMESTAMP) { + + if($flags & self::FLAG_TIMESTAMP) + { $self->timestamp = $buffer->consumeTimestamp(); } - - if ($flags & self::FLAG_TYPE) { + + if($flags & self::FLAG_TYPE) + { $self->typeHeader = $buffer->consumeString(); } - - if ($flags & self::FLAG_USER_ID) { + + if($flags & self::FLAG_USER_ID) + { $self->userId = $buffer->consumeString(); } - - if ($flags & self::FLAG_APP_ID) { + + if($flags & self::FLAG_APP_ID) + { $self->appId = $buffer->consumeString(); } - - if ($flags & self::FLAG_CLUSTER_ID) { + + if($flags & self::FLAG_CLUSTER_ID) + { $self->clusterId = $buffer->consumeString(); } - + return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = new Buffer; $buffer ->appendUint16($this->classId) ->appendUint16($this->weight) - ->appendUint64($this->bodySize) - ; - + ->appendUint64($this->bodySize); + $flags = $this->flags; - + $buffer->appendUint16($flags); - - if ($flags & ContentHeaderFrame::FLAG_CONTENT_TYPE) { - $buffer->appendString($this->contentType); + + if($flags & self::FLAG_CONTENT_TYPE) + { + $buffer->appendString((string) $this->contentType); } - - if ($flags & ContentHeaderFrame::FLAG_CONTENT_ENCODING) { - $buffer->appendString($this->contentEncoding); + + if($flags & self::FLAG_CONTENT_ENCODING) + { + $buffer->appendString((string) $this->contentEncoding); } - - if ($flags & ContentHeaderFrame::FLAG_HEADERS) { + + if($flags & self::FLAG_HEADERS) + { $buffer->appendTable($this->headers); } - - if ($flags & ContentHeaderFrame::FLAG_DELIVERY_MODE) { - $buffer->appendUint8($this->deliveryMode); + + if($flags & self::FLAG_DELIVERY_MODE) + { + $buffer->appendUint8((int) $this->deliveryMode); } - - if ($flags & ContentHeaderFrame::FLAG_PRIORITY) { - $buffer->appendUint8($this->priority); + + if($flags & self::FLAG_PRIORITY) + { + $buffer->appendUint8((int) $this->priority); } - - if ($flags & ContentHeaderFrame::FLAG_CORRELATION_ID) { - $buffer->appendString($this->correlationId); + + if($flags & self::FLAG_CORRELATION_ID) + { + $buffer->appendString((string) $this->correlationId); } - - if ($flags & ContentHeaderFrame::FLAG_REPLY_TO) { - $buffer->appendString($this->replyTo); + + if($flags & self::FLAG_REPLY_TO) + { + $buffer->appendString((string) $this->replyTo); } - - if ($flags & ContentHeaderFrame::FLAG_EXPIRATION) { - $buffer->appendString($this->expiration); + + if($flags & self::FLAG_EXPIRATION) + { + $buffer->appendString((string) $this->expiration); } - - if ($flags & ContentHeaderFrame::FLAG_MESSAGE_ID) { - $buffer->appendString($this->messageId); + + if($flags & self::FLAG_MESSAGE_ID) + { + $buffer->appendString((string) $this->messageId); } - - if ($flags & ContentHeaderFrame::FLAG_TIMESTAMP) { + + if($flags & self::FLAG_TIMESTAMP && $this->timestamp !== null) + { $buffer->appendTimestamp($this->timestamp); } - - if ($flags & ContentHeaderFrame::FLAG_TYPE) { - $buffer->appendString($this->typeHeader); + + if($flags & self::FLAG_TYPE) + { + $buffer->appendString((string) $this->typeHeader); } - - if ($flags & ContentHeaderFrame::FLAG_USER_ID) { - $buffer->appendString($this->userId); + + if($flags & self::FLAG_USER_ID) + { + $buffer->appendString((string) $this->userId); } - - if ($flags & ContentHeaderFrame::FLAG_APP_ID) { - $buffer->appendString($this->appId); + + if($flags & self::FLAG_APP_ID) + { + $buffer->appendString((string) $this->appId); } - - if ($flags & ContentHeaderFrame::FLAG_CLUSTER_ID) { - $buffer->appendString($this->clusterId); + + if($flags & self::FLAG_CLUSTER_ID) + { + $buffer->appendString((string) $this->clusterId); } - + return $buffer; } - /** - * @return array - */ public function toArray(): array { $headers = $this->headers ?: []; - if ($this->contentType !== null) { + if($this->contentType !== null) + { $headers['content-type'] = $this->contentType; } - if ($this->contentEncoding !== null) { + if($this->contentEncoding !== null) + { $headers['content-encoding'] = $this->contentEncoding; } - if ($this->deliveryMode !== null) { + if($this->deliveryMode !== null) + { $headers['delivery-mode'] = $this->deliveryMode; } - if ($this->priority !== null) { + if($this->priority !== null) + { $headers['priority'] = $this->priority; } - if ($this->correlationId !== null) { + if($this->correlationId !== null) + { $headers['correlation-id'] = $this->correlationId; } - if ($this->replyTo !== null) { + if($this->replyTo !== null) + { $headers['reply-to'] = $this->replyTo; } - if ($this->expiration !== null) { + if($this->expiration !== null) + { $headers['expiration'] = $this->expiration; } - if ($this->messageId !== null) { + if($this->messageId !== null) + { $headers['message-id'] = $this->messageId; } - if ($this->timestamp !== null) { + if($this->timestamp !== null) + { $headers['timestamp'] = $this->timestamp; } - if ($this->typeHeader !== null) { + if($this->typeHeader !== null) + { $headers['type'] = $this->typeHeader; } - if ($this->userId !== null) { + if($this->userId !== null) + { $headers['user-id'] = $this->userId; } - if ($this->appId !== null) { + if($this->appId !== null) + { $headers['app-id'] = $this->appId; } - if ($this->clusterId !== null) { + if($this->clusterId !== null) + { $headers['cluster-id'] = $this->clusterId; } diff --git a/src/Protocol/ExchangeBindFrame.php b/src/Protocol/ExchangeBindFrame.php index f5fb9b9..7afc6f9 100644 --- a/src/Protocol/ExchangeBindFrame.php +++ b/src/Protocol/ExchangeBindFrame.php @@ -49,11 +49,9 @@ public function __construct() { parent::__construct(Constants::CLASS_EXCHANGE, Constants::METHOD_EXCHANGE_BIND); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -68,9 +66,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ExchangeDeclareFrame.php b/src/Protocol/ExchangeDeclareFrame.php index 0016a17..b1699fe 100644 --- a/src/Protocol/ExchangeDeclareFrame.php +++ b/src/Protocol/ExchangeDeclareFrame.php @@ -64,11 +64,9 @@ public function __construct() { parent::__construct(Constants::CLASS_EXCHANGE, Constants::METHOD_EXCHANGE_DECLARE); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -84,9 +82,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ExchangeDeleteFrame.php b/src/Protocol/ExchangeDeleteFrame.php index 9d19ca4..00ccef1 100644 --- a/src/Protocol/ExchangeDeleteFrame.php +++ b/src/Protocol/ExchangeDeleteFrame.php @@ -39,11 +39,9 @@ public function __construct() { parent::__construct(Constants::CLASS_EXCHANGE, Constants::METHOD_EXCHANGE_DELETE); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -56,10 +54,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ExchangeUnbindFrame.php b/src/Protocol/ExchangeUnbindFrame.php index 0daaaf9..e62ad18 100644 --- a/src/Protocol/ExchangeUnbindFrame.php +++ b/src/Protocol/ExchangeUnbindFrame.php @@ -49,11 +49,9 @@ public function __construct() { parent::__construct(Constants::CLASS_EXCHANGE, Constants::METHOD_EXCHANGE_UNBIND); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -67,10 +65,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/MethodFrame.php b/src/Protocol/MethodFrame.php index d84c231..d165760 100644 --- a/src/Protocol/MethodFrame.php +++ b/src/Protocol/MethodFrame.php @@ -16,20 +16,16 @@ class MethodFrame extends AbstractFrame { /** - * @var int + * @var int|null */ public $classId; /** - * @var int + * @var int|null */ public $methodId; - /** - * @param int $classId - * @param int $methodId - */ - public function __construct(int $classId = null, int $methodId = null) + public function __construct(?int $classId = null, ?int $methodId = null) { parent::__construct(Constants::FRAME_METHOD); @@ -37,16 +33,12 @@ public function __construct(int $classId = null, int $methodId = null) $this->methodId = $methodId; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = new Buffer; $buffer - ->appendUint16($this->classId) - ->appendUint16($this->methodId) - ; + ->appendUint16((int) $this->classId) + ->appendUint16((int) $this->methodId); return $buffer; } diff --git a/src/Protocol/QueueBindFrame.php b/src/Protocol/QueueBindFrame.php index 3424201..1f6074c 100644 --- a/src/Protocol/QueueBindFrame.php +++ b/src/Protocol/QueueBindFrame.php @@ -48,13 +48,10 @@ class QueueBindFrame extends MethodFrame public function __construct() { parent::__construct(Constants::CLASS_QUEUE, Constants::METHOD_QUEUE_BIND); - } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -68,10 +65,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/QueueDeclareFrame.php b/src/Protocol/QueueDeclareFrame.php index 299fdf9..7e0ee0e 100644 --- a/src/Protocol/QueueDeclareFrame.php +++ b/src/Protocol/QueueDeclareFrame.php @@ -59,11 +59,9 @@ public function __construct() { parent::__construct(Constants::CLASS_QUEUE, Constants::METHOD_QUEUE_DECLARE); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -77,10 +75,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/QueueDeclareOkFrame.php b/src/Protocol/QueueDeclareOkFrame.php index 589c72d..390cf0f 100644 --- a/src/Protocol/QueueDeclareOkFrame.php +++ b/src/Protocol/QueueDeclareOkFrame.php @@ -34,11 +34,9 @@ public function __construct() { parent::__construct(Constants::CLASS_QUEUE, Constants::METHOD_QUEUE_DECLARE_OK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -50,9 +48,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/QueueDeleteFrame.php b/src/Protocol/QueueDeleteFrame.php index 57823d4..b6ae5a9 100644 --- a/src/Protocol/QueueDeleteFrame.php +++ b/src/Protocol/QueueDeleteFrame.php @@ -44,11 +44,9 @@ public function __construct() { parent::__construct(Constants::CLASS_QUEUE, Constants::METHOD_QUEUE_DELETE); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -60,10 +58,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/QueueDeleteOkFrame.php b/src/Protocol/QueueDeleteOkFrame.php index 8d8de65..e499c03 100644 --- a/src/Protocol/QueueDeleteOkFrame.php +++ b/src/Protocol/QueueDeleteOkFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_QUEUE, Constants::METHOD_QUEUE_DELETE_OK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -37,10 +35,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/QueuePurgeFrame.php b/src/Protocol/QueuePurgeFrame.php index e1bd347..02b2c50 100644 --- a/src/Protocol/QueuePurgeFrame.php +++ b/src/Protocol/QueuePurgeFrame.php @@ -34,11 +34,9 @@ public function __construct() { parent::__construct(Constants::CLASS_QUEUE, Constants::METHOD_QUEUE_PURGE); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -49,10 +47,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/QueuePurgeOkFrame.php b/src/Protocol/QueuePurgeOkFrame.php index c42018a..5c3fd69 100644 --- a/src/Protocol/QueuePurgeOkFrame.php +++ b/src/Protocol/QueuePurgeOkFrame.php @@ -24,11 +24,9 @@ public function __construct() { parent::__construct(Constants::CLASS_QUEUE, Constants::METHOD_QUEUE_PURGE_OK); } - + /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -37,10 +35,7 @@ public static function unpack(Buffer $buffer): self return $self; } - - /** - * @return Buffer - */ + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/QueueUnbindFrame.php b/src/Protocol/QueueUnbindFrame.php index d9c4276..92d454b 100644 --- a/src/Protocol/QueueUnbindFrame.php +++ b/src/Protocol/QueueUnbindFrame.php @@ -46,9 +46,7 @@ public function __construct() } /** - * @param Buffer $buffer - * - * @return self + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { @@ -62,9 +60,6 @@ public static function unpack(Buffer $buffer): self return $self; } - /** - * @return Buffer - */ public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Queue.php b/src/Queue.php index 47c0394..e1dc4dc 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types=1); +declare(strict_types = 1); namespace PHPinnacle\Ridge; @@ -29,11 +29,6 @@ final class Queue */ private $consumers; - /** - * @param string $name - * @param int $messages - * @param int $consumers - */ public function __construct(string $name, int $messages, int $consumers) { $this->name = $name; @@ -41,25 +36,16 @@ public function __construct(string $name, int $messages, int $consumers) $this->consumers = $consumers; } - /** - * @return string - */ public function name(): string { return $this->name; } - /** - * @return int - */ public function messages(): int { return $this->messages; } - /** - * @return int - */ public function consumers(): int { return $this->consumers; diff --git a/tests/AsyncTest.php b/tests/AsyncTest.php index ab00366..4e723ca 100644 --- a/tests/AsyncTest.php +++ b/tests/AsyncTest.php @@ -65,6 +65,7 @@ protected function runTestAsync(...$args) self::markTestIncomplete($message); + /** @noinspection PhpUnreachableStatementInspection */ Loop::stop(); } }); diff --git a/tests/BufferTest.php b/tests/BufferTest.php index 115fbca..03ec97c 100644 --- a/tests/BufferTest.php +++ b/tests/BufferTest.php @@ -1,4 +1,5 @@ -getTimestamp(), $buffer->consumeTimestamp()->getTimestamp()); } - public function testString() + public function testString(): void { $buffer = new Buffer; @@ -32,7 +33,7 @@ public function testString() self::assertSame('abcd', $buffer->consumeString()); } - public function testText() + public function testText(): void { $buffer = new Buffer; @@ -40,7 +41,7 @@ public function testText() self::assertSame('abcd', $buffer->consumeText()); } - public function testArray() + public function testArray(): void { $buffer = new Buffer; $array = [1, 'a', null, true, M_PI, [2], ['a' => 'b'], \DateTime::createFromFormat('m/d/Y', '1/1/1970')]; @@ -49,9 +50,9 @@ public function testArray() self::assertEquals($array, $buffer->consumeArray()); } - public function testArrayWithUnknownField() + public function testArrayWithUnknownField(): void { - self::expectException(Exception\ProtocolException::class); + $this->expectException(Exception\ProtocolException::class); $buffer = new Buffer; $table = [ @@ -63,7 +64,7 @@ public function testArrayWithUnknownField() $buffer->appendArray($table); } - public function testTable() + public function testTable(): void { $buffer = new Buffer; $table = [ @@ -82,9 +83,9 @@ public function testTable() self::assertEquals($table, $buffer->consumeTable()); } - public function testTableWithUnknownField() + public function testTableWithUnknownField(): void { - self::expectException(Exception\ProtocolException::class); + $this->expectException(Exception\ProtocolException::class); $buffer = new Buffer; $table = [ @@ -96,7 +97,7 @@ public function testTableWithUnknownField() $buffer->appendTable($table); } - public function testBits() + public function testBits(): void { $buffer = new Buffer; $bits = [true, false, true]; diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index 062c229..5e88db3 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -20,9 +20,9 @@ class ChannelTest extends AsyncTest { - public function testOpenNotReadyChannel(Client $client) + public function testOpenNotReadyChannel(Client $client): \Generator { - self::expectException(Exception\ChannelException::class); + $this->expectException(Exception\ChannelException::class); /** @var Channel $channel */ $channel = yield $client->channel(); @@ -36,7 +36,7 @@ public function testOpenNotReadyChannel(Client $client) yield $client->disconnect(); } - public function testClose(Client $client) + public function testClose(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -50,22 +50,25 @@ public function testClose(Client $client) yield $client->disconnect(); } - public function testCloseAlreadyClosedChannel(Client $client) + public function testCloseAlreadyClosedChannel(Client $client): \Generator { - self::expectException(Exception\ChannelException::class); + $this->expectException(Exception\ChannelException::class); /** @var Channel $channel */ $channel = yield $client->channel(); - try { + try + { yield $channel->close(); yield $channel->close(); - } finally { + } + finally + { yield $client->disconnect(); } } - public function testExchangeDeclare(Client $client) + public function testExchangeDeclare(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -79,12 +82,12 @@ public function testExchangeDeclare(Client $client) yield $client->disconnect(); } - public function testExchangeDelete(Client $client) + public function testExchangeDelete(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); - yield $channel->exchangeDeclare('test_exchange_no_ad', 'direct'); + yield $channel->exchangeDeclare('test_exchange_no_ad'); $promise = $channel->exchangeDelete('test_exchange_no_ad'); @@ -95,7 +98,7 @@ public function testExchangeDelete(Client $client) yield $client->disconnect(); } - public function testQueueDeclare(Client $client) + public function testQueueDeclare(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -115,7 +118,7 @@ public function testQueueDeclare(Client $client) yield $client->disconnect(); } - public function testQueueBind(Client $client) + public function testQueueBind(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -132,7 +135,7 @@ public function testQueueBind(Client $client) yield $client->disconnect(); } - public function testQueueUnbind(Client $client) + public function testQueueUnbind(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -150,7 +153,7 @@ public function testQueueUnbind(Client $client) yield $client->disconnect(); } - public function testQueuePurge(Client $client) + public function testQueuePurge(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -169,7 +172,7 @@ public function testQueuePurge(Client $client) yield $client->disconnect(); } - public function testQueueDelete(Client $client) + public function testQueueDelete(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -187,7 +190,7 @@ public function testQueueDelete(Client $client) yield $client->disconnect(); } - public function testPublish(Client $client) + public function testPublish(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -200,17 +203,19 @@ public function testPublish(Client $client) yield $client->disconnect(); } - public function testMandatoryPublish(Client $client) + public function testMandatoryPublish(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); $deferred = new Deferred(); - $watcher = Loop::delay(100, function () use ($deferred) { + $watcher = Loop::delay(100, function() use ($deferred) + { $deferred->resolve(false); }); - $channel->events()->onReturn(function (Message $message) use ($deferred, $watcher) { + $channel->events()->onReturn(function(Message $message) use ($deferred, $watcher) + { self::assertSame($message->content(), '.'); self::assertSame($message->exchange(), ''); self::assertSame($message->routingKey(), '404'); @@ -232,12 +237,13 @@ public function testMandatoryPublish(Client $client) yield $client->disconnect(); } - public function testImmediatePublish(Client $client) + public function testImmediatePublish(Client $client): \Generator { $properties = $client->properties(); // RabbitMQ 3 doesn't support "immediate" publish flag. - if ($properties->product() === 'RabbitMQ' && version_compare($properties->version(), '3.0', '>')) { + if($properties->product() === 'RabbitMQ' && version_compare($properties->version(), '3.0', '>')) + { yield $client->disconnect(); return; @@ -247,11 +253,13 @@ public function testImmediatePublish(Client $client) $channel = yield $client->channel(); $deferred = new Deferred(); - $watcher = Loop::delay(100, function () use ($deferred) { + $watcher = Loop::delay(100, function() use ($deferred) + { $deferred->resolve(false); }); - $channel->events()->onReturn(function (Message $message) use ($deferred, $watcher) { + $channel->events()->onReturn(function(Message $message) use ($deferred, $watcher) + { self::assertTrue($message->returned()); Loop::cancel($watcher); @@ -267,16 +275,16 @@ public function testImmediatePublish(Client $client) yield $client->disconnect(); } - public function testConsume(Client $client) + public function testConsume(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); yield $channel->queueDeclare('test_queue', false, false, false, true); yield $channel->publish('hi', '', 'test_queue'); - - /** @noinspection PhpUnusedLocalVariableInspection */ - $tag = yield $channel->consume(function (Message $message) use ($client, &$tag) { + + $tag = yield $channel->consume(function(Message $message) use ($client, &$tag) + { self::assertEquals('hi', $message->content()); self::assertEquals($tag, $message->consumerTag()); @@ -284,7 +292,7 @@ public function testConsume(Client $client) }, 'test_queue', false, true); } - public function testCancel(Client $client) + public function testCancel(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -292,8 +300,14 @@ public function testCancel(Client $client) yield $channel->queueDeclare('test_queue', false, false, false, true); yield $channel->publish('hi', '', 'test_queue'); - $tag = yield $channel->consume(function (Message $message) { - }, 'test_queue', false, true); + $tag = yield $channel->consume( + static function(Message $message) + { + }, + 'test_queue', + false, + true + ); $promise = $channel->cancel($tag); @@ -304,7 +318,7 @@ public function testCancel(Client $client) yield $client->disconnect(); } - public function testHeaders(Client $client) + public function testHeaders(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -312,10 +326,11 @@ public function testHeaders(Client $client) yield $channel->queueDeclare('test_queue', false, false, false, true); yield $channel->publish('hi html', '', 'test_queue', [ 'content-type' => 'text/html', - 'custom' => 'value', + 'custom' => 'value', ]); - yield $channel->consume(function (Message $message) use ($client) { + yield $channel->consume(function(Message $message) use ($client) + { self::assertEquals('text/html', $message->header('content-type')); self::assertEquals('value', $message->header('custom')); self::assertEquals('hi html', $message->content()); @@ -324,7 +339,7 @@ public function testHeaders(Client $client) }, 'test_queue', false, true); } - public function testGet(Client $client) + public function testGet(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -357,7 +372,8 @@ public function testGet(Client $client) self::assertEquals(2, $message2->deliveryTag()); self::assertFalse($message2->redelivered()); - $client->disconnect()->onResolve(function () use ($client) { + $client->disconnect()->onResolve(function() use ($client) + { yield $client->connect(); /** @var Channel $channel */ @@ -378,7 +394,7 @@ public function testGet(Client $client) }); } - public function testAck(Client $client) + public function testAck(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -397,7 +413,7 @@ public function testAck(Client $client) yield $client->disconnect(); } - public function testNack(Client $client) + public function testNack(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -430,7 +446,7 @@ public function testNack(Client $client) yield $client->disconnect(); } - public function testReject(Client $client) + public function testReject(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -463,7 +479,7 @@ public function testReject(Client $client) yield $client->disconnect(); } - public function testRecover(Client $client) + public function testRecover(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -494,7 +510,7 @@ public function testRecover(Client $client) yield $client->disconnect(); } - public function testBigMessage(Client $client) + public function testBigMessage(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -505,7 +521,8 @@ public function testBigMessage(Client $client) yield $channel->publish($body, '', 'test_queue'); - yield $channel->consume(function (Message $message, Channel $channel) use ($body, $client) { + yield $channel->consume(function(Message $message, Channel $channel) use ($body, $client) + { self::assertEquals(\strlen($body), \strlen($message->content())); yield $channel->ack($message); @@ -513,9 +530,9 @@ public function testBigMessage(Client $client) }, 'test_queue'); } - public function testGetDouble(Client $client) + public function testGetDouble(Client $client): \Generator { - self::expectException(Exception\ChannelException::class); + $this->expectException(Exception\ChannelException::class); /** @var Channel $channel */ $channel = yield $client->channel(); @@ -523,19 +540,22 @@ public function testGetDouble(Client $client) yield $channel->queueDeclare('get_test_double', false, false, false, true); yield $channel->publish('.', '', 'get_test_double'); - try { + try + { yield [ $channel->get('get_test_double'), $channel->get('get_test_double'), ]; - } finally { + } + finally + { yield $channel->queueDelete('get_test_double'); yield $client->disconnect(); } } - public function testEmptyMessage(Client $client) + public function testEmptyMessage(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -551,12 +571,14 @@ public function testEmptyMessage(Client $client) $count = 0; - yield $channel->consume(function (Message $message, Channel $channel) use ($client, &$count) { + yield $channel->consume(function(Message $message, Channel $channel) use ($client, &$count) + { self::assertEmpty($message->content()); yield $channel->ack($message); - if (++$count === 2) { + if(++$count === 2) + { yield $client->disconnect(); } }, 'empty_body_message_test'); @@ -565,7 +587,7 @@ public function testEmptyMessage(Client $client) yield $channel->publish('', '', 'empty_body_message_test'); } - public function testTxs(Client $client) + public function testTxs(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); @@ -593,55 +615,65 @@ public function testTxs(Client $client) yield $client->disconnect(); } - public function testTxSelectCannotBeCalledMultipleTimes(Client $client) + public function testTxSelectCannotBeCalledMultipleTimes(Client $client): \Generator { - self::expectException(Exception\ChannelException::class); + $this->expectException(Exception\ChannelException::class); /** @var Channel $channel */ $channel = yield $client->channel(); - try { + try + { yield $channel->txSelect(); yield $channel->txSelect(); - } finally { + } + finally + { yield $client->disconnect(); } } - public function testTxCommitCannotBeCalledUnderNotTransactionMode(Client $client) + public function testTxCommitCannotBeCalledUnderNotTransactionMode(Client $client): \Generator { - self::expectException(Exception\ChannelException::class); + $this->expectException(Exception\ChannelException::class); /** @var Channel $channel */ $channel = yield $client->channel(); - try { + try + { yield $channel->txCommit(); - } finally { + } + finally + { yield $client->disconnect(); } } - public function testTxRollbackCannotBeCalledUnderNotTransactionMode(Client $client) + public function testTxRollbackCannotBeCalledUnderNotTransactionMode(Client $client): \Generator { - self::expectException(Exception\ChannelException::class); + $this->expectException(Exception\ChannelException::class); /** @var Channel $channel */ $channel = yield $client->channel(); - try { + try + { yield $channel->txRollback(); - } finally { + } + finally + { yield $client->disconnect(); } } - public function testConfirmMode(Client $client) + public function testConfirmMode(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); - $channel->events()->onAck(function (int $deliveryTag, bool $multiple) { - self::assertEquals($deliveryTag, 1); + $channel->events()->onAck(function(int $deliveryTag, bool $multiple) + { + self::assertEquals(1, $deliveryTag); self::assertFalse($multiple); }); @@ -649,7 +681,7 @@ public function testConfirmMode(Client $client) $deliveryTag = yield $channel->publish('.'); - self::assertEquals($deliveryTag, 1); + self::assertEquals(1, $deliveryTag); yield $client->disconnect(); } diff --git a/tests/ClientConnectTest.php b/tests/ClientConnectTest.php index e8bd85e..d547f25 100644 --- a/tests/ClientConnectTest.php +++ b/tests/ClientConnectTest.php @@ -12,13 +12,11 @@ use Amp\Loop; use Amp\Socket\ConnectException; -use PHPinnacle\Ridge\Channel; use PHPinnacle\Ridge\Client; -use PHPinnacle\Ridge\Message; class ClientConnectTest extends RidgeTest { - public function testConnect() + public function testConnect(): void { Loop::run(function () { $client = self::client(); @@ -35,9 +33,9 @@ public function testConnect() }); } - public function testConnectFailure() + public function testConnectFailure(): void { - self::expectException(ConnectException::class); + $this->expectException(ConnectException::class); Loop::run(function () { $client = Client::create('amqp://127.0.0.2:5673'); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index e8e00ce..207dd39 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -16,7 +16,7 @@ class ClientTest extends AsyncTest { - public function testOpenChannel(Client $client) + public function testOpenChannel(Client $client): \Generator { self::assertPromise($promise = $client->channel()); self::assertInstanceOf(Channel::class, yield $promise); @@ -24,7 +24,7 @@ public function testOpenChannel(Client $client) yield $client->disconnect(); } - public function testOpenMultipleChannel(Client $client) + public function testOpenMultipleChannel(Client $client): \Generator { /** @var Channel $channel1 */ /** @var Channel $channel2 */ @@ -45,7 +45,7 @@ public function testOpenMultipleChannel(Client $client) yield $client->disconnect(); } - public function testDisconnectWithBufferedMessages(Client $client) + public function testDisconnectWithBufferedMessages(Client $client): \Generator { /** @var Channel $channel */ $channel = yield $client->channel(); diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 4b90e65..2ac922b 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -14,18 +14,18 @@ class ConfigTest extends RidgeTest { - public function testCreate() + public function testCreate(): void { $config = new Config(); - self::assertSame('localhost', $config->host()); - self::assertSame(5672, $config->port()); - self::assertSame('/', $config->vhost()); - self::assertSame('guest', $config->user()); - self::assertSame('guest', $config->password()); + self::assertSame('localhost', $config->host); + self::assertSame(5672, $config->port); + self::assertSame('/', $config->vhost); + self::assertSame('guest', $config->user); + self::assertSame('guest', $config->pass); } - public function testUri() + public function testUri(): void { $default = new Config(); $custom = new Config('my-domain.com', 6672); @@ -34,24 +34,24 @@ public function testUri() self::assertSame('tcp://my-domain.com:6672', $custom->uri()); } - public function testParse() + public function testParse(): void { $config = Config::parse('amqp://user:pass@localhost:5672/test'); - self::assertSame('localhost', $config->host()); - self::assertSame(5672, $config->port()); - self::assertSame('test', $config->vhost()); - self::assertSame('user', $config->user()); - self::assertSame('pass', $config->password()); + self::assertSame('localhost', $config->host); + self::assertSame(5672, $config->port); + self::assertSame('test', $config->vhost); + self::assertSame('user', $config->user); + self::assertSame('pass', $config->pass); } - public function testVhost() + public function testVhost(): void { - self::assertSame('test', Config::parse('amqp://localhost:5672/test')->vhost()); - self::assertSame('/', Config::parse('amqp://localhost:5672/')->vhost()); - self::assertSame('/', Config::parse('amqp://localhost:5672')->vhost()); - self::assertSame('test/', Config::parse('amqp://localhost:5672/test/')->vhost()); - self::assertSame('test/test', Config::parse('amqp://localhost:5672/test/test')->vhost()); - self::assertSame('test/test//', Config::parse('amqp://localhost:5672/test/test//')->vhost()); + self::assertSame('test', Config::parse('amqp://localhost:5672/test')->vhost); + self::assertSame('/', Config::parse('amqp://localhost:5672/')->vhost); + self::assertSame('/', Config::parse('amqp://localhost:5672')->vhost); + self::assertSame('test/', Config::parse('amqp://localhost:5672/test/')->vhost); + self::assertSame('test/test', Config::parse('amqp://localhost:5672/test/test')->vhost); + self::assertSame('test/test//', Config::parse('amqp://localhost:5672/test/test//')->vhost); } } diff --git a/tests/RidgeTest.php b/tests/RidgeTest.php index ded143e..49c7a10 100644 --- a/tests/RidgeTest.php +++ b/tests/RidgeTest.php @@ -22,7 +22,7 @@ abstract class RidgeTest extends TestCase * * @return void */ - protected static function assertPromise($value): void + protected static function assertPromise(mixed $value): void { self::assertInstanceOf(Promise::class, $value); } @@ -37,7 +37,6 @@ protected static function client(): Client } $config = Config::parse($dsn); - $config->heartbeat(0); return new Client($config); } From 62f51531c163d59366f690dfeabb18e1bc489fc8 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:22:46 +0100 Subject: [PATCH 04/58] setup rabbitmq --- .github/workflows/continuous-integration.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 8ded6a3..ce28218 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -70,6 +70,15 @@ jobs: - name: Install dependencies run: composer update --no-ansi --no-interaction --no-progress --prefer-lowest + - name: Run RabbitMQ + uses: getong/rabbitmq-action@v1.2 + with: + rabbitmq version: '3.8.2-management-alpine' + host port: 5672 + rabbitmq user: 'guest' + rabbitmq password: 'guest' + rabbitmq vhost: '/' + - name: Run tests with phpunit run: XDEBUG_MODE=coverage php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover From dd7d21252987e3e640145302d7a5e4756b742cca Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:23:21 +0100 Subject: [PATCH 05/58] remove unused compose file --- docker-compose.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index fac00c9..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: "3" - -services: - - queue: - image: rabbitmq:3-management - container_name: service-bus-skeletone-queue - restart: always - ports: - - 5672:5672 - - 15672:15672 - environment: - RABBITMQ_VM_MEMORY_HIGH_WATERMARK: 512MiB - RABBITMQ_ERLANG_COOKIE: f6fAjy5yes - RABBITMQ_DEFAULT_USER: guest - RABBITMQ_DEFAULT_PASS: guest \ No newline at end of file From d3b1580a6378a4bc41342d0bf59116af3b25b92f Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:24:33 +0100 Subject: [PATCH 06/58] update ci file --- .github/workflows/continuous-integration.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ce28218..1b7f9fd 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -73,11 +73,10 @@ jobs: - name: Run RabbitMQ uses: getong/rabbitmq-action@v1.2 with: - rabbitmq version: '3.8.2-management-alpine' + rabbitmq version: 3.8.2-management-alpine host port: 5672 - rabbitmq user: 'guest' - rabbitmq password: 'guest' - rabbitmq vhost: '/' + rabbitmq user: guest + rabbitmq password: guest - name: Run tests with phpunit run: XDEBUG_MODE=coverage php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover From 0c5223d544983d765fdbe5d5552c184132cb4cce Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:30:14 +0100 Subject: [PATCH 07/58] update ci file --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1b7f9fd..010e3ad 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -77,6 +77,7 @@ jobs: host port: 5672 rabbitmq user: guest rabbitmq password: guest + rabbitmq vhost: / - name: Run tests with phpunit run: XDEBUG_MODE=coverage php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover From 589ab60f266fea8bc63f87f2ac52b7662055197f Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:34:53 +0100 Subject: [PATCH 08/58] update ci file --- .github/workflows/continuous-integration.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 010e3ad..542d1dc 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -80,7 +80,7 @@ jobs: rabbitmq vhost: / - name: Run tests with phpunit - run: XDEBUG_MODE=coverage php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover + run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover - name: Upload coverage file uses: actions/upload-artifact@v2 diff --git a/README.md b/README.md index 9db9a2e..18142d1 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Please see [CHANGELOG](.github/CHANGELOG.md) for more information on what has ch ## Contributing -Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CONDUCT](.github/CONDUCT.md) for details. ## Security From 85bdf395fe5d5922bdeec988d4c7e73745401ba4 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:36:31 +0100 Subject: [PATCH 09/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 542d1dc..1b54a5b 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -80,7 +80,7 @@ jobs: rabbitmq vhost: / - name: Run tests with phpunit - run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover + run: php ./vendor/bin/phpunit --configuration ./phpunit.xml - name: Upload coverage file uses: actions/upload-artifact@v2 From 7ea71fdb7c7324aa56ff0c6c4fd468bc9623c76a Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:38:10 +0100 Subject: [PATCH 10/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1b54a5b..76ff6b1 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -80,7 +80,7 @@ jobs: rabbitmq vhost: / - name: Run tests with phpunit - run: php ./vendor/bin/phpunit --configuration ./phpunit.xml + run: php ./vendor/bin/phpunit - name: Upload coverage file uses: actions/upload-artifact@v2 From a5ef68a547cd742350f3ae9a2fe3dfa51edc8545 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:45:51 +0100 Subject: [PATCH 11/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- tests/BufferTest.php | 108 --- tests/ChannelTest.php | 688 ------------------- tests/ClientConnectTest.php | 59 -- tests/ClientTest.php | 68 -- 5 files changed, 1 insertion(+), 924 deletions(-) delete mode 100644 tests/BufferTest.php delete mode 100644 tests/ChannelTest.php delete mode 100644 tests/ClientConnectTest.php delete mode 100644 tests/ClientTest.php diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 76ff6b1..542d1dc 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -80,7 +80,7 @@ jobs: rabbitmq vhost: / - name: Run tests with phpunit - run: php ./vendor/bin/phpunit + run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover - name: Upload coverage file uses: actions/upload-artifact@v2 diff --git a/tests/BufferTest.php b/tests/BufferTest.php deleted file mode 100644 index 03ec97c..0000000 --- a/tests/BufferTest.php +++ /dev/null @@ -1,108 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPinnacle\Ridge\Tests; - -use PHPinnacle\Ridge\Buffer; -use PHPinnacle\Ridge\Exception; - -class BufferTest extends RidgeTest -{ - public function testTimestamp(): void - { - $buffer = new Buffer; - $date = new \DateTime; - - self::assertSame($buffer, $buffer->appendTimestamp($date)); - self::assertSame($date->getTimestamp(), $buffer->consumeTimestamp()->getTimestamp()); - } - - public function testString(): void - { - $buffer = new Buffer; - - self::assertSame($buffer, $buffer->appendString('abcd')); - self::assertSame('abcd', $buffer->consumeString()); - } - - public function testText(): void - { - $buffer = new Buffer; - - self::assertSame($buffer, $buffer->appendText('abcd')); - self::assertSame('abcd', $buffer->consumeText()); - } - - public function testArray(): void - { - $buffer = new Buffer; - $array = [1, 'a', null, true, M_PI, [2], ['a' => 'b'], \DateTime::createFromFormat('m/d/Y', '1/1/1970')]; - - self::assertSame($buffer, $buffer->appendArray($array)); - self::assertEquals($array, $buffer->consumeArray()); - } - - public function testArrayWithUnknownField(): void - { - $this->expectException(Exception\ProtocolException::class); - - $buffer = new Buffer; - $table = [ - 1, - 'a', - new \stdClass(), - ]; - - $buffer->appendArray($table); - } - - public function testTable(): void - { - $buffer = new Buffer; - $table = [ - '1' => 1, - 'b' => 'a', - 'c' => null, - '5' => true, - 'p' => M_PI, - '6' => [1,2], - 'g' => [ - 'a' => 1 - ], - ]; - - self::assertSame($buffer, $buffer->appendTable($table)); - self::assertEquals($table, $buffer->consumeTable()); - } - - public function testTableWithUnknownField(): void - { - $this->expectException(Exception\ProtocolException::class); - - $buffer = new Buffer; - $table = [ - '1' => 1, - 'b' => 'a', - 'c' => new \stdClass(), - ]; - - $buffer->appendTable($table); - } - - public function testBits(): void - { - $buffer = new Buffer; - $bits = [true, false, true]; - - self::assertSame($buffer, $buffer->appendBits($bits)); - self::assertEquals($bits, $buffer->consumeBits(\count($bits))); - } -} diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php deleted file mode 100644 index 5e88db3..0000000 --- a/tests/ChannelTest.php +++ /dev/null @@ -1,688 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPinnacle\Ridge\Tests; - -use Amp\Deferred; -use Amp\Loop; -use PHPinnacle\Ridge\Channel; -use PHPinnacle\Ridge\Client; -use PHPinnacle\Ridge\Exception; -use PHPinnacle\Ridge\Message; -use PHPinnacle\Ridge\Queue; - -class ChannelTest extends AsyncTest -{ - public function testOpenNotReadyChannel(Client $client): \Generator - { - $this->expectException(Exception\ChannelException::class); - - /** @var Channel $channel */ - $channel = yield $client->channel(); - - $promise = $channel->open(); - - self::assertPromise($promise); - - yield $promise; - - yield $client->disconnect(); - } - - public function testClose(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - $promise = $channel->close(); - - self::assertPromise($promise); - - yield $promise; - - yield $client->disconnect(); - } - - public function testCloseAlreadyClosedChannel(Client $client): \Generator - { - $this->expectException(Exception\ChannelException::class); - - /** @var Channel $channel */ - $channel = yield $client->channel(); - - try - { - yield $channel->close(); - yield $channel->close(); - } - finally - { - yield $client->disconnect(); - } - } - - public function testExchangeDeclare(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - $promise = $channel->exchangeDeclare('test_exchange', 'direct', false, false, true); - - self::assertPromise($promise); - - yield $promise; - - yield $client->disconnect(); - } - - public function testExchangeDelete(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->exchangeDeclare('test_exchange_no_ad'); - - $promise = $channel->exchangeDelete('test_exchange_no_ad'); - - self::assertPromise($promise); - - yield $promise; - - yield $client->disconnect(); - } - - public function testQueueDeclare(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - $promise = $channel->queueDeclare('test_queue', false, false, false, true); - - self::assertPromise($promise); - - /** @var Queue $queue */ - $queue = yield $promise; - - self::assertInstanceOf(Queue::class, $queue); - self::assertSame('test_queue', $queue->name()); - self::assertSame(0, $queue->messages()); - self::assertSame(0, $queue->consumers()); - - yield $client->disconnect(); - } - - public function testQueueBind(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->exchangeDeclare('test_exchange', 'direct', false, false, true); - yield $channel->queueDeclare('test_queue', false, false, false, true); - - $promise = $channel->queueBind('test_queue', 'test_exchange'); - - self::assertPromise($promise); - - yield $promise; - - yield $client->disconnect(); - } - - public function testQueueUnbind(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->exchangeDeclare('test_exchange', 'direct', false, false, true); - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->queueBind('test_queue', 'test_exchange'); - - $promise = $channel->queueUnbind('test_queue', 'test_exchange'); - - self::assertPromise($promise); - - yield $promise; - - yield $client->disconnect(); - } - - public function testQueuePurge(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->publish('test', '', 'test_queue'); - yield $channel->publish('test', '', 'test_queue'); - - $promise = $channel->queuePurge('test_queue'); - - $messages = yield $promise; - - self::assertPromise($promise); - self::assertEquals(2, $messages); - - yield $client->disconnect(); - } - - public function testQueueDelete(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue_no_ad'); - yield $channel->publish('test', '', 'test_queue_no_ad'); - - $promise = $channel->queueDelete('test_queue_no_ad'); - - $messages = yield $promise; - - self::assertPromise($promise); - self::assertEquals(1, $messages); - - yield $client->disconnect(); - } - - public function testPublish(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - $promise = $channel->publish('test publish'); - - self::assertPromise($promise); - self::assertNull(yield $promise); - - yield $client->disconnect(); - } - - public function testMandatoryPublish(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - $deferred = new Deferred(); - $watcher = Loop::delay(100, function() use ($deferred) - { - $deferred->resolve(false); - }); - - $channel->events()->onReturn(function(Message $message) use ($deferred, $watcher) - { - self::assertSame($message->content(), '.'); - self::assertSame($message->exchange(), ''); - self::assertSame($message->routingKey(), '404'); - self::assertSame($message->headers(), []); - self::assertNull($message->consumerTag()); - self::assertNull($message->deliveryTag()); - self::assertFalse($message->redelivered()); - self::assertTrue($message->returned()); - - Loop::cancel($watcher); - - $deferred->resolve(true); - }); - - yield $channel->publish('.', '', '404', [], true); - - self::assertTrue(yield $deferred->promise(), 'Mandatory return event not received!'); - - yield $client->disconnect(); - } - - public function testImmediatePublish(Client $client): \Generator - { - $properties = $client->properties(); - - // RabbitMQ 3 doesn't support "immediate" publish flag. - if($properties->product() === 'RabbitMQ' && version_compare($properties->version(), '3.0', '>')) - { - yield $client->disconnect(); - - return; - } - - /** @var Channel $channel */ - $channel = yield $client->channel(); - - $deferred = new Deferred(); - $watcher = Loop::delay(100, function() use ($deferred) - { - $deferred->resolve(false); - }); - - $channel->events()->onReturn(function(Message $message) use ($deferred, $watcher) - { - self::assertTrue($message->returned()); - - Loop::cancel($watcher); - - $deferred->resolve(true); - }); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->publish('.', '', 'test_queue', [], false, true); - - self::assertTrue(yield $deferred->promise(), 'Immediate return event not received!'); - - yield $client->disconnect(); - } - - public function testConsume(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->publish('hi', '', 'test_queue'); - - $tag = yield $channel->consume(function(Message $message) use ($client, &$tag) - { - self::assertEquals('hi', $message->content()); - self::assertEquals($tag, $message->consumerTag()); - - yield $client->disconnect(); - }, 'test_queue', false, true); - } - - public function testCancel(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->publish('hi', '', 'test_queue'); - - $tag = yield $channel->consume( - static function(Message $message) - { - }, - 'test_queue', - false, - true - ); - - $promise = $channel->cancel($tag); - - self::assertPromise($promise); - - yield $promise; - - yield $client->disconnect(); - } - - public function testHeaders(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->publish('hi html', '', 'test_queue', [ - 'content-type' => 'text/html', - 'custom' => 'value', - ]); - - yield $channel->consume(function(Message $message) use ($client) - { - self::assertEquals('text/html', $message->header('content-type')); - self::assertEquals('value', $message->header('custom')); - self::assertEquals('hi html', $message->content()); - - yield $client->disconnect(); - }, 'test_queue', false, true); - } - - public function testGet(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('get_test', false, false, false, true); - - yield $channel->publish('.', '', 'get_test'); - - /** @var Message $message1 */ - $message1 = yield $channel->get('get_test', true); - - self::assertNotNull($message1); - self::assertInstanceOf(Message::class, $message1); - self::assertEquals('', $message1->exchange()); - self::assertEquals('.', $message1->content()); - self::assertEquals('get_test', $message1->routingKey()); - self::assertEquals(1, $message1->deliveryTag()); - self::assertNull($message1->consumerTag()); - self::assertFalse($message1->redelivered()); - self::assertIsArray($message1->headers()); - - self::assertNull(yield $channel->get('get_test', true)); - - yield $channel->publish('..', '', 'get_test'); - - /** @var Message $message2 */ - $message2 = yield $channel->get('get_test'); - - self::assertNotNull($message2); - self::assertEquals(2, $message2->deliveryTag()); - self::assertFalse($message2->redelivered()); - - $client->disconnect()->onResolve(function() use ($client) - { - yield $client->connect(); - - /** @var Channel $channel */ - $channel = yield $client->channel(); - - /** @var Message $message3 */ - $message3 = yield $channel->get('get_test'); - - self::assertNotNull($message3); - self::assertInstanceOf(Message::class, $message3); - self::assertEquals('', $message3->exchange()); - self::assertEquals('..', $message3->content()); - self::assertTrue($message3->redelivered()); - - yield $channel->ack($message3); - - yield $client->disconnect(); - }); - } - - public function testAck(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->publish('.', '', 'test_queue'); - - /** @var Message $message */ - $message = yield $channel->get('test_queue'); - $promise = $channel->ack($message); - - self::assertPromise($promise); - - yield $promise; - - yield $client->disconnect(); - } - - public function testNack(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->publish('.', '', 'test_queue'); - - /** @var Message $message */ - $message = yield $channel->get('test_queue'); - - self::assertNotNull($message); - self::assertFalse($message->redelivered()); - - $promise = $channel->nack($message); - - self::assertPromise($promise); - - yield $promise; - - /** @var Message $message */ - $message = yield $channel->get('test_queue'); - - self::assertNotNull($message); - self::assertTrue($message->redelivered()); - - yield $channel->nack($message, false, false); - - self::assertNull(yield $channel->get('test_queue')); - - yield $client->disconnect(); - } - - public function testReject(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->publish('.', '', 'test_queue'); - - /** @var Message $message */ - $message = yield $channel->get('test_queue'); - - self::assertNotNull($message); - self::assertFalse($message->redelivered()); - - $promise = $channel->reject($message); - - self::assertPromise($promise); - - yield $promise; - - /** @var Message $message */ - $message = yield $channel->get('test_queue'); - - self::assertNotNull($message); - self::assertTrue($message->redelivered()); - - yield $channel->reject($message, false); - - self::assertNull(yield $channel->get('test_queue')); - - yield $client->disconnect(); - } - - public function testRecover(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - yield $channel->publish('.', '', 'test_queue'); - - /** @var Message $message */ - $message = yield $channel->get('test_queue'); - - self::assertNotNull($message); - self::assertFalse($message->redelivered()); - - $promise = $channel->recover(true); - - self::assertPromise($promise); - - yield $promise; - - /** @var Message $message */ - $message = yield $channel->get('test_queue'); - - self::assertNotNull($message); - self::assertTrue($message->redelivered()); - - yield $channel->ack($message); - - yield $client->disconnect(); - } - - public function testBigMessage(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('test_queue', false, false, false, true); - - $body = \str_repeat('a', 10 << 20); // 10 MiB - - yield $channel->publish($body, '', 'test_queue'); - - yield $channel->consume(function(Message $message, Channel $channel) use ($body, $client) - { - self::assertEquals(\strlen($body), \strlen($message->content())); - - yield $channel->ack($message); - yield $client->disconnect(); - }, 'test_queue'); - } - - public function testGetDouble(Client $client): \Generator - { - $this->expectException(Exception\ChannelException::class); - - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('get_test_double', false, false, false, true); - yield $channel->publish('.', '', 'get_test_double'); - - try - { - yield [ - $channel->get('get_test_double'), - $channel->get('get_test_double'), - ]; - } - finally - { - yield $channel->queueDelete('get_test_double'); - - yield $client->disconnect(); - } - } - - public function testEmptyMessage(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('empty_body_message_test', false, false, false, true); - yield $channel->publish('', '', 'empty_body_message_test'); - - /** @var Message $message */ - $message = yield $channel->get('empty_body_message_test', true); - - self::assertNotNull($message); - self::assertEquals('', $message->content()); - - $count = 0; - - yield $channel->consume(function(Message $message, Channel $channel) use ($client, &$count) - { - self::assertEmpty($message->content()); - - yield $channel->ack($message); - - if(++$count === 2) - { - yield $client->disconnect(); - } - }, 'empty_body_message_test'); - - yield $channel->publish('', '', 'empty_body_message_test'); - yield $channel->publish('', '', 'empty_body_message_test'); - } - - public function testTxs(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - - yield $channel->queueDeclare('tx_test', false, false, false, true); - - yield $channel->txSelect(); - yield $channel->publish('.', '', 'tx_test'); - yield $channel->txCommit(); - - /** @var Message $message */ - $message = yield $channel->get('tx_test', true); - - self::assertNotNull($message); - self::assertInstanceOf(Message::class, $message); - self::assertEquals('.', $message->content()); - - $channel->publish('..', '', 'tx_test'); - $channel->txRollback(); - - $nothing = yield $channel->get('tx_test', true); - - self::assertNull($nothing); - - yield $client->disconnect(); - } - - public function testTxSelectCannotBeCalledMultipleTimes(Client $client): \Generator - { - $this->expectException(Exception\ChannelException::class); - - /** @var Channel $channel */ - $channel = yield $client->channel(); - - try - { - yield $channel->txSelect(); - yield $channel->txSelect(); - } - finally - { - yield $client->disconnect(); - } - } - - public function testTxCommitCannotBeCalledUnderNotTransactionMode(Client $client): \Generator - { - $this->expectException(Exception\ChannelException::class); - - /** @var Channel $channel */ - $channel = yield $client->channel(); - - try - { - yield $channel->txCommit(); - } - finally - { - yield $client->disconnect(); - } - } - - public function testTxRollbackCannotBeCalledUnderNotTransactionMode(Client $client): \Generator - { - $this->expectException(Exception\ChannelException::class); - - /** @var Channel $channel */ - $channel = yield $client->channel(); - - try - { - yield $channel->txRollback(); - } - finally - { - yield $client->disconnect(); - } - } - - public function testConfirmMode(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - $channel->events()->onAck(function(int $deliveryTag, bool $multiple) - { - self::assertEquals(1, $deliveryTag); - self::assertFalse($multiple); - }); - - yield $channel->confirmSelect(); - - $deliveryTag = yield $channel->publish('.'); - - self::assertEquals(1, $deliveryTag); - - yield $client->disconnect(); - } -} diff --git a/tests/ClientConnectTest.php b/tests/ClientConnectTest.php deleted file mode 100644 index d547f25..0000000 --- a/tests/ClientConnectTest.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPinnacle\Ridge\Tests; - -use Amp\Loop; -use Amp\Socket\ConnectException; -use PHPinnacle\Ridge\Client; - -class ClientConnectTest extends RidgeTest -{ - public function testConnect(): void - { - Loop::run(function () { - $client = self::client(); - - $promise = $client->connect(); - - self::assertPromise($promise); - - yield $promise; - - self::assertTrue($client->isConnected()); - - yield $client->disconnect(); - }); - } - - public function testConnectFailure(): void - { - $this->expectException(ConnectException::class); - - Loop::run(function () { - $client = Client::create('amqp://127.0.0.2:5673'); - - yield $client->connect(); - }); - } -// -// public function testConnectAuth() -// { -// $client = new Client([ -// 'user' => 'testuser', -// 'password' => 'testpassword', -// 'vhost' => 'testvhost', -// ]); -// $client->connect(); -// $client->disconnect(); -// -// $this->assertTrue(true); -// } -} diff --git a/tests/ClientTest.php b/tests/ClientTest.php deleted file mode 100644 index 207dd39..0000000 --- a/tests/ClientTest.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPinnacle\Ridge\Tests; - -use PHPinnacle\Ridge\Channel; -use PHPinnacle\Ridge\Client; -use PHPinnacle\Ridge\Message; - -class ClientTest extends AsyncTest -{ - public function testOpenChannel(Client $client): \Generator - { - self::assertPromise($promise = $client->channel()); - self::assertInstanceOf(Channel::class, yield $promise); - - yield $client->disconnect(); - } - - public function testOpenMultipleChannel(Client $client): \Generator - { - /** @var Channel $channel1 */ - /** @var Channel $channel2 */ - $channel1 = yield $client->channel(); - $channel2 = yield $client->channel(); - - self::assertInstanceOf(Channel::class, $channel1); - self::assertInstanceOf(Channel::class, $channel2); - self::assertNotEquals($channel1->id(), $channel2->id()); - - /** @var Channel $channel3 */ - $channel3 = yield $client->channel(); - - self::assertInstanceOf(Channel::class, $channel3); - self::assertNotEquals($channel1->id(), $channel3->id()); - self::assertNotEquals($channel2->id(), $channel3->id()); - - yield $client->disconnect(); - } - - public function testDisconnectWithBufferedMessages(Client $client): \Generator - { - /** @var Channel $channel */ - $channel = yield $client->channel(); - $count = 0; - - yield $channel->qos(0, 1000); - yield $channel->queueDeclare('disconnect_test', false, false, false, true); - yield $channel->consume(function (Message $message, Channel $channel) use ($client, &$count) { - yield $channel->ack($message); - - self::assertEquals(1, ++$count); - - yield $client->disconnect(); - }, 'disconnect_test'); - - yield $channel->publish('.', '', 'disconnect_test'); - yield $channel->publish('.', '', 'disconnect_test'); - yield $channel->publish('.', '', 'disconnect_test'); - } -} From 9a4653141c8a04b52421f83731104481c55823bc Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 17:48:11 +0100 Subject: [PATCH 12/58] debug ci --- tests/BufferTest.php | 108 +++++++++++++++++++++++++++++++++++++++++++ tests/ClientTest.php | 68 +++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 tests/BufferTest.php create mode 100644 tests/ClientTest.php diff --git a/tests/BufferTest.php b/tests/BufferTest.php new file mode 100644 index 0000000..03ec97c --- /dev/null +++ b/tests/BufferTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPinnacle\Ridge\Tests; + +use PHPinnacle\Ridge\Buffer; +use PHPinnacle\Ridge\Exception; + +class BufferTest extends RidgeTest +{ + public function testTimestamp(): void + { + $buffer = new Buffer; + $date = new \DateTime; + + self::assertSame($buffer, $buffer->appendTimestamp($date)); + self::assertSame($date->getTimestamp(), $buffer->consumeTimestamp()->getTimestamp()); + } + + public function testString(): void + { + $buffer = new Buffer; + + self::assertSame($buffer, $buffer->appendString('abcd')); + self::assertSame('abcd', $buffer->consumeString()); + } + + public function testText(): void + { + $buffer = new Buffer; + + self::assertSame($buffer, $buffer->appendText('abcd')); + self::assertSame('abcd', $buffer->consumeText()); + } + + public function testArray(): void + { + $buffer = new Buffer; + $array = [1, 'a', null, true, M_PI, [2], ['a' => 'b'], \DateTime::createFromFormat('m/d/Y', '1/1/1970')]; + + self::assertSame($buffer, $buffer->appendArray($array)); + self::assertEquals($array, $buffer->consumeArray()); + } + + public function testArrayWithUnknownField(): void + { + $this->expectException(Exception\ProtocolException::class); + + $buffer = new Buffer; + $table = [ + 1, + 'a', + new \stdClass(), + ]; + + $buffer->appendArray($table); + } + + public function testTable(): void + { + $buffer = new Buffer; + $table = [ + '1' => 1, + 'b' => 'a', + 'c' => null, + '5' => true, + 'p' => M_PI, + '6' => [1,2], + 'g' => [ + 'a' => 1 + ], + ]; + + self::assertSame($buffer, $buffer->appendTable($table)); + self::assertEquals($table, $buffer->consumeTable()); + } + + public function testTableWithUnknownField(): void + { + $this->expectException(Exception\ProtocolException::class); + + $buffer = new Buffer; + $table = [ + '1' => 1, + 'b' => 'a', + 'c' => new \stdClass(), + ]; + + $buffer->appendTable($table); + } + + public function testBits(): void + { + $buffer = new Buffer; + $bits = [true, false, true]; + + self::assertSame($buffer, $buffer->appendBits($bits)); + self::assertEquals($bits, $buffer->consumeBits(\count($bits))); + } +} diff --git a/tests/ClientTest.php b/tests/ClientTest.php new file mode 100644 index 0000000..207dd39 --- /dev/null +++ b/tests/ClientTest.php @@ -0,0 +1,68 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPinnacle\Ridge\Tests; + +use PHPinnacle\Ridge\Channel; +use PHPinnacle\Ridge\Client; +use PHPinnacle\Ridge\Message; + +class ClientTest extends AsyncTest +{ + public function testOpenChannel(Client $client): \Generator + { + self::assertPromise($promise = $client->channel()); + self::assertInstanceOf(Channel::class, yield $promise); + + yield $client->disconnect(); + } + + public function testOpenMultipleChannel(Client $client): \Generator + { + /** @var Channel $channel1 */ + /** @var Channel $channel2 */ + $channel1 = yield $client->channel(); + $channel2 = yield $client->channel(); + + self::assertInstanceOf(Channel::class, $channel1); + self::assertInstanceOf(Channel::class, $channel2); + self::assertNotEquals($channel1->id(), $channel2->id()); + + /** @var Channel $channel3 */ + $channel3 = yield $client->channel(); + + self::assertInstanceOf(Channel::class, $channel3); + self::assertNotEquals($channel1->id(), $channel3->id()); + self::assertNotEquals($channel2->id(), $channel3->id()); + + yield $client->disconnect(); + } + + public function testDisconnectWithBufferedMessages(Client $client): \Generator + { + /** @var Channel $channel */ + $channel = yield $client->channel(); + $count = 0; + + yield $channel->qos(0, 1000); + yield $channel->queueDeclare('disconnect_test', false, false, false, true); + yield $channel->consume(function (Message $message, Channel $channel) use ($client, &$count) { + yield $channel->ack($message); + + self::assertEquals(1, ++$count); + + yield $client->disconnect(); + }, 'disconnect_test'); + + yield $channel->publish('.', '', 'disconnect_test'); + yield $channel->publish('.', '', 'disconnect_test'); + yield $channel->publish('.', '', 'disconnect_test'); + } +} From 06717dae0790c08de0637e1c57dbcd6fa4818e50 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 18:58:50 +0100 Subject: [PATCH 13/58] change tests --- tests/AsyncTest.php | 80 ----- tests/BufferTest.php | 3 +- tests/ChannelTest.php | 669 ++++++++++++++++++++++++++++++++++++ tests/ClientConnectTest.php | 67 ++++ tests/ClientTest.php | 87 +++-- tests/ConfigTest.php | 3 +- tests/RidgeTest.php | 43 --- 7 files changed, 803 insertions(+), 149 deletions(-) delete mode 100644 tests/AsyncTest.php create mode 100644 tests/ChannelTest.php create mode 100644 tests/ClientConnectTest.php delete mode 100644 tests/RidgeTest.php diff --git a/tests/AsyncTest.php b/tests/AsyncTest.php deleted file mode 100644 index 4e723ca..0000000 --- a/tests/AsyncTest.php +++ /dev/null @@ -1,80 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPinnacle\Ridge\Tests; - -use Amp\Loop; -use function Amp\call; - -abstract class AsyncTest extends RidgeTest -{ - /** - * @var string - */ - private $realTestName; - - /** - * @codeCoverageIgnore Invoked before code coverage data is being collected. - * - * @param string $name - */ - public function setName(string $name): void - { - parent::setName($name); - - $this->realTestName = $name; - } - - protected function runTest() - { - parent::setName('runTestAsync'); - - return parent::runTest(); - } - - protected function runTestAsync(...$args) - { - $return = null; - - try { - Loop::run(function () use (&$return, $args) { - $client = self::client(); - - yield $client->connect(); - - \array_unshift($args, $client); - - $return = yield call([$this, $this->realTestName], ...$args); - - $info = Loop::getInfo(); - $count = $info['enabled_watchers']['referenced']; - - if ($count !== 0) { - $message = "Still have {$count} loop watchers."; - - foreach (['defer', 'delay', 'repeat', 'on_readable', 'on_writable'] as $key) { - $message .= " {$key} - {$info[$key]['enabled']}."; - } - - self::markTestIncomplete($message); - - /** @noinspection PhpUnreachableStatementInspection */ - Loop::stop(); - } - }); - } finally { - Loop::set((new Loop\DriverFactory)->create()); - - \gc_collect_cycles(); - } - - return $return; - } -} diff --git a/tests/BufferTest.php b/tests/BufferTest.php index 03ec97c..167f5fc 100644 --- a/tests/BufferTest.php +++ b/tests/BufferTest.php @@ -13,8 +13,9 @@ use PHPinnacle\Ridge\Buffer; use PHPinnacle\Ridge\Exception; +use PHPUnit\Framework\TestCase; -class BufferTest extends RidgeTest +class BufferTest extends TestCase { public function testTimestamp(): void { diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php new file mode 100644 index 0000000..f3560cd --- /dev/null +++ b/tests/ChannelTest.php @@ -0,0 +1,669 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPinnacle\Ridge\Tests; + +use Amp\Deferred; +use Amp\Loop; +use PHPinnacle\Ridge\Channel; +use PHPinnacle\Ridge\Client; +use PHPinnacle\Ridge\Config; +use PHPinnacle\Ridge\Exception; +use PHPinnacle\Ridge\Message; +use PHPinnacle\Ridge\Queue; +use PHPUnit\Framework\TestCase; +use function Amp\call; +use function Amp\Promise\wait; + +class ChannelTest extends TestCase +{ + /** + * @var Client + */ + private $client; + + /** + * @var Channel + */ + private $channel; + + protected function setUp(): void + { + parent::setUp(); + + $this->client = new Client( + Config::parse(\getenv('RIDGE_TEST_DSN')) + ); + + wait($this->client->connect()); + + $this->channel = wait($this->client->channel()); + } + + protected function tearDown(): void + { + parent::tearDown(); + + try + { + wait($this->channel->close()); + } + catch(\Throwable) + { + + } + + wait($this->client->disconnect()); + } + + public function testOpenNotReadyChannel(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->open()); + } + + public function testCloseAlreadyClosedChannel(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->close()); + wait($this->channel->close()); + } + + public function testExchangeDeclare(): void + { + wait( + $this->channel->exchangeDeclare( + 'test_exchange', + 'direct', + false, + false, + true + ) + ); + } + + public function testExchangeDelete(): void + { + wait($this->channel->exchangeDeclare('test_exchange_no_ad')); + wait($this->channel->exchangeDelete('test_exchange_no_ad')); + } + + public function testQueueDeclare(): void + { + /** @var Queue $queue */ + $queue = wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + self::assertInstanceOf(Queue::class, $queue); + self::assertSame('test_queue', $queue->name()); + self::assertSame(0, $queue->messages()); + self::assertSame(0, $queue->consumers()); + } + + public function testQueueBind(): void + { + wait( + $this->channel->exchangeDeclare( + 'test_exchange', + 'direct', + false, + false, + true + ) + ); + + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait($this->channel->queueBind('test_queue', 'test_exchange')); + } + + public function testQueueUnbind(): void + { + wait( + $this->channel->exchangeDeclare( + 'test_exchange', + 'direct', + false, + false, + true + ) + ); + + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait($this->channel->queueBind('test_queue', 'test_exchange')); + wait($this->channel->queueUnbind('test_queue', 'test_exchange')); + } + + public function testQueuePurge(): void + { + wait($this->channel->queueDeclare('test_queue', false, false, false, true)); + wait($this->channel->publish('test', '', 'test_queue')); + wait($this->channel->publish('test', '', 'test_queue')); + + $messages = wait($this->channel->queuePurge('test_queue')); + + self::assertEquals(2, $messages); + } + + public function testQueueDelete(): void + { + wait($this->channel->queueDeclare('test_queue_no_ad')); + wait($this->channel->publish('test', '', 'test_queue_no_ad')); + + $messages = wait($this->channel->queueDelete('test_queue_no_ad')); + + self::assertEquals(1, $messages); + } + + public function testPublish(): void + { + self::assertNull(wait($this->channel->publish('test publish'))); + } + + public function testMandatoryPublish(): void + { + $deferred = new Deferred(); + $watcher = Loop::delay(100, function() use ($deferred) + { + $deferred->resolve(false); + }); + + $this->channel->events()->onReturn( + function(Message $message) use ($deferred, $watcher) + { + self::assertSame($message->content(), '.'); + self::assertSame($message->exchange(), ''); + self::assertSame($message->routingKey(), '404'); + self::assertSame($message->headers(), []); + self::assertNull($message->consumerTag()); + self::assertNull($message->deliveryTag()); + self::assertFalse($message->redelivered()); + self::assertTrue($message->returned()); + + Loop::cancel($watcher); + + $deferred->resolve(true); + } + ); + + wait($this->channel->publish('.', '', '404', [], true)); + + self::assertTrue(wait($deferred->promise()), 'Mandatory return event not received!'); + } + + public function testImmediatePublish(): void + { + $properties = $this->client->properties(); + + // RabbitMQ 3 doesn't support "immediate" publish flag. + if($properties->product() === 'RabbitMQ' && version_compare($properties->version(), '3.0', '>')) + { + return; + } + + $deferred = new Deferred(); + $watcher = Loop::delay(100, function() use ($deferred) + { + $deferred->resolve(false); + }); + + $this->channel->events()->onReturn( + function(Message $message) use ($deferred, $watcher) + { + self::assertTrue($message->returned()); + + Loop::cancel($watcher); + + $deferred->resolve(true); + } + ); + + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'test_queue', [], false, true)); + + self::assertTrue(wait($deferred->promise()), 'Immediate return event not received!'); + } + + public function testConsume(): void + { + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait($this->channel->publish('hi', '', 'test_queue')); + + wait( + $this->channel->consume( + function(Message $message) use (&$tag) + { + self::assertEquals('hi', $message->content()); + self::assertEquals($tag, $message->consumerTag()); + }, + 'test_queue', + false, + true + ) + ); + } + + public function testCancel(): void + { + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait($this->channel->publish('hi', '', 'test_queue')); + + $tag = wait( + $this->channel->consume( + static function(Message $message) + { + }, + 'test_queue', + false, + true + ) + ); + + wait($this->channel->cancel($tag)); + } + + public function testHeaders(): void + { + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait( + $this->channel->publish('hi html', '', 'test_queue', [ + 'content-type' => 'text/html', + 'custom' => 'value', + ]) + ); + + wait( + $this->channel->consume( + function(Message $message) + { + self::assertEquals('text/html', $message->header('content-type')); + self::assertEquals('value', $message->header('custom')); + self::assertEquals('hi html', $message->content()); + + }, + 'test_queue', + false, + true + ) + ); + } + + public function testGet(): void + { + wait( + $this->channel->queueDeclare('get_test', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'get_test')); + + /** @var Message $message1 */ + $message1 = wait($this->channel->get('get_test', true)); + + self::assertNotNull($message1); + self::assertInstanceOf(Message::class, $message1); + self::assertEquals('', $message1->exchange()); + self::assertEquals('.', $message1->content()); + self::assertEquals('get_test', $message1->routingKey()); + self::assertEquals(1, $message1->deliveryTag()); + self::assertNull($message1->consumerTag()); + self::assertFalse($message1->redelivered()); + self::assertIsArray($message1->headers()); + + self::assertNull(wait($this->channel->get('get_test', true))); + + wait($this->channel->publish('..', '', 'get_test')); + + /** @var Message $message2 */ + $message2 = wait($this->channel->get('get_test')); + + self::assertNotNull($message2); + self::assertEquals(2, $message2->deliveryTag()); + self::assertFalse($message2->redelivered()); + + $this->client->disconnect()->onResolve( + function() + { + yield $this->client->connect(); + + /** @var Channel $channel */ + $channel = yield $this->client->channel(); + + /** @var Message $message3 */ + $message3 = yield $channel->get('get_test'); + + self::assertNotNull($message3); + self::assertInstanceOf(Message::class, $message3); + self::assertEquals('', $message3->exchange()); + self::assertEquals('..', $message3->content()); + self::assertTrue($message3->redelivered()); + + yield $channel->ack($message3); + + yield $this->client->disconnect(); + } + ); + } + + public function testAck(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + wait($this->channel->publish('.', '', 'test_queue')); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + wait($this->channel->ack($message)); + } + + public function testNack(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'test_queue')); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertFalse($message->redelivered()); + + wait($this->channel->nack($message)); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertTrue($message->redelivered()); + + wait($this->channel->nack($message, false, false)); + + self::assertNull(wait($this->channel->get('test_queue'))); + + } + + public function testReject(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'test_queue')); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertFalse($message->redelivered()); + + wait($this->channel->reject($message)); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertTrue($message->redelivered()); + + wait($this->channel->reject($message, false)); + + self::assertNull(wait($this->channel->get('test_queue'))); + } + + public function testRecover(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'test_queue')); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertFalse($message->redelivered()); + + wait($this->channel->recover(true)); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertTrue($message->redelivered()); + + wait($this->channel->ack($message)); + } + + public function testBigMessage(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + $body = \str_repeat('a', 10 << 20); // 10 MiB + + wait($this->channel->publish($body, '', 'test_queue')); + + wait( + $this->channel->consume( + function(Message $message, Channel $channel) use ($body) + { + self::assertEquals(\strlen($body), \strlen($message->content())); + + yield $channel->ack($message); + }, + 'test_queue' + ) + ); + } + + public function testGetDouble(): void + { + $this->expectException(Exception\ChannelException::class); + + wait( + $this->channel->queueDeclare( + 'get_test_double', + false, + false, + false, + true + ) + ); + + wait($this->channel->publish('.', '', 'get_test_double')); + + try + { + wait( + call( + function() + { + yield [ + $this->channel->get('get_test_double'), + $this->channel->get('get_test_double'), + ]; + } + ) + ); + } + finally + { + wait($this->channel->queueDelete('get_test_double')); + } + } + + public function testEmptyMessage(): void + { + wait( + $this->channel->queueDeclare( + 'empty_body_message_test', + false, + false, + false, + true + ) + ); + + wait($this->channel->publish('', '', 'empty_body_message_test')); + + /** @var Message $message */ + $message = wait($this->channel->get('empty_body_message_test', true)); + + self::assertNotNull($message); + self::assertEquals('', $message->content()); + + wait($this->channel->publish('', '', 'empty_body_message_test')); + wait($this->channel->publish('', '', 'empty_body_message_test')); + + $count = 0; + + wait( + $this->channel->consume( + function(Message $message, Channel $channel) use (&$count) + { + self::assertEmpty($message->content()); + + yield $channel->ack($message); + + if(++$count === 2) + { + return; + } + }, + 'empty_body_message_test' + ) + ); + + self::assertSame(2, $count); + } + + public function testTxs(): void + { + wait($this->channel->queueDeclare('tx_test', false, false, false, true)); + + wait($this->channel->txSelect()); + wait($this->channel->publish('.', '', 'tx_test')); + wait($this->channel->txCommit()); + + /** @var Message $message */ + $message = wait($this->channel->get('tx_test', true)); + + self::assertNotNull($message); + self::assertInstanceOf(Message::class, $message); + self::assertEquals('.', $message->content()); + + wait($this->channel->publish('..', '', 'tx_test')); + wait($this->channel->txRollback()); + + $nothing = wait($this->channel->get('tx_test', true)); + + self::assertNull($nothing); + } + + public function testTxSelectCannotBeCalledMultipleTimes(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->txSelect()); + wait($this->channel->txSelect()); + } + + public function testTxCommitCannotBeCalledUnderNotTransactionMode(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->txCommit()); + } + + public function testTxRollbackCannotBeCalledUnderNotTransactionMode(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->txRollback()); + } + + public function testConfirmMode(): void + { + $this->channel->events()->onAck( + function(int $deliveryTag, bool $multiple) + { + self::assertEquals(1, $deliveryTag); + self::assertFalse($multiple); + } + ); + + wait($this->channel->confirmSelect()); + + $deliveryTag = wait($this->channel->publish('.')); + + self::assertEquals(1, $deliveryTag); + } +} diff --git a/tests/ClientConnectTest.php b/tests/ClientConnectTest.php new file mode 100644 index 0000000..13dad36 --- /dev/null +++ b/tests/ClientConnectTest.php @@ -0,0 +1,67 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPinnacle\Ridge\Tests; + +use Amp\Loop; +use Amp\Socket\ConnectException; +use PHPinnacle\Ridge\Client; +use PHPinnacle\Ridge\Config; +use PHPUnit\Framework\TestCase; + +class ClientConnectTest extends TestCase +{ + public function testConnect(): void + { + Loop::run( + function() + { + $client = new Client( + Config::parse(\getenv('RIDGE_TEST_DSN')) + ); + + yield $client->connect(); + + self::assertTrue($client->isConnected()); + + yield $client->disconnect(); + } + ); + } + + public function testConnectFailure(): void + { + $this->expectException(ConnectException::class); + + Loop::run( + function() + { + $client = Client::create('amqp://127.0.0.2:5673'); + + yield $client->connect(); + } + ); + } + + public function testConnectAuth() + { + $this->expectException(ConnectException::class); + + Loop::run( + function() + { + $client = new Client(new Config('localhost', 5673, 'testuser', 'testpassword')); + + yield $client->connect(); + yield $client->disconnect(); + } + ); + } +} diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 207dd39..08aeb1c 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -12,57 +12,96 @@ use PHPinnacle\Ridge\Channel; use PHPinnacle\Ridge\Client; +use PHPinnacle\Ridge\Config; use PHPinnacle\Ridge\Message; +use PHPUnit\Framework\TestCase; +use function Amp\Promise\wait; -class ClientTest extends AsyncTest +class ClientTest extends TestCase { - public function testOpenChannel(Client $client): \Generator + /** + * @var Client + */ + private $client; + + protected function setUp(): void + { + parent::setUp(); + + $this->client = new Client( + Config::parse(\getenv('RIDGE_TEST_DSN')) + ); + + wait($this->client->connect()); + } + + protected function tearDown(): void { - self::assertPromise($promise = $client->channel()); - self::assertInstanceOf(Channel::class, yield $promise); + parent::tearDown(); + + wait($this->client->disconnect()); + } - yield $client->disconnect(); + public function testOpenChannel(): void + { + self::assertInstanceOf(Channel::class, wait($this->client->channel())); } - public function testOpenMultipleChannel(Client $client): \Generator + public function testOpenMultipleChannel(): void { /** @var Channel $channel1 */ + $channel1 = wait($this->client->channel()); + /** @var Channel $channel2 */ - $channel1 = yield $client->channel(); - $channel2 = yield $client->channel(); + $channel2 = wait($this->client->channel()); self::assertInstanceOf(Channel::class, $channel1); self::assertInstanceOf(Channel::class, $channel2); self::assertNotEquals($channel1->id(), $channel2->id()); /** @var Channel $channel3 */ - $channel3 = yield $client->channel(); + $channel3 = wait($this->client->channel()); self::assertInstanceOf(Channel::class, $channel3); self::assertNotEquals($channel1->id(), $channel3->id()); self::assertNotEquals($channel2->id(), $channel3->id()); - - yield $client->disconnect(); } - public function testDisconnectWithBufferedMessages(Client $client): \Generator + public function testDisconnectWithBufferedMessages(): void { /** @var Channel $channel */ - $channel = yield $client->channel(); - $count = 0; + $channel = wait($this->client->channel()); + + + wait($channel->qos(0, 1000)); + + wait( + $channel->queueDeclare('disconnect_test', false, false, false, true) + ); + + wait($channel->publish('.', '', 'disconnect_test')); + wait($channel->publish('.', '', 'disconnect_test')); + wait($channel->publish('.', '', 'disconnect_test')); + + $count = 0; - yield $channel->qos(0, 1000); - yield $channel->queueDeclare('disconnect_test', false, false, false, true); - yield $channel->consume(function (Message $message, Channel $channel) use ($client, &$count) { - yield $channel->ack($message); + wait( + $channel->consume( + function(Message $message, Channel $channel) use (&$count) + { + yield $channel->ack($message); - self::assertEquals(1, ++$count); + $count++; - yield $client->disconnect(); - }, 'disconnect_test'); + if($count === 3) + { + return; + } + }, + 'disconnect_test' + ) + ); - yield $channel->publish('.', '', 'disconnect_test'); - yield $channel->publish('.', '', 'disconnect_test'); - yield $channel->publish('.', '', 'disconnect_test'); + self::assertSame(3, $count); } } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 2ac922b..213171c 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -11,8 +11,9 @@ namespace PHPinnacle\Ridge\Tests; use PHPinnacle\Ridge\Config; +use PHPUnit\Framework\TestCase; -class ConfigTest extends RidgeTest +class ConfigTest extends TestCase { public function testCreate(): void { diff --git a/tests/RidgeTest.php b/tests/RidgeTest.php deleted file mode 100644 index 49c7a10..0000000 --- a/tests/RidgeTest.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPinnacle\Ridge\Tests; - -use Amp\Promise; -use PHPinnacle\Ridge\Client; -use PHPinnacle\Ridge\Config; -use PHPUnit\Framework\TestCase; - -abstract class RidgeTest extends TestCase -{ - /** - * @param mixed $value - * - * @return void - */ - protected static function assertPromise(mixed $value): void - { - self::assertInstanceOf(Promise::class, $value); - } - - /** - * @return Client - */ - protected static function client(): Client - { - if (!$dsn = \getenv('RIDGE_TEST_DSN')) { - self::markTestSkipped('No test dsn! Please set RIDGE_TEST_DSN environment variable.'); - } - - $config = Config::parse($dsn); - - return new Client($config); - } -} From 50f3457562f7a7fe4c10bbdc7af85b90ebf8b75b Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:02:41 +0100 Subject: [PATCH 14/58] debug ci --- tests/ChannelTest.php | 669 ------------------------------------------ 1 file changed, 669 deletions(-) delete mode 100644 tests/ChannelTest.php diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php deleted file mode 100644 index f3560cd..0000000 --- a/tests/ChannelTest.php +++ /dev/null @@ -1,669 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPinnacle\Ridge\Tests; - -use Amp\Deferred; -use Amp\Loop; -use PHPinnacle\Ridge\Channel; -use PHPinnacle\Ridge\Client; -use PHPinnacle\Ridge\Config; -use PHPinnacle\Ridge\Exception; -use PHPinnacle\Ridge\Message; -use PHPinnacle\Ridge\Queue; -use PHPUnit\Framework\TestCase; -use function Amp\call; -use function Amp\Promise\wait; - -class ChannelTest extends TestCase -{ - /** - * @var Client - */ - private $client; - - /** - * @var Channel - */ - private $channel; - - protected function setUp(): void - { - parent::setUp(); - - $this->client = new Client( - Config::parse(\getenv('RIDGE_TEST_DSN')) - ); - - wait($this->client->connect()); - - $this->channel = wait($this->client->channel()); - } - - protected function tearDown(): void - { - parent::tearDown(); - - try - { - wait($this->channel->close()); - } - catch(\Throwable) - { - - } - - wait($this->client->disconnect()); - } - - public function testOpenNotReadyChannel(): void - { - $this->expectException(Exception\ChannelException::class); - - wait($this->channel->open()); - } - - public function testCloseAlreadyClosedChannel(): void - { - $this->expectException(Exception\ChannelException::class); - - wait($this->channel->close()); - wait($this->channel->close()); - } - - public function testExchangeDeclare(): void - { - wait( - $this->channel->exchangeDeclare( - 'test_exchange', - 'direct', - false, - false, - true - ) - ); - } - - public function testExchangeDelete(): void - { - wait($this->channel->exchangeDeclare('test_exchange_no_ad')); - wait($this->channel->exchangeDelete('test_exchange_no_ad')); - } - - public function testQueueDeclare(): void - { - /** @var Queue $queue */ - $queue = wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - self::assertInstanceOf(Queue::class, $queue); - self::assertSame('test_queue', $queue->name()); - self::assertSame(0, $queue->messages()); - self::assertSame(0, $queue->consumers()); - } - - public function testQueueBind(): void - { - wait( - $this->channel->exchangeDeclare( - 'test_exchange', - 'direct', - false, - false, - true - ) - ); - - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait($this->channel->queueBind('test_queue', 'test_exchange')); - } - - public function testQueueUnbind(): void - { - wait( - $this->channel->exchangeDeclare( - 'test_exchange', - 'direct', - false, - false, - true - ) - ); - - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait($this->channel->queueBind('test_queue', 'test_exchange')); - wait($this->channel->queueUnbind('test_queue', 'test_exchange')); - } - - public function testQueuePurge(): void - { - wait($this->channel->queueDeclare('test_queue', false, false, false, true)); - wait($this->channel->publish('test', '', 'test_queue')); - wait($this->channel->publish('test', '', 'test_queue')); - - $messages = wait($this->channel->queuePurge('test_queue')); - - self::assertEquals(2, $messages); - } - - public function testQueueDelete(): void - { - wait($this->channel->queueDeclare('test_queue_no_ad')); - wait($this->channel->publish('test', '', 'test_queue_no_ad')); - - $messages = wait($this->channel->queueDelete('test_queue_no_ad')); - - self::assertEquals(1, $messages); - } - - public function testPublish(): void - { - self::assertNull(wait($this->channel->publish('test publish'))); - } - - public function testMandatoryPublish(): void - { - $deferred = new Deferred(); - $watcher = Loop::delay(100, function() use ($deferred) - { - $deferred->resolve(false); - }); - - $this->channel->events()->onReturn( - function(Message $message) use ($deferred, $watcher) - { - self::assertSame($message->content(), '.'); - self::assertSame($message->exchange(), ''); - self::assertSame($message->routingKey(), '404'); - self::assertSame($message->headers(), []); - self::assertNull($message->consumerTag()); - self::assertNull($message->deliveryTag()); - self::assertFalse($message->redelivered()); - self::assertTrue($message->returned()); - - Loop::cancel($watcher); - - $deferred->resolve(true); - } - ); - - wait($this->channel->publish('.', '', '404', [], true)); - - self::assertTrue(wait($deferred->promise()), 'Mandatory return event not received!'); - } - - public function testImmediatePublish(): void - { - $properties = $this->client->properties(); - - // RabbitMQ 3 doesn't support "immediate" publish flag. - if($properties->product() === 'RabbitMQ' && version_compare($properties->version(), '3.0', '>')) - { - return; - } - - $deferred = new Deferred(); - $watcher = Loop::delay(100, function() use ($deferred) - { - $deferred->resolve(false); - }); - - $this->channel->events()->onReturn( - function(Message $message) use ($deferred, $watcher) - { - self::assertTrue($message->returned()); - - Loop::cancel($watcher); - - $deferred->resolve(true); - } - ); - - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); - - wait($this->channel->publish('.', '', 'test_queue', [], false, true)); - - self::assertTrue(wait($deferred->promise()), 'Immediate return event not received!'); - } - - public function testConsume(): void - { - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait($this->channel->publish('hi', '', 'test_queue')); - - wait( - $this->channel->consume( - function(Message $message) use (&$tag) - { - self::assertEquals('hi', $message->content()); - self::assertEquals($tag, $message->consumerTag()); - }, - 'test_queue', - false, - true - ) - ); - } - - public function testCancel(): void - { - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait($this->channel->publish('hi', '', 'test_queue')); - - $tag = wait( - $this->channel->consume( - static function(Message $message) - { - }, - 'test_queue', - false, - true - ) - ); - - wait($this->channel->cancel($tag)); - } - - public function testHeaders(): void - { - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait( - $this->channel->publish('hi html', '', 'test_queue', [ - 'content-type' => 'text/html', - 'custom' => 'value', - ]) - ); - - wait( - $this->channel->consume( - function(Message $message) - { - self::assertEquals('text/html', $message->header('content-type')); - self::assertEquals('value', $message->header('custom')); - self::assertEquals('hi html', $message->content()); - - }, - 'test_queue', - false, - true - ) - ); - } - - public function testGet(): void - { - wait( - $this->channel->queueDeclare('get_test', false, false, false, true) - ); - - wait($this->channel->publish('.', '', 'get_test')); - - /** @var Message $message1 */ - $message1 = wait($this->channel->get('get_test', true)); - - self::assertNotNull($message1); - self::assertInstanceOf(Message::class, $message1); - self::assertEquals('', $message1->exchange()); - self::assertEquals('.', $message1->content()); - self::assertEquals('get_test', $message1->routingKey()); - self::assertEquals(1, $message1->deliveryTag()); - self::assertNull($message1->consumerTag()); - self::assertFalse($message1->redelivered()); - self::assertIsArray($message1->headers()); - - self::assertNull(wait($this->channel->get('get_test', true))); - - wait($this->channel->publish('..', '', 'get_test')); - - /** @var Message $message2 */ - $message2 = wait($this->channel->get('get_test')); - - self::assertNotNull($message2); - self::assertEquals(2, $message2->deliveryTag()); - self::assertFalse($message2->redelivered()); - - $this->client->disconnect()->onResolve( - function() - { - yield $this->client->connect(); - - /** @var Channel $channel */ - $channel = yield $this->client->channel(); - - /** @var Message $message3 */ - $message3 = yield $channel->get('get_test'); - - self::assertNotNull($message3); - self::assertInstanceOf(Message::class, $message3); - self::assertEquals('', $message3->exchange()); - self::assertEquals('..', $message3->content()); - self::assertTrue($message3->redelivered()); - - yield $channel->ack($message3); - - yield $this->client->disconnect(); - } - ); - } - - public function testAck(): void - { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); - wait($this->channel->publish('.', '', 'test_queue')); - - /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); - - wait($this->channel->ack($message)); - } - - public function testNack(): void - { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); - - wait($this->channel->publish('.', '', 'test_queue')); - - /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); - - self::assertNotNull($message); - self::assertFalse($message->redelivered()); - - wait($this->channel->nack($message)); - - /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); - - self::assertNotNull($message); - self::assertTrue($message->redelivered()); - - wait($this->channel->nack($message, false, false)); - - self::assertNull(wait($this->channel->get('test_queue'))); - - } - - public function testReject(): void - { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); - - wait($this->channel->publish('.', '', 'test_queue')); - - /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); - - self::assertNotNull($message); - self::assertFalse($message->redelivered()); - - wait($this->channel->reject($message)); - - /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); - - self::assertNotNull($message); - self::assertTrue($message->redelivered()); - - wait($this->channel->reject($message, false)); - - self::assertNull(wait($this->channel->get('test_queue'))); - } - - public function testRecover(): void - { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); - - wait($this->channel->publish('.', '', 'test_queue')); - - /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); - - self::assertNotNull($message); - self::assertFalse($message->redelivered()); - - wait($this->channel->recover(true)); - - /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); - - self::assertNotNull($message); - self::assertTrue($message->redelivered()); - - wait($this->channel->ack($message)); - } - - public function testBigMessage(): void - { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); - - $body = \str_repeat('a', 10 << 20); // 10 MiB - - wait($this->channel->publish($body, '', 'test_queue')); - - wait( - $this->channel->consume( - function(Message $message, Channel $channel) use ($body) - { - self::assertEquals(\strlen($body), \strlen($message->content())); - - yield $channel->ack($message); - }, - 'test_queue' - ) - ); - } - - public function testGetDouble(): void - { - $this->expectException(Exception\ChannelException::class); - - wait( - $this->channel->queueDeclare( - 'get_test_double', - false, - false, - false, - true - ) - ); - - wait($this->channel->publish('.', '', 'get_test_double')); - - try - { - wait( - call( - function() - { - yield [ - $this->channel->get('get_test_double'), - $this->channel->get('get_test_double'), - ]; - } - ) - ); - } - finally - { - wait($this->channel->queueDelete('get_test_double')); - } - } - - public function testEmptyMessage(): void - { - wait( - $this->channel->queueDeclare( - 'empty_body_message_test', - false, - false, - false, - true - ) - ); - - wait($this->channel->publish('', '', 'empty_body_message_test')); - - /** @var Message $message */ - $message = wait($this->channel->get('empty_body_message_test', true)); - - self::assertNotNull($message); - self::assertEquals('', $message->content()); - - wait($this->channel->publish('', '', 'empty_body_message_test')); - wait($this->channel->publish('', '', 'empty_body_message_test')); - - $count = 0; - - wait( - $this->channel->consume( - function(Message $message, Channel $channel) use (&$count) - { - self::assertEmpty($message->content()); - - yield $channel->ack($message); - - if(++$count === 2) - { - return; - } - }, - 'empty_body_message_test' - ) - ); - - self::assertSame(2, $count); - } - - public function testTxs(): void - { - wait($this->channel->queueDeclare('tx_test', false, false, false, true)); - - wait($this->channel->txSelect()); - wait($this->channel->publish('.', '', 'tx_test')); - wait($this->channel->txCommit()); - - /** @var Message $message */ - $message = wait($this->channel->get('tx_test', true)); - - self::assertNotNull($message); - self::assertInstanceOf(Message::class, $message); - self::assertEquals('.', $message->content()); - - wait($this->channel->publish('..', '', 'tx_test')); - wait($this->channel->txRollback()); - - $nothing = wait($this->channel->get('tx_test', true)); - - self::assertNull($nothing); - } - - public function testTxSelectCannotBeCalledMultipleTimes(): void - { - $this->expectException(Exception\ChannelException::class); - - wait($this->channel->txSelect()); - wait($this->channel->txSelect()); - } - - public function testTxCommitCannotBeCalledUnderNotTransactionMode(): void - { - $this->expectException(Exception\ChannelException::class); - - wait($this->channel->txCommit()); - } - - public function testTxRollbackCannotBeCalledUnderNotTransactionMode(): void - { - $this->expectException(Exception\ChannelException::class); - - wait($this->channel->txRollback()); - } - - public function testConfirmMode(): void - { - $this->channel->events()->onAck( - function(int $deliveryTag, bool $multiple) - { - self::assertEquals(1, $deliveryTag); - self::assertFalse($multiple); - } - ); - - wait($this->channel->confirmSelect()); - - $deliveryTag = wait($this->channel->publish('.')); - - self::assertEquals(1, $deliveryTag); - } -} From a8c01031eed337e200d0179a73346d701d6470a0 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:04:06 +0100 Subject: [PATCH 15/58] debug ci --- tests/ChannelTest.php | 669 ++++++++++++++++++++++++++++++++++++ tests/ClientConnectTest.php | 67 ---- 2 files changed, 669 insertions(+), 67 deletions(-) create mode 100644 tests/ChannelTest.php delete mode 100644 tests/ClientConnectTest.php diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php new file mode 100644 index 0000000..f3560cd --- /dev/null +++ b/tests/ChannelTest.php @@ -0,0 +1,669 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPinnacle\Ridge\Tests; + +use Amp\Deferred; +use Amp\Loop; +use PHPinnacle\Ridge\Channel; +use PHPinnacle\Ridge\Client; +use PHPinnacle\Ridge\Config; +use PHPinnacle\Ridge\Exception; +use PHPinnacle\Ridge\Message; +use PHPinnacle\Ridge\Queue; +use PHPUnit\Framework\TestCase; +use function Amp\call; +use function Amp\Promise\wait; + +class ChannelTest extends TestCase +{ + /** + * @var Client + */ + private $client; + + /** + * @var Channel + */ + private $channel; + + protected function setUp(): void + { + parent::setUp(); + + $this->client = new Client( + Config::parse(\getenv('RIDGE_TEST_DSN')) + ); + + wait($this->client->connect()); + + $this->channel = wait($this->client->channel()); + } + + protected function tearDown(): void + { + parent::tearDown(); + + try + { + wait($this->channel->close()); + } + catch(\Throwable) + { + + } + + wait($this->client->disconnect()); + } + + public function testOpenNotReadyChannel(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->open()); + } + + public function testCloseAlreadyClosedChannel(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->close()); + wait($this->channel->close()); + } + + public function testExchangeDeclare(): void + { + wait( + $this->channel->exchangeDeclare( + 'test_exchange', + 'direct', + false, + false, + true + ) + ); + } + + public function testExchangeDelete(): void + { + wait($this->channel->exchangeDeclare('test_exchange_no_ad')); + wait($this->channel->exchangeDelete('test_exchange_no_ad')); + } + + public function testQueueDeclare(): void + { + /** @var Queue $queue */ + $queue = wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + self::assertInstanceOf(Queue::class, $queue); + self::assertSame('test_queue', $queue->name()); + self::assertSame(0, $queue->messages()); + self::assertSame(0, $queue->consumers()); + } + + public function testQueueBind(): void + { + wait( + $this->channel->exchangeDeclare( + 'test_exchange', + 'direct', + false, + false, + true + ) + ); + + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait($this->channel->queueBind('test_queue', 'test_exchange')); + } + + public function testQueueUnbind(): void + { + wait( + $this->channel->exchangeDeclare( + 'test_exchange', + 'direct', + false, + false, + true + ) + ); + + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait($this->channel->queueBind('test_queue', 'test_exchange')); + wait($this->channel->queueUnbind('test_queue', 'test_exchange')); + } + + public function testQueuePurge(): void + { + wait($this->channel->queueDeclare('test_queue', false, false, false, true)); + wait($this->channel->publish('test', '', 'test_queue')); + wait($this->channel->publish('test', '', 'test_queue')); + + $messages = wait($this->channel->queuePurge('test_queue')); + + self::assertEquals(2, $messages); + } + + public function testQueueDelete(): void + { + wait($this->channel->queueDeclare('test_queue_no_ad')); + wait($this->channel->publish('test', '', 'test_queue_no_ad')); + + $messages = wait($this->channel->queueDelete('test_queue_no_ad')); + + self::assertEquals(1, $messages); + } + + public function testPublish(): void + { + self::assertNull(wait($this->channel->publish('test publish'))); + } + + public function testMandatoryPublish(): void + { + $deferred = new Deferred(); + $watcher = Loop::delay(100, function() use ($deferred) + { + $deferred->resolve(false); + }); + + $this->channel->events()->onReturn( + function(Message $message) use ($deferred, $watcher) + { + self::assertSame($message->content(), '.'); + self::assertSame($message->exchange(), ''); + self::assertSame($message->routingKey(), '404'); + self::assertSame($message->headers(), []); + self::assertNull($message->consumerTag()); + self::assertNull($message->deliveryTag()); + self::assertFalse($message->redelivered()); + self::assertTrue($message->returned()); + + Loop::cancel($watcher); + + $deferred->resolve(true); + } + ); + + wait($this->channel->publish('.', '', '404', [], true)); + + self::assertTrue(wait($deferred->promise()), 'Mandatory return event not received!'); + } + + public function testImmediatePublish(): void + { + $properties = $this->client->properties(); + + // RabbitMQ 3 doesn't support "immediate" publish flag. + if($properties->product() === 'RabbitMQ' && version_compare($properties->version(), '3.0', '>')) + { + return; + } + + $deferred = new Deferred(); + $watcher = Loop::delay(100, function() use ($deferred) + { + $deferred->resolve(false); + }); + + $this->channel->events()->onReturn( + function(Message $message) use ($deferred, $watcher) + { + self::assertTrue($message->returned()); + + Loop::cancel($watcher); + + $deferred->resolve(true); + } + ); + + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'test_queue', [], false, true)); + + self::assertTrue(wait($deferred->promise()), 'Immediate return event not received!'); + } + + public function testConsume(): void + { + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait($this->channel->publish('hi', '', 'test_queue')); + + wait( + $this->channel->consume( + function(Message $message) use (&$tag) + { + self::assertEquals('hi', $message->content()); + self::assertEquals($tag, $message->consumerTag()); + }, + 'test_queue', + false, + true + ) + ); + } + + public function testCancel(): void + { + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait($this->channel->publish('hi', '', 'test_queue')); + + $tag = wait( + $this->channel->consume( + static function(Message $message) + { + }, + 'test_queue', + false, + true + ) + ); + + wait($this->channel->cancel($tag)); + } + + public function testHeaders(): void + { + wait( + $this->channel->queueDeclare( + 'test_queue', + false, + false, + false, + true + ) + ); + + wait( + $this->channel->publish('hi html', '', 'test_queue', [ + 'content-type' => 'text/html', + 'custom' => 'value', + ]) + ); + + wait( + $this->channel->consume( + function(Message $message) + { + self::assertEquals('text/html', $message->header('content-type')); + self::assertEquals('value', $message->header('custom')); + self::assertEquals('hi html', $message->content()); + + }, + 'test_queue', + false, + true + ) + ); + } + + public function testGet(): void + { + wait( + $this->channel->queueDeclare('get_test', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'get_test')); + + /** @var Message $message1 */ + $message1 = wait($this->channel->get('get_test', true)); + + self::assertNotNull($message1); + self::assertInstanceOf(Message::class, $message1); + self::assertEquals('', $message1->exchange()); + self::assertEquals('.', $message1->content()); + self::assertEquals('get_test', $message1->routingKey()); + self::assertEquals(1, $message1->deliveryTag()); + self::assertNull($message1->consumerTag()); + self::assertFalse($message1->redelivered()); + self::assertIsArray($message1->headers()); + + self::assertNull(wait($this->channel->get('get_test', true))); + + wait($this->channel->publish('..', '', 'get_test')); + + /** @var Message $message2 */ + $message2 = wait($this->channel->get('get_test')); + + self::assertNotNull($message2); + self::assertEquals(2, $message2->deliveryTag()); + self::assertFalse($message2->redelivered()); + + $this->client->disconnect()->onResolve( + function() + { + yield $this->client->connect(); + + /** @var Channel $channel */ + $channel = yield $this->client->channel(); + + /** @var Message $message3 */ + $message3 = yield $channel->get('get_test'); + + self::assertNotNull($message3); + self::assertInstanceOf(Message::class, $message3); + self::assertEquals('', $message3->exchange()); + self::assertEquals('..', $message3->content()); + self::assertTrue($message3->redelivered()); + + yield $channel->ack($message3); + + yield $this->client->disconnect(); + } + ); + } + + public function testAck(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + wait($this->channel->publish('.', '', 'test_queue')); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + wait($this->channel->ack($message)); + } + + public function testNack(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'test_queue')); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertFalse($message->redelivered()); + + wait($this->channel->nack($message)); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertTrue($message->redelivered()); + + wait($this->channel->nack($message, false, false)); + + self::assertNull(wait($this->channel->get('test_queue'))); + + } + + public function testReject(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'test_queue')); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertFalse($message->redelivered()); + + wait($this->channel->reject($message)); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertTrue($message->redelivered()); + + wait($this->channel->reject($message, false)); + + self::assertNull(wait($this->channel->get('test_queue'))); + } + + public function testRecover(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + wait($this->channel->publish('.', '', 'test_queue')); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertFalse($message->redelivered()); + + wait($this->channel->recover(true)); + + /** @var Message $message */ + $message = wait($this->channel->get('test_queue')); + + self::assertNotNull($message); + self::assertTrue($message->redelivered()); + + wait($this->channel->ack($message)); + } + + public function testBigMessage(): void + { + wait( + $this->channel->queueDeclare('test_queue', false, false, false, true) + ); + + $body = \str_repeat('a', 10 << 20); // 10 MiB + + wait($this->channel->publish($body, '', 'test_queue')); + + wait( + $this->channel->consume( + function(Message $message, Channel $channel) use ($body) + { + self::assertEquals(\strlen($body), \strlen($message->content())); + + yield $channel->ack($message); + }, + 'test_queue' + ) + ); + } + + public function testGetDouble(): void + { + $this->expectException(Exception\ChannelException::class); + + wait( + $this->channel->queueDeclare( + 'get_test_double', + false, + false, + false, + true + ) + ); + + wait($this->channel->publish('.', '', 'get_test_double')); + + try + { + wait( + call( + function() + { + yield [ + $this->channel->get('get_test_double'), + $this->channel->get('get_test_double'), + ]; + } + ) + ); + } + finally + { + wait($this->channel->queueDelete('get_test_double')); + } + } + + public function testEmptyMessage(): void + { + wait( + $this->channel->queueDeclare( + 'empty_body_message_test', + false, + false, + false, + true + ) + ); + + wait($this->channel->publish('', '', 'empty_body_message_test')); + + /** @var Message $message */ + $message = wait($this->channel->get('empty_body_message_test', true)); + + self::assertNotNull($message); + self::assertEquals('', $message->content()); + + wait($this->channel->publish('', '', 'empty_body_message_test')); + wait($this->channel->publish('', '', 'empty_body_message_test')); + + $count = 0; + + wait( + $this->channel->consume( + function(Message $message, Channel $channel) use (&$count) + { + self::assertEmpty($message->content()); + + yield $channel->ack($message); + + if(++$count === 2) + { + return; + } + }, + 'empty_body_message_test' + ) + ); + + self::assertSame(2, $count); + } + + public function testTxs(): void + { + wait($this->channel->queueDeclare('tx_test', false, false, false, true)); + + wait($this->channel->txSelect()); + wait($this->channel->publish('.', '', 'tx_test')); + wait($this->channel->txCommit()); + + /** @var Message $message */ + $message = wait($this->channel->get('tx_test', true)); + + self::assertNotNull($message); + self::assertInstanceOf(Message::class, $message); + self::assertEquals('.', $message->content()); + + wait($this->channel->publish('..', '', 'tx_test')); + wait($this->channel->txRollback()); + + $nothing = wait($this->channel->get('tx_test', true)); + + self::assertNull($nothing); + } + + public function testTxSelectCannotBeCalledMultipleTimes(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->txSelect()); + wait($this->channel->txSelect()); + } + + public function testTxCommitCannotBeCalledUnderNotTransactionMode(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->txCommit()); + } + + public function testTxRollbackCannotBeCalledUnderNotTransactionMode(): void + { + $this->expectException(Exception\ChannelException::class); + + wait($this->channel->txRollback()); + } + + public function testConfirmMode(): void + { + $this->channel->events()->onAck( + function(int $deliveryTag, bool $multiple) + { + self::assertEquals(1, $deliveryTag); + self::assertFalse($multiple); + } + ); + + wait($this->channel->confirmSelect()); + + $deliveryTag = wait($this->channel->publish('.')); + + self::assertEquals(1, $deliveryTag); + } +} diff --git a/tests/ClientConnectTest.php b/tests/ClientConnectTest.php deleted file mode 100644 index 13dad36..0000000 --- a/tests/ClientConnectTest.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPinnacle\Ridge\Tests; - -use Amp\Loop; -use Amp\Socket\ConnectException; -use PHPinnacle\Ridge\Client; -use PHPinnacle\Ridge\Config; -use PHPUnit\Framework\TestCase; - -class ClientConnectTest extends TestCase -{ - public function testConnect(): void - { - Loop::run( - function() - { - $client = new Client( - Config::parse(\getenv('RIDGE_TEST_DSN')) - ); - - yield $client->connect(); - - self::assertTrue($client->isConnected()); - - yield $client->disconnect(); - } - ); - } - - public function testConnectFailure(): void - { - $this->expectException(ConnectException::class); - - Loop::run( - function() - { - $client = Client::create('amqp://127.0.0.2:5673'); - - yield $client->connect(); - } - ); - } - - public function testConnectAuth() - { - $this->expectException(ConnectException::class); - - Loop::run( - function() - { - $client = new Client(new Config('localhost', 5673, 'testuser', 'testpassword')); - - yield $client->connect(); - yield $client->disconnect(); - } - ); - } -} From a60256f559087a63dd10add873dfc160623a9153 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:10:30 +0100 Subject: [PATCH 16/58] debug ci --- .github/workflows/continuous-integration.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 542d1dc..7b0339a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -56,9 +56,6 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Override PHP ini values for JIT compiler - run: echo "PHP_INI_VALUES::assert.exception=1, zend.assertions=1, opcache.enable=1, opcache.enable_cli=1, opcache.optimization_level=-1, opcache.jit=1255, opcache.jit_buffer_size=32M" >> $GITHUB_ENV - - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: From b3405fa29ef3574915abe3019eca088e3b72181c Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:11:28 +0100 Subject: [PATCH 17/58] debug ci --- .github/workflows/continuous-integration.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7b0339a..a67ecf3 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -49,8 +49,7 @@ jobs: runs-on: ubuntu-latest env: - PHP_EXTENSIONS: dom, json, mbstring, curl, tokenizer - PHP_INI_VALUES: assert.exception=1, zend.assertions=1 + PHP_EXTENSIONS: dom, json, mbstring, tokenizer steps: - name: Checkout @@ -61,7 +60,6 @@ jobs: with: php-version: 8.0 extensions: ${{ env.PHP_EXTENSIONS }} - ini-values: ${{ env.PHP_INI_VALUES }} tools: composer:v2 - name: Install dependencies From 8e985c9f24b46b25c7fe38ae108de4c14f4e740e Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:13:55 +0100 Subject: [PATCH 18/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a67ecf3..44066e8 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -49,7 +49,7 @@ jobs: runs-on: ubuntu-latest env: - PHP_EXTENSIONS: dom, json, mbstring, tokenizer + PHP_EXTENSIONS: dom, json, mbstring steps: - name: Checkout From a0fb82b56752ceb05fe1765a1d938733b65b10c6 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:14:07 +0100 Subject: [PATCH 19/58] debug ci --- tests/ClientConnectTest.php | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/ClientConnectTest.php diff --git a/tests/ClientConnectTest.php b/tests/ClientConnectTest.php new file mode 100644 index 0000000..112648a --- /dev/null +++ b/tests/ClientConnectTest.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPinnacle\Ridge\Tests; + +use Amp\Loop; +use Amp\Socket\ConnectException; +use PHPinnacle\Ridge\Client; +use PHPinnacle\Ridge\Config; +use PHPUnit\Framework\TestCase; +use function Amp\Promise\wait; + +class ClientConnectTest extends TestCase +{ + public function testConnect(): void + { + $client = new Client( + Config::parse(\getenv('RIDGE_TEST_DSN')) + ); + + wait($client->connect()); + + self::assertTrue($client->isConnected()); + + wait($client->disconnect()); + } + + public function testConnectFailure(): void + { + $this->expectException(ConnectException::class); + + $client = Client::create('amqp://127.0.0.2:5673'); + + wait($client->connect()); + } + + public function testConnectAuth() + { + $this->expectException(ConnectException::class); + + $client = new Client(new Config('localhost', 5673, 'testuser', 'testpassword')); + + wait($client->connect()); + wait($client->disconnect()); + } +} From 9e0d6d95ff7d17f5f486f54d4971ce89aaa6222d Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:22:27 +0100 Subject: [PATCH 20/58] debug ci --- .github/workflows/continuous-integration.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 44066e8..5f26b98 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -68,8 +68,6 @@ jobs: - name: Run RabbitMQ uses: getong/rabbitmq-action@v1.2 with: - rabbitmq version: 3.8.2-management-alpine - host port: 5672 rabbitmq user: guest rabbitmq password: guest rabbitmq vhost: / From a168187688824b3be1450f7e1107ff4ea98492c9 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:25:10 +0100 Subject: [PATCH 21/58] debug ci --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index f44f4be..bd713d7 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -15,7 +15,7 @@ - + From 28c6a17577eeba622b228c48ad1f346936c8dbf7 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:31:53 +0100 Subject: [PATCH 22/58] debug ci --- .github/workflows/continuous-integration.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 5f26b98..9c6ac23 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -72,6 +72,9 @@ jobs: rabbitmq password: guest rabbitmq vhost: / + - name: Run docker info + run: docker ps + - name: Run tests with phpunit run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover From 68f8c5aea675fbeb848e1f256d0a99c7a60899f9 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:33:57 +0100 Subject: [PATCH 23/58] debug ci --- .github/workflows/continuous-integration.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9c6ac23..9165c1d 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -72,12 +72,12 @@ jobs: rabbitmq password: guest rabbitmq vhost: / - - name: Run docker info - run: docker ps - - name: Run tests with phpunit run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover + - name: Run docker info + run: docker logs objective_mendeleev + - name: Upload coverage file uses: actions/upload-artifact@v2 with: From 4fc9552a5b0c6a000b9d04ee07821d590d5c97b7 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:38:05 +0100 Subject: [PATCH 24/58] debug ci --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9165c1d..b82b9d8 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -59,7 +59,6 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.0 - extensions: ${{ env.PHP_EXTENSIONS }} tools: composer:v2 - name: Install dependencies From ca031e35b6a34f7004614cf9a9eeb3efbc674a0a Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:42:37 +0100 Subject: [PATCH 25/58] debug ci --- .github/workflows/continuous-integration.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b82b9d8..de9aaa5 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -48,9 +48,6 @@ jobs: runs-on: ubuntu-latest - env: - PHP_EXTENSIONS: dom, json, mbstring - steps: - name: Checkout uses: actions/checkout@v2 @@ -59,10 +56,11 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.0 + coverage: pcov tools: composer:v2 - name: Install dependencies - run: composer update --no-ansi --no-interaction --no-progress --prefer-lowest + run: composer install -ov - name: Run RabbitMQ uses: getong/rabbitmq-action@v1.2 From b06a3891df636655c26e60aefc8c2441dcd752fb Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:48:10 +0100 Subject: [PATCH 26/58] debug ci --- .github/workflows/continuous-integration.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index de9aaa5..cfb21b6 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -48,6 +48,9 @@ jobs: runs-on: ubuntu-latest + env: + PHP_EXTENSIONS: curl, mbstring, dom, intl, json, libxml, xml, xmlwriter, sockets + steps: - name: Checkout uses: actions/checkout@v2 @@ -56,11 +59,11 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.0 - coverage: pcov + extensions: ${{ env.PHP_EXTENSIONS }} tools: composer:v2 - name: Install dependencies - run: composer install -ov + run: composer update -ov - name: Run RabbitMQ uses: getong/rabbitmq-action@v1.2 @@ -72,9 +75,6 @@ jobs: - name: Run tests with phpunit run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover - - name: Run docker info - run: docker logs objective_mendeleev - - name: Upload coverage file uses: actions/upload-artifact@v2 with: From 6627fe60dfed1af3cf9722d3e2cce135db9b25cc Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:50:18 +0100 Subject: [PATCH 27/58] debug ci --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index cfb21b6..c72982c 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -68,6 +68,7 @@ jobs: - name: Run RabbitMQ uses: getong/rabbitmq-action@v1.2 with: + rabbitmq version: '3.8.2-management-alpine' rabbitmq user: guest rabbitmq password: guest rabbitmq vhost: / From eaccf4ba8c9753a984e8b8e3c3f6ca8ac0023ced Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:54:23 +0100 Subject: [PATCH 28/58] debug ci --- .github/workflows/continuous-integration.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c72982c..580fa22 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -67,12 +67,16 @@ jobs: - name: Run RabbitMQ uses: getong/rabbitmq-action@v1.2 + continue-on-error: true with: - rabbitmq version: '3.8.2-management-alpine' + rabbitmq version: 3.8.2-management-alpine rabbitmq user: guest rabbitmq password: guest rabbitmq vhost: / + - name: Docker info + run: docker logs objective_mendeleev + - name: Run tests with phpunit run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover From a2b7832993ad719b3d2301d2a595da78aa53799c Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:56:40 +0100 Subject: [PATCH 29/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 580fa22..e86fa00 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -75,7 +75,7 @@ jobs: rabbitmq vhost: / - name: Docker info - run: docker logs objective_mendeleev + run: docker ps - name: Run tests with phpunit run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover From d9c18127c106a33c35950383431042df7b9f9c68 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 19:58:06 +0100 Subject: [PATCH 30/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e86fa00..9d88ce2 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -75,7 +75,7 @@ jobs: rabbitmq vhost: / - name: Docker info - run: docker ps + run: docker logs hungry_rubin - name: Run tests with phpunit run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover From ed1b8cd8ec1fe52d0a3327a043ca885a5c5fbe03 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:03:02 +0100 Subject: [PATCH 31/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9d88ce2..b09a636 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -75,7 +75,7 @@ jobs: rabbitmq vhost: / - name: Docker info - run: docker logs hungry_rubin + run: docker logs $(docker ps --format "{{.Names}}") - name: Run tests with phpunit run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover From d8047cfd773933b48c9191a0aee76fa8946ffe29 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:03:35 +0100 Subject: [PATCH 32/58] debug ci --- .github/workflows/continuous-integration.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b09a636..a4fa2a9 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -74,12 +74,12 @@ jobs: rabbitmq password: guest rabbitmq vhost: / - - name: Docker info - run: docker logs $(docker ps --format "{{.Names}}") - - name: Run tests with phpunit run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover + - name: Docker info + run: docker logs $(docker ps --format "{{.Names}}") + - name: Upload coverage file uses: actions/upload-artifact@v2 with: From 6ca25de5d4fb4a06679f949ffe6fbb4cf96f73b3 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:04:50 +0100 Subject: [PATCH 33/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a4fa2a9..7c0aa0a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -67,7 +67,6 @@ jobs: - name: Run RabbitMQ uses: getong/rabbitmq-action@v1.2 - continue-on-error: true with: rabbitmq version: 3.8.2-management-alpine rabbitmq user: guest @@ -75,6 +74,7 @@ jobs: rabbitmq vhost: / - name: Run tests with phpunit + continue-on-error: true run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover - name: Docker info From 49c9956352a750f20feac4b7cb35863d7c4b2c00 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:10:54 +0100 Subject: [PATCH 34/58] debug ci --- .github/workflows/continuous-integration.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7c0aa0a..89fa86d 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -73,12 +73,12 @@ jobs: rabbitmq password: guest rabbitmq vhost: / + - name: Set RabbitMQ URL in environment + run: echo "RIDGE_TEST_DSN=amqp://guest:guest@127.0.0.1:5672/?heartbeat=0" >> $GITHUB_ENV + - name: Run tests with phpunit continue-on-error: true - run: php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover - - - name: Docker info - run: docker logs $(docker ps --format "{{.Names}}") + run: php ./vendor/bin/phpunit --coverage-clover=coverage.clover - name: Upload coverage file uses: actions/upload-artifact@v2 From a895388799ecba7f5aa5ca3a098e72639d1d611e Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:13:00 +0100 Subject: [PATCH 35/58] debug ci --- .github/workflows/continuous-integration.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 89fa86d..42b41b5 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -74,10 +74,9 @@ jobs: rabbitmq vhost: / - name: Set RabbitMQ URL in environment - run: echo "RIDGE_TEST_DSN=amqp://guest:guest@127.0.0.1:5672/?heartbeat=0" >> $GITHUB_ENV + run: echo "RIDGE_TEST_DSN=amqp://guest:guest@127.0.0.1:5672//?heartbeat=0" >> $GITHUB_ENV - name: Run tests with phpunit - continue-on-error: true run: php ./vendor/bin/phpunit --coverage-clover=coverage.clover - name: Upload coverage file From bc5b67ad8ce4b46c2e553d5642d538dbb2915ed0 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:14:04 +0100 Subject: [PATCH 36/58] debug ci --- .github/workflows/continuous-integration.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 42b41b5..838a5aa 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -79,6 +79,10 @@ jobs: - name: Run tests with phpunit run: php ./vendor/bin/phpunit --coverage-clover=coverage.clover + - name: Send code coverage report to Scrutinizer + run: | + docker logs $(docker ps --format "{{.Names}}") + - name: Upload coverage file uses: actions/upload-artifact@v2 with: From edc00e672bf3946ca1772a6984d9dabf782d3bdd Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:15:59 +0100 Subject: [PATCH 37/58] debug ci --- .github/workflows/continuous-integration.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 838a5aa..114c191 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -77,9 +77,10 @@ jobs: run: echo "RIDGE_TEST_DSN=amqp://guest:guest@127.0.0.1:5672//?heartbeat=0" >> $GITHUB_ENV - name: Run tests with phpunit - run: php ./vendor/bin/phpunit --coverage-clover=coverage.clover + continue-on-error: true + run: php ./vendor/bin/phpunit --coverage-clover=coverage.clover && docker logs $(docker ps --format "{{.Names}}") - - name: Send code coverage report to Scrutinizer + - name: Info run: | docker logs $(docker ps --format "{{.Names}}") From 0a7380af4c19670b284e4c6523dee349ccd8d0d3 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:19:33 +0100 Subject: [PATCH 38/58] debug ci --- .github/workflows/continuous-integration.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 114c191..2f41846 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -73,16 +73,8 @@ jobs: rabbitmq password: guest rabbitmq vhost: / - - name: Set RabbitMQ URL in environment - run: echo "RIDGE_TEST_DSN=amqp://guest:guest@127.0.0.1:5672//?heartbeat=0" >> $GITHUB_ENV - - name: Run tests with phpunit - continue-on-error: true - run: php ./vendor/bin/phpunit --coverage-clover=coverage.clover && docker logs $(docker ps --format "{{.Names}}") - - - name: Info - run: | - docker logs $(docker ps --format "{{.Names}}") + run: RIDGE_TEST_DSN=amqp://guest:guest@127.0.0.1:5672//?heartbeat=0 ./vendor/bin/phpunit - name: Upload coverage file uses: actions/upload-artifact@v2 From 73772c8562a99e5267a4fcc7e3ca7ccfde0b497a Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:21:34 +0100 Subject: [PATCH 39/58] debug ci --- .github/workflows/continuous-integration.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 2f41846..4eb12bf 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -69,12 +69,12 @@ jobs: uses: getong/rabbitmq-action@v1.2 with: rabbitmq version: 3.8.2-management-alpine - rabbitmq user: guest - rabbitmq password: guest - rabbitmq vhost: / + rabbitmq user: admin + rabbitmq password: password + rabbitmq vhost: vhost_name - name: Run tests with phpunit - run: RIDGE_TEST_DSN=amqp://guest:guest@127.0.0.1:5672//?heartbeat=0 ./vendor/bin/phpunit + run: RIDGE_TEST_DSN=amqp://admin:password@127.0.0.1:5672/vhost_name?heartbeat=0 ./vendor/bin/phpunit - name: Upload coverage file uses: actions/upload-artifact@v2 From 02562399112204adc5bb3cabf4db978939200530 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:24:19 +0100 Subject: [PATCH 40/58] debug ci --- tests/ChannelTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index f3560cd..b466e0c 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -62,6 +62,8 @@ protected function tearDown(): void } wait($this->client->disconnect()); + + var_export(shell_exec('docker logs $(docker ps --format "{{.Names}}")')); } public function testOpenNotReadyChannel(): void From 66e57ce44474289f83a73d0d0c18b249383870de Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:26:24 +0100 Subject: [PATCH 41/58] debug ci --- tests/ChannelTest.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index b466e0c..f756649 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -39,13 +39,20 @@ protected function setUp(): void { parent::setUp(); - $this->client = new Client( - Config::parse(\getenv('RIDGE_TEST_DSN')) - ); + try + { + $this->client = new Client( + Config::parse(\getenv('RIDGE_TEST_DSN')) + ); - wait($this->client->connect()); + wait($this->client->connect()); - $this->channel = wait($this->client->channel()); + $this->channel = wait($this->client->channel()); + } + finally + { + var_export(shell_exec('docker logs $(docker ps --format "{{.Names}}")')); + } } protected function tearDown(): void @@ -62,8 +69,6 @@ protected function tearDown(): void } wait($this->client->disconnect()); - - var_export(shell_exec('docker logs $(docker ps --format "{{.Names}}")')); } public function testOpenNotReadyChannel(): void From dc4b237d41c38f3f9ffb56484632e86012a2fe16 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:32:53 +0100 Subject: [PATCH 42/58] debug ci --- .github/workflows/continuous-integration.yml | 8 +++++--- phpunit.xml | 2 +- tests/ChannelTest.php | 17 +++++------------ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 4eb12bf..e39abd7 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -49,7 +49,8 @@ jobs: runs-on: ubuntu-latest env: - PHP_EXTENSIONS: curl, mbstring, dom, intl, json, libxml, xml, xmlwriter, sockets + PHP_EXTENSIONS: mbstring, dom, intl, json, libxml, xml, xmlwriter, sockets + PHP_INI_VALUES: assert.exception=1, zend.assertions=1 steps: - name: Checkout @@ -60,6 +61,7 @@ jobs: with: php-version: 8.0 extensions: ${{ env.PHP_EXTENSIONS }} + ini-values: ${{ env.PHP_INI_VALUES }} tools: composer:v2 - name: Install dependencies @@ -71,10 +73,10 @@ jobs: rabbitmq version: 3.8.2-management-alpine rabbitmq user: admin rabbitmq password: password - rabbitmq vhost: vhost_name + rabbitmq vhost: vhost - name: Run tests with phpunit - run: RIDGE_TEST_DSN=amqp://admin:password@127.0.0.1:5672/vhost_name?heartbeat=0 ./vendor/bin/phpunit + run: XDEBUG_MODE=coverage RIDGE_TEST_DSN=amqp://admin:password@127.0.0.1:5672/vhost?heartbeat=0 ./vendor/bin/phpunit --coverage-clover=coverage.clover - name: Upload coverage file uses: actions/upload-artifact@v2 diff --git a/phpunit.xml b/phpunit.xml index bd713d7..49cb4fc 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -15,7 +15,7 @@ - + diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index f756649..f3560cd 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -39,20 +39,13 @@ protected function setUp(): void { parent::setUp(); - try - { - $this->client = new Client( - Config::parse(\getenv('RIDGE_TEST_DSN')) - ); + $this->client = new Client( + Config::parse(\getenv('RIDGE_TEST_DSN')) + ); - wait($this->client->connect()); + wait($this->client->connect()); - $this->channel = wait($this->client->channel()); - } - finally - { - var_export(shell_exec('docker logs $(docker ps --format "{{.Names}}")')); - } + $this->channel = wait($this->client->channel()); } protected function tearDown(): void From 18810117a0fa3ec2e8338c7cdb2798f90bcadbab Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:41:33 +0100 Subject: [PATCH 43/58] debug ci --- src/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Connection.php b/src/Connection.php index ae26edc..be00505 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -169,7 +169,7 @@ function() } } - $this->socket = null; + //$this->socket = null; } ); } From 9d38ceddb0ba4aa20ca34fbe191cc3b67b831471 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:42:17 +0100 Subject: [PATCH 44/58] debug ci --- src/Client.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Client.php b/src/Client.php index 1d63099..9f76b27 100644 --- a/src/Client.php +++ b/src/Client.php @@ -119,22 +119,24 @@ function() yield $this->connectionTune(); yield $this->connectionOpen(); - asyncCall(function() - { - yield $this->await(Protocol\ConnectionCloseFrame::class); - - $buffer = new Buffer; - $buffer - ->appendUint8(1) - ->appendUint16(0) - ->appendUint32(4) - ->appendUint16(10) - ->appendUint16(51) - ->appendUint8(206); - - $this->connection->write($buffer); - $this->connection->close(); - }); + asyncCall( + function() + { + yield $this->await(Protocol\ConnectionCloseFrame::class); + + $buffer = new Buffer; + $buffer + ->appendUint8(1) + ->appendUint16(0) + ->appendUint32(4) + ->appendUint16(10) + ->appendUint16(51) + ->appendUint8(206); + + $this->connection->write($buffer); + $this->connection->close(); + } + ); $this->state = self::STATE_CONNECTED; } From 74d411bf42f154a303a4ff934d56a0f180ac4ff4 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:45:13 +0100 Subject: [PATCH 45/58] debug ci --- src/Connection.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index be00505..38f49f7 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -159,9 +159,7 @@ function() */ foreach($this->callbacks[(int) $frame->channel][$class] ?? [] as $i => $callback) { - $result = yield call($callback, $frame); - - if($result) + if(yield call($callback, $frame)) { unset($this->callbacks[(int) $frame->channel][$class][$i]); } @@ -169,7 +167,7 @@ function() } } - //$this->socket = null; + $this->socket = null; } ); } From 5d5c1bb874c55cb90f0dd89f44b17464975e30f6 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:46:57 +0100 Subject: [PATCH 46/58] debug ci --- src/Client.php | 12 ++++++------ src/Connection.php | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Client.php b/src/Client.php index 9f76b27..e6360ea 100644 --- a/src/Client.php +++ b/src/Client.php @@ -306,11 +306,11 @@ function() /** @var Protocol\ConnectionTuneFrame $tune */ $tune = yield $this->await(Protocol\ConnectionTuneFrame::class); - $heartbeat = $this->config->heartbeat; + $heartbeatInterval = $this->config->heartbeat; - if($heartbeat !== 0) + if($heartbeatInterval !== 0) { - $heartbeat = \min($heartbeat, $tune->heartbeat); + $heartbeatInterval = \min($heartbeatInterval, $tune->heartbeat); } $maxChannel = \min($this->config->maxChannel, $tune->channelMax); @@ -325,16 +325,16 @@ function() ->appendUint16(31) ->appendInt16($maxChannel) ->appendInt32($maxFrame) - ->appendInt16($heartbeat) + ->appendInt16($heartbeatInterval) ->appendUint8(206); yield $this->connection->write($buffer); $this->properties->tune($maxChannel, $maxFrame); - if($heartbeat > 0) + if($heartbeatInterval > 0) { - $this->connection->heartbeat($heartbeat); + $this->connection->heartbeat($heartbeatInterval); } } ); diff --git a/src/Connection.php b/src/Connection.php index 38f49f7..a968888 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -176,11 +176,9 @@ function() public function heartbeat(int $interval): void { - $milliseconds = $interval * 1000; - $this->heartbeatWatcherId = Loop::repeat( - $milliseconds, - function(string $watcherId) use ($milliseconds) + $interval, + function(string $watcherId) use ($interval) { if($this->socket === null) { @@ -192,8 +190,7 @@ function(string $watcherId) use ($milliseconds) $currentTime = Loop::now(); $lastWrite = $this->lastWrite ?: $currentTime; - /** @var int $nextHeartbeat */ - $nextHeartbeat = $lastWrite + $milliseconds; + $nextHeartbeat = $lastWrite + $interval; if($currentTime >= $nextHeartbeat) { From 2aaf44ab680c3fd8996a9640421744ecca704637 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 20:51:33 +0100 Subject: [PATCH 47/58] debug ci --- tests/ChannelTest.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index f3560cd..46e5f71 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -66,17 +66,23 @@ protected function tearDown(): void public function testOpenNotReadyChannel(): void { + /** @var Channel $channel */ + $channel = wait($this->client->channel()); + $this->expectException(Exception\ChannelException::class); - wait($this->channel->open()); + wait($channel->open()); } public function testCloseAlreadyClosedChannel(): void { + /** @var Channel $channel */ + $channel = wait($this->client->channel()); + $this->expectException(Exception\ChannelException::class); - wait($this->channel->close()); - wait($this->channel->close()); + wait($channel->close()); + wait($channel->close()); } public function testExchangeDeclare(): void From 3f49c0609ac89d0c78a4f32b091b2341a91df04b Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 21:39:24 +0100 Subject: [PATCH 48/58] debug ci --- src/Client.php | 13 +++++-------- tests/ChannelTest.php | 4 ++++ tests/ClientConnectTest.php | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Client.php b/src/Client.php index e6360ea..e0238c2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -19,11 +19,10 @@ final class Client { - private const - STATE_NOT_CONNECTED = 0, - STATE_CONNECTING = 1, - STATE_CONNECTED = 2, - STATE_DISCONNECTING = 3; + private const STATE_NOT_CONNECTED = 0; + private const STATE_CONNECTING = 1; + private const STATE_CONNECTED = 2; + private const STATE_DISCONNECTING = 3; /** * @var Config @@ -97,10 +96,8 @@ function() $this->connection = new Connection($this->config->uri()); - $timeout = $this->config->timeout; - yield $this->connection->open( - $timeout, + $this->config->timeout, $this->config->tcpAttempts, $this->config->tcpNoDelay ); diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index 46e5f71..b35a374 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -39,6 +39,8 @@ protected function setUp(): void { parent::setUp(); + Loop::run(); + $this->client = new Client( Config::parse(\getenv('RIDGE_TEST_DSN')) ); @@ -62,6 +64,8 @@ protected function tearDown(): void } wait($this->client->disconnect()); + + Loop::stop(); } public function testOpenNotReadyChannel(): void diff --git a/tests/ClientConnectTest.php b/tests/ClientConnectTest.php index 112648a..d6e2f6b 100644 --- a/tests/ClientConnectTest.php +++ b/tests/ClientConnectTest.php @@ -19,6 +19,20 @@ class ClientConnectTest extends TestCase { + protected function setUp(): void + { + parent::setUp(); + + Loop::run(); + } + + protected function tearDown(): void + { + parent::tearDown(); + + Loop::stop(); + } + public function testConnect(): void { $client = new Client( From c738108034d2f245ca2487d05037674bafd817d1 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 21:43:49 +0100 Subject: [PATCH 49/58] debug ci --- tests/ClientTest.php | 107 ------------------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 tests/ClientTest.php diff --git a/tests/ClientTest.php b/tests/ClientTest.php deleted file mode 100644 index 08aeb1c..0000000 --- a/tests/ClientTest.php +++ /dev/null @@ -1,107 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPinnacle\Ridge\Tests; - -use PHPinnacle\Ridge\Channel; -use PHPinnacle\Ridge\Client; -use PHPinnacle\Ridge\Config; -use PHPinnacle\Ridge\Message; -use PHPUnit\Framework\TestCase; -use function Amp\Promise\wait; - -class ClientTest extends TestCase -{ - /** - * @var Client - */ - private $client; - - protected function setUp(): void - { - parent::setUp(); - - $this->client = new Client( - Config::parse(\getenv('RIDGE_TEST_DSN')) - ); - - wait($this->client->connect()); - } - - protected function tearDown(): void - { - parent::tearDown(); - - wait($this->client->disconnect()); - } - - public function testOpenChannel(): void - { - self::assertInstanceOf(Channel::class, wait($this->client->channel())); - } - - public function testOpenMultipleChannel(): void - { - /** @var Channel $channel1 */ - $channel1 = wait($this->client->channel()); - - /** @var Channel $channel2 */ - $channel2 = wait($this->client->channel()); - - self::assertInstanceOf(Channel::class, $channel1); - self::assertInstanceOf(Channel::class, $channel2); - self::assertNotEquals($channel1->id(), $channel2->id()); - - /** @var Channel $channel3 */ - $channel3 = wait($this->client->channel()); - - self::assertInstanceOf(Channel::class, $channel3); - self::assertNotEquals($channel1->id(), $channel3->id()); - self::assertNotEquals($channel2->id(), $channel3->id()); - } - - public function testDisconnectWithBufferedMessages(): void - { - /** @var Channel $channel */ - $channel = wait($this->client->channel()); - - - wait($channel->qos(0, 1000)); - - wait( - $channel->queueDeclare('disconnect_test', false, false, false, true) - ); - - wait($channel->publish('.', '', 'disconnect_test')); - wait($channel->publish('.', '', 'disconnect_test')); - wait($channel->publish('.', '', 'disconnect_test')); - - $count = 0; - - wait( - $channel->consume( - function(Message $message, Channel $channel) use (&$count) - { - yield $channel->ack($message); - - $count++; - - if($count === 3) - { - return; - } - }, - 'disconnect_test' - ) - ); - - self::assertSame(3, $count); - } -} From cc36207971522ca2b158bc3d95b9c79098091331 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 21:55:25 +0100 Subject: [PATCH 50/58] debug ci --- tests/AsyncTest.php | 79 ++++ tests/BufferTest.php | 26 +- tests/ChannelTest.php | 817 ++++++++++++++++++------------------ tests/ClientConnectTest.php | 68 ++- tests/ClientTest.php | 68 +++ tests/ConfigTest.php | 11 +- tests/RidgeTest.php | 44 ++ 7 files changed, 636 insertions(+), 477 deletions(-) create mode 100644 tests/AsyncTest.php create mode 100644 tests/ClientTest.php create mode 100644 tests/RidgeTest.php diff --git a/tests/AsyncTest.php b/tests/AsyncTest.php new file mode 100644 index 0000000..ab00366 --- /dev/null +++ b/tests/AsyncTest.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPinnacle\Ridge\Tests; + +use Amp\Loop; +use function Amp\call; + +abstract class AsyncTest extends RidgeTest +{ + /** + * @var string + */ + private $realTestName; + + /** + * @codeCoverageIgnore Invoked before code coverage data is being collected. + * + * @param string $name + */ + public function setName(string $name): void + { + parent::setName($name); + + $this->realTestName = $name; + } + + protected function runTest() + { + parent::setName('runTestAsync'); + + return parent::runTest(); + } + + protected function runTestAsync(...$args) + { + $return = null; + + try { + Loop::run(function () use (&$return, $args) { + $client = self::client(); + + yield $client->connect(); + + \array_unshift($args, $client); + + $return = yield call([$this, $this->realTestName], ...$args); + + $info = Loop::getInfo(); + $count = $info['enabled_watchers']['referenced']; + + if ($count !== 0) { + $message = "Still have {$count} loop watchers."; + + foreach (['defer', 'delay', 'repeat', 'on_readable', 'on_writable'] as $key) { + $message .= " {$key} - {$info[$key]['enabled']}."; + } + + self::markTestIncomplete($message); + + Loop::stop(); + } + }); + } finally { + Loop::set((new Loop\DriverFactory)->create()); + + \gc_collect_cycles(); + } + + return $return; + } +} diff --git a/tests/BufferTest.php b/tests/BufferTest.php index 167f5fc..115fbca 100644 --- a/tests/BufferTest.php +++ b/tests/BufferTest.php @@ -1,5 +1,4 @@ -getTimestamp(), $buffer->consumeTimestamp()->getTimestamp()); } - public function testString(): void + public function testString() { $buffer = new Buffer; @@ -34,7 +32,7 @@ public function testString(): void self::assertSame('abcd', $buffer->consumeString()); } - public function testText(): void + public function testText() { $buffer = new Buffer; @@ -42,7 +40,7 @@ public function testText(): void self::assertSame('abcd', $buffer->consumeText()); } - public function testArray(): void + public function testArray() { $buffer = new Buffer; $array = [1, 'a', null, true, M_PI, [2], ['a' => 'b'], \DateTime::createFromFormat('m/d/Y', '1/1/1970')]; @@ -51,9 +49,9 @@ public function testArray(): void self::assertEquals($array, $buffer->consumeArray()); } - public function testArrayWithUnknownField(): void + public function testArrayWithUnknownField() { - $this->expectException(Exception\ProtocolException::class); + self::expectException(Exception\ProtocolException::class); $buffer = new Buffer; $table = [ @@ -65,7 +63,7 @@ public function testArrayWithUnknownField(): void $buffer->appendArray($table); } - public function testTable(): void + public function testTable() { $buffer = new Buffer; $table = [ @@ -84,9 +82,9 @@ public function testTable(): void self::assertEquals($table, $buffer->consumeTable()); } - public function testTableWithUnknownField(): void + public function testTableWithUnknownField() { - $this->expectException(Exception\ProtocolException::class); + self::expectException(Exception\ProtocolException::class); $buffer = new Buffer; $table = [ @@ -98,7 +96,7 @@ public function testTableWithUnknownField(): void $buffer->appendTable($table); } - public function testBits(): void + public function testBits() { $buffer = new Buffer; $bits = [true, false, true]; diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index b35a374..062c229 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -1,5 +1,4 @@ -channel(); - Loop::run(); + $promise = $channel->open(); - $this->client = new Client( - Config::parse(\getenv('RIDGE_TEST_DSN')) - ); + self::assertPromise($promise); - wait($this->client->connect()); + yield $promise; - $this->channel = wait($this->client->channel()); + yield $client->disconnect(); } - protected function tearDown(): void + public function testClose(Client $client) { - parent::tearDown(); + /** @var Channel $channel */ + $channel = yield $client->channel(); - try - { - wait($this->channel->close()); - } - catch(\Throwable) - { + $promise = $channel->close(); - } + self::assertPromise($promise); - wait($this->client->disconnect()); + yield $promise; - Loop::stop(); + yield $client->disconnect(); } - public function testOpenNotReadyChannel(): void + public function testCloseAlreadyClosedChannel(Client $client) { - /** @var Channel $channel */ - $channel = wait($this->client->channel()); + self::expectException(Exception\ChannelException::class); - $this->expectException(Exception\ChannelException::class); + /** @var Channel $channel */ + $channel = yield $client->channel(); - wait($channel->open()); + try { + yield $channel->close(); + yield $channel->close(); + } finally { + yield $client->disconnect(); + } } - public function testCloseAlreadyClosedChannel(): void + public function testExchangeDeclare(Client $client) { /** @var Channel $channel */ - $channel = wait($this->client->channel()); + $channel = yield $client->channel(); - $this->expectException(Exception\ChannelException::class); + $promise = $channel->exchangeDeclare('test_exchange', 'direct', false, false, true); - wait($channel->close()); - wait($channel->close()); - } + self::assertPromise($promise); - public function testExchangeDeclare(): void - { - wait( - $this->channel->exchangeDeclare( - 'test_exchange', - 'direct', - false, - false, - true - ) - ); + yield $promise; + + yield $client->disconnect(); } - public function testExchangeDelete(): void + public function testExchangeDelete(Client $client) { - wait($this->channel->exchangeDeclare('test_exchange_no_ad')); - wait($this->channel->exchangeDelete('test_exchange_no_ad')); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->exchangeDeclare('test_exchange_no_ad', 'direct'); + + $promise = $channel->exchangeDelete('test_exchange_no_ad'); + + self::assertPromise($promise); + + yield $promise; + + yield $client->disconnect(); } - public function testQueueDeclare(): void + public function testQueueDeclare(Client $client) { + /** @var Channel $channel */ + $channel = yield $client->channel(); + + $promise = $channel->queueDeclare('test_queue', false, false, false, true); + + self::assertPromise($promise); + /** @var Queue $queue */ - $queue = wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); + $queue = yield $promise; self::assertInstanceOf(Queue::class, $queue); self::assertSame('test_queue', $queue->name()); self::assertSame(0, $queue->messages()); self::assertSame(0, $queue->consumers()); + + yield $client->disconnect(); } - public function testQueueBind(): void + public function testQueueBind(Client $client) { - wait( - $this->channel->exchangeDeclare( - 'test_exchange', - 'direct', - false, - false, - true - ) - ); - - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait($this->channel->queueBind('test_queue', 'test_exchange')); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->exchangeDeclare('test_exchange', 'direct', false, false, true); + yield $channel->queueDeclare('test_queue', false, false, false, true); + + $promise = $channel->queueBind('test_queue', 'test_exchange'); + + self::assertPromise($promise); + + yield $promise; + + yield $client->disconnect(); } - public function testQueueUnbind(): void + public function testQueueUnbind(Client $client) { - wait( - $this->channel->exchangeDeclare( - 'test_exchange', - 'direct', - false, - false, - true - ) - ); - - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait($this->channel->queueBind('test_queue', 'test_exchange')); - wait($this->channel->queueUnbind('test_queue', 'test_exchange')); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->exchangeDeclare('test_exchange', 'direct', false, false, true); + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->queueBind('test_queue', 'test_exchange'); + + $promise = $channel->queueUnbind('test_queue', 'test_exchange'); + + self::assertPromise($promise); + + yield $promise; + + yield $client->disconnect(); } - public function testQueuePurge(): void + public function testQueuePurge(Client $client) { - wait($this->channel->queueDeclare('test_queue', false, false, false, true)); - wait($this->channel->publish('test', '', 'test_queue')); - wait($this->channel->publish('test', '', 'test_queue')); + /** @var Channel $channel */ + $channel = yield $client->channel(); - $messages = wait($this->channel->queuePurge('test_queue')); + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->publish('test', '', 'test_queue'); + yield $channel->publish('test', '', 'test_queue'); + $promise = $channel->queuePurge('test_queue'); + + $messages = yield $promise; + + self::assertPromise($promise); self::assertEquals(2, $messages); + + yield $client->disconnect(); } - public function testQueueDelete(): void + public function testQueueDelete(Client $client) { - wait($this->channel->queueDeclare('test_queue_no_ad')); - wait($this->channel->publish('test', '', 'test_queue_no_ad')); + /** @var Channel $channel */ + $channel = yield $client->channel(); - $messages = wait($this->channel->queueDelete('test_queue_no_ad')); + yield $channel->queueDeclare('test_queue_no_ad'); + yield $channel->publish('test', '', 'test_queue_no_ad'); + $promise = $channel->queueDelete('test_queue_no_ad'); + + $messages = yield $promise; + + self::assertPromise($promise); self::assertEquals(1, $messages); + + yield $client->disconnect(); } - public function testPublish(): void + public function testPublish(Client $client) { - self::assertNull(wait($this->channel->publish('test publish'))); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + $promise = $channel->publish('test publish'); + + self::assertPromise($promise); + self::assertNull(yield $promise); + + yield $client->disconnect(); } - public function testMandatoryPublish(): void + public function testMandatoryPublish(Client $client) { + /** @var Channel $channel */ + $channel = yield $client->channel(); + $deferred = new Deferred(); - $watcher = Loop::delay(100, function() use ($deferred) - { + $watcher = Loop::delay(100, function () use ($deferred) { $deferred->resolve(false); }); - $this->channel->events()->onReturn( - function(Message $message) use ($deferred, $watcher) - { - self::assertSame($message->content(), '.'); - self::assertSame($message->exchange(), ''); - self::assertSame($message->routingKey(), '404'); - self::assertSame($message->headers(), []); - self::assertNull($message->consumerTag()); - self::assertNull($message->deliveryTag()); - self::assertFalse($message->redelivered()); - self::assertTrue($message->returned()); - - Loop::cancel($watcher); - - $deferred->resolve(true); - } - ); + $channel->events()->onReturn(function (Message $message) use ($deferred, $watcher) { + self::assertSame($message->content(), '.'); + self::assertSame($message->exchange(), ''); + self::assertSame($message->routingKey(), '404'); + self::assertSame($message->headers(), []); + self::assertNull($message->consumerTag()); + self::assertNull($message->deliveryTag()); + self::assertFalse($message->redelivered()); + self::assertTrue($message->returned()); - wait($this->channel->publish('.', '', '404', [], true)); + Loop::cancel($watcher); - self::assertTrue(wait($deferred->promise()), 'Mandatory return event not received!'); + $deferred->resolve(true); + }); + + yield $channel->publish('.', '', '404', [], true); + + self::assertTrue(yield $deferred->promise(), 'Mandatory return event not received!'); + + yield $client->disconnect(); } - public function testImmediatePublish(): void + public function testImmediatePublish(Client $client) { - $properties = $this->client->properties(); + $properties = $client->properties(); // RabbitMQ 3 doesn't support "immediate" publish flag. - if($properties->product() === 'RabbitMQ' && version_compare($properties->version(), '3.0', '>')) - { + if ($properties->product() === 'RabbitMQ' && version_compare($properties->version(), '3.0', '>')) { + yield $client->disconnect(); + return; } + /** @var Channel $channel */ + $channel = yield $client->channel(); + $deferred = new Deferred(); - $watcher = Loop::delay(100, function() use ($deferred) - { + $watcher = Loop::delay(100, function () use ($deferred) { $deferred->resolve(false); }); - $this->channel->events()->onReturn( - function(Message $message) use ($deferred, $watcher) - { - self::assertTrue($message->returned()); + $channel->events()->onReturn(function (Message $message) use ($deferred, $watcher) { + self::assertTrue($message->returned()); - Loop::cancel($watcher); + Loop::cancel($watcher); - $deferred->resolve(true); - } - ); + $deferred->resolve(true); + }); - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->publish('.', '', 'test_queue', [], false, true); - wait($this->channel->publish('.', '', 'test_queue', [], false, true)); + self::assertTrue(yield $deferred->promise(), 'Immediate return event not received!'); - self::assertTrue(wait($deferred->promise()), 'Immediate return event not received!'); + yield $client->disconnect(); } - public function testConsume(): void + public function testConsume(Client $client) { - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait($this->channel->publish('hi', '', 'test_queue')); - - wait( - $this->channel->consume( - function(Message $message) use (&$tag) - { - self::assertEquals('hi', $message->content()); - self::assertEquals($tag, $message->consumerTag()); - }, - 'test_queue', - false, - true - ) - ); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->publish('hi', '', 'test_queue'); + + /** @noinspection PhpUnusedLocalVariableInspection */ + $tag = yield $channel->consume(function (Message $message) use ($client, &$tag) { + self::assertEquals('hi', $message->content()); + self::assertEquals($tag, $message->consumerTag()); + + yield $client->disconnect(); + }, 'test_queue', false, true); } - public function testCancel(): void + public function testCancel(Client $client) { - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait($this->channel->publish('hi', '', 'test_queue')); - - $tag = wait( - $this->channel->consume( - static function(Message $message) - { - }, - 'test_queue', - false, - true - ) - ); - - wait($this->channel->cancel($tag)); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->publish('hi', '', 'test_queue'); + + $tag = yield $channel->consume(function (Message $message) { + }, 'test_queue', false, true); + + $promise = $channel->cancel($tag); + + self::assertPromise($promise); + + yield $promise; + + yield $client->disconnect(); } - public function testHeaders(): void + public function testHeaders(Client $client) { - wait( - $this->channel->queueDeclare( - 'test_queue', - false, - false, - false, - true - ) - ); - - wait( - $this->channel->publish('hi html', '', 'test_queue', [ - 'content-type' => 'text/html', - 'custom' => 'value', - ]) - ); - - wait( - $this->channel->consume( - function(Message $message) - { - self::assertEquals('text/html', $message->header('content-type')); - self::assertEquals('value', $message->header('custom')); - self::assertEquals('hi html', $message->content()); - - }, - 'test_queue', - false, - true - ) - ); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->publish('hi html', '', 'test_queue', [ + 'content-type' => 'text/html', + 'custom' => 'value', + ]); + + yield $channel->consume(function (Message $message) use ($client) { + self::assertEquals('text/html', $message->header('content-type')); + self::assertEquals('value', $message->header('custom')); + self::assertEquals('hi html', $message->content()); + + yield $client->disconnect(); + }, 'test_queue', false, true); } - public function testGet(): void + public function testGet(Client $client) { - wait( - $this->channel->queueDeclare('get_test', false, false, false, true) - ); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->queueDeclare('get_test', false, false, false, true); - wait($this->channel->publish('.', '', 'get_test')); + yield $channel->publish('.', '', 'get_test'); /** @var Message $message1 */ - $message1 = wait($this->channel->get('get_test', true)); + $message1 = yield $channel->get('get_test', true); self::assertNotNull($message1); self::assertInstanceOf(Message::class, $message1); @@ -383,297 +346,311 @@ public function testGet(): void self::assertFalse($message1->redelivered()); self::assertIsArray($message1->headers()); - self::assertNull(wait($this->channel->get('get_test', true))); + self::assertNull(yield $channel->get('get_test', true)); - wait($this->channel->publish('..', '', 'get_test')); + yield $channel->publish('..', '', 'get_test'); /** @var Message $message2 */ - $message2 = wait($this->channel->get('get_test')); + $message2 = yield $channel->get('get_test'); self::assertNotNull($message2); self::assertEquals(2, $message2->deliveryTag()); self::assertFalse($message2->redelivered()); - $this->client->disconnect()->onResolve( - function() - { - yield $this->client->connect(); + $client->disconnect()->onResolve(function () use ($client) { + yield $client->connect(); - /** @var Channel $channel */ - $channel = yield $this->client->channel(); + /** @var Channel $channel */ + $channel = yield $client->channel(); - /** @var Message $message3 */ - $message3 = yield $channel->get('get_test'); + /** @var Message $message3 */ + $message3 = yield $channel->get('get_test'); - self::assertNotNull($message3); - self::assertInstanceOf(Message::class, $message3); - self::assertEquals('', $message3->exchange()); - self::assertEquals('..', $message3->content()); - self::assertTrue($message3->redelivered()); + self::assertNotNull($message3); + self::assertInstanceOf(Message::class, $message3); + self::assertEquals('', $message3->exchange()); + self::assertEquals('..', $message3->content()); + self::assertTrue($message3->redelivered()); - yield $channel->ack($message3); + yield $channel->ack($message3); - yield $this->client->disconnect(); - } - ); + yield $client->disconnect(); + }); } - public function testAck(): void + public function testAck(Client $client) { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); - wait($this->channel->publish('.', '', 'test_queue')); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->publish('.', '', 'test_queue'); /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); + $message = yield $channel->get('test_queue'); + $promise = $channel->ack($message); - wait($this->channel->ack($message)); + self::assertPromise($promise); + + yield $promise; + + yield $client->disconnect(); } - public function testNack(): void + public function testNack(Client $client) { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); + /** @var Channel $channel */ + $channel = yield $client->channel(); - wait($this->channel->publish('.', '', 'test_queue')); + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->publish('.', '', 'test_queue'); /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); + $message = yield $channel->get('test_queue'); self::assertNotNull($message); self::assertFalse($message->redelivered()); - wait($this->channel->nack($message)); + $promise = $channel->nack($message); + + self::assertPromise($promise); + + yield $promise; /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); + $message = yield $channel->get('test_queue'); self::assertNotNull($message); self::assertTrue($message->redelivered()); - wait($this->channel->nack($message, false, false)); + yield $channel->nack($message, false, false); - self::assertNull(wait($this->channel->get('test_queue'))); + self::assertNull(yield $channel->get('test_queue')); + yield $client->disconnect(); } - public function testReject(): void + public function testReject(Client $client) { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); + /** @var Channel $channel */ + $channel = yield $client->channel(); - wait($this->channel->publish('.', '', 'test_queue')); + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->publish('.', '', 'test_queue'); /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); + $message = yield $channel->get('test_queue'); self::assertNotNull($message); self::assertFalse($message->redelivered()); - wait($this->channel->reject($message)); + $promise = $channel->reject($message); + + self::assertPromise($promise); + + yield $promise; /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); + $message = yield $channel->get('test_queue'); self::assertNotNull($message); self::assertTrue($message->redelivered()); - wait($this->channel->reject($message, false)); + yield $channel->reject($message, false); - self::assertNull(wait($this->channel->get('test_queue'))); + self::assertNull(yield $channel->get('test_queue')); + + yield $client->disconnect(); } - public function testRecover(): void + public function testRecover(Client $client) { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); + /** @var Channel $channel */ + $channel = yield $client->channel(); - wait($this->channel->publish('.', '', 'test_queue')); + yield $channel->queueDeclare('test_queue', false, false, false, true); + yield $channel->publish('.', '', 'test_queue'); /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); + $message = yield $channel->get('test_queue'); self::assertNotNull($message); self::assertFalse($message->redelivered()); - wait($this->channel->recover(true)); + $promise = $channel->recover(true); + + self::assertPromise($promise); + + yield $promise; /** @var Message $message */ - $message = wait($this->channel->get('test_queue')); + $message = yield $channel->get('test_queue'); self::assertNotNull($message); self::assertTrue($message->redelivered()); - wait($this->channel->ack($message)); + yield $channel->ack($message); + + yield $client->disconnect(); } - public function testBigMessage(): void + public function testBigMessage(Client $client) { - wait( - $this->channel->queueDeclare('test_queue', false, false, false, true) - ); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->queueDeclare('test_queue', false, false, false, true); $body = \str_repeat('a', 10 << 20); // 10 MiB - wait($this->channel->publish($body, '', 'test_queue')); + yield $channel->publish($body, '', 'test_queue'); - wait( - $this->channel->consume( - function(Message $message, Channel $channel) use ($body) - { - self::assertEquals(\strlen($body), \strlen($message->content())); + yield $channel->consume(function (Message $message, Channel $channel) use ($body, $client) { + self::assertEquals(\strlen($body), \strlen($message->content())); - yield $channel->ack($message); - }, - 'test_queue' - ) - ); + yield $channel->ack($message); + yield $client->disconnect(); + }, 'test_queue'); } - public function testGetDouble(): void + public function testGetDouble(Client $client) { - $this->expectException(Exception\ChannelException::class); - - wait( - $this->channel->queueDeclare( - 'get_test_double', - false, - false, - false, - true - ) - ); - - wait($this->channel->publish('.', '', 'get_test_double')); - - try - { - wait( - call( - function() - { - yield [ - $this->channel->get('get_test_double'), - $this->channel->get('get_test_double'), - ]; - } - ) - ); - } - finally - { - wait($this->channel->queueDelete('get_test_double')); + self::expectException(Exception\ChannelException::class); + + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->queueDeclare('get_test_double', false, false, false, true); + yield $channel->publish('.', '', 'get_test_double'); + + try { + yield [ + $channel->get('get_test_double'), + $channel->get('get_test_double'), + ]; + } finally { + yield $channel->queueDelete('get_test_double'); + + yield $client->disconnect(); } } - public function testEmptyMessage(): void + public function testEmptyMessage(Client $client) { - wait( - $this->channel->queueDeclare( - 'empty_body_message_test', - false, - false, - false, - true - ) - ); - - wait($this->channel->publish('', '', 'empty_body_message_test')); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + yield $channel->queueDeclare('empty_body_message_test', false, false, false, true); + yield $channel->publish('', '', 'empty_body_message_test'); /** @var Message $message */ - $message = wait($this->channel->get('empty_body_message_test', true)); + $message = yield $channel->get('empty_body_message_test', true); self::assertNotNull($message); self::assertEquals('', $message->content()); - wait($this->channel->publish('', '', 'empty_body_message_test')); - wait($this->channel->publish('', '', 'empty_body_message_test')); - $count = 0; - wait( - $this->channel->consume( - function(Message $message, Channel $channel) use (&$count) - { - self::assertEmpty($message->content()); + yield $channel->consume(function (Message $message, Channel $channel) use ($client, &$count) { + self::assertEmpty($message->content()); - yield $channel->ack($message); + yield $channel->ack($message); - if(++$count === 2) - { - return; - } - }, - 'empty_body_message_test' - ) - ); + if (++$count === 2) { + yield $client->disconnect(); + } + }, 'empty_body_message_test'); - self::assertSame(2, $count); + yield $channel->publish('', '', 'empty_body_message_test'); + yield $channel->publish('', '', 'empty_body_message_test'); } - public function testTxs(): void + public function testTxs(Client $client) { - wait($this->channel->queueDeclare('tx_test', false, false, false, true)); + /** @var Channel $channel */ + $channel = yield $client->channel(); - wait($this->channel->txSelect()); - wait($this->channel->publish('.', '', 'tx_test')); - wait($this->channel->txCommit()); + yield $channel->queueDeclare('tx_test', false, false, false, true); + + yield $channel->txSelect(); + yield $channel->publish('.', '', 'tx_test'); + yield $channel->txCommit(); /** @var Message $message */ - $message = wait($this->channel->get('tx_test', true)); + $message = yield $channel->get('tx_test', true); self::assertNotNull($message); self::assertInstanceOf(Message::class, $message); self::assertEquals('.', $message->content()); - wait($this->channel->publish('..', '', 'tx_test')); - wait($this->channel->txRollback()); + $channel->publish('..', '', 'tx_test'); + $channel->txRollback(); - $nothing = wait($this->channel->get('tx_test', true)); + $nothing = yield $channel->get('tx_test', true); self::assertNull($nothing); + + yield $client->disconnect(); } - public function testTxSelectCannotBeCalledMultipleTimes(): void + public function testTxSelectCannotBeCalledMultipleTimes(Client $client) { - $this->expectException(Exception\ChannelException::class); + self::expectException(Exception\ChannelException::class); + + /** @var Channel $channel */ + $channel = yield $client->channel(); - wait($this->channel->txSelect()); - wait($this->channel->txSelect()); + try { + yield $channel->txSelect(); + yield $channel->txSelect(); + } finally { + yield $client->disconnect(); + } } - public function testTxCommitCannotBeCalledUnderNotTransactionMode(): void + public function testTxCommitCannotBeCalledUnderNotTransactionMode(Client $client) { - $this->expectException(Exception\ChannelException::class); + self::expectException(Exception\ChannelException::class); + + /** @var Channel $channel */ + $channel = yield $client->channel(); - wait($this->channel->txCommit()); + try { + yield $channel->txCommit(); + } finally { + yield $client->disconnect(); + } } - public function testTxRollbackCannotBeCalledUnderNotTransactionMode(): void + public function testTxRollbackCannotBeCalledUnderNotTransactionMode(Client $client) { - $this->expectException(Exception\ChannelException::class); + self::expectException(Exception\ChannelException::class); - wait($this->channel->txRollback()); + /** @var Channel $channel */ + $channel = yield $client->channel(); + + try { + yield $channel->txRollback(); + } finally { + yield $client->disconnect(); + } } - public function testConfirmMode(): void + public function testConfirmMode(Client $client) { - $this->channel->events()->onAck( - function(int $deliveryTag, bool $multiple) - { - self::assertEquals(1, $deliveryTag); - self::assertFalse($multiple); - } - ); + /** @var Channel $channel */ + $channel = yield $client->channel(); + $channel->events()->onAck(function (int $deliveryTag, bool $multiple) { + self::assertEquals($deliveryTag, 1); + self::assertFalse($multiple); + }); + + yield $channel->confirmSelect(); - wait($this->channel->confirmSelect()); + $deliveryTag = yield $channel->publish('.'); - $deliveryTag = wait($this->channel->publish('.')); + self::assertEquals($deliveryTag, 1); - self::assertEquals(1, $deliveryTag); + yield $client->disconnect(); } } diff --git a/tests/ClientConnectTest.php b/tests/ClientConnectTest.php index d6e2f6b..e8bd85e 100644 --- a/tests/ClientConnectTest.php +++ b/tests/ClientConnectTest.php @@ -12,56 +12,50 @@ use Amp\Loop; use Amp\Socket\ConnectException; +use PHPinnacle\Ridge\Channel; use PHPinnacle\Ridge\Client; -use PHPinnacle\Ridge\Config; -use PHPUnit\Framework\TestCase; -use function Amp\Promise\wait; +use PHPinnacle\Ridge\Message; -class ClientConnectTest extends TestCase +class ClientConnectTest extends RidgeTest { - protected function setUp(): void + public function testConnect() { - parent::setUp(); + Loop::run(function () { + $client = self::client(); - Loop::run(); - } - - protected function tearDown(): void - { - parent::tearDown(); + $promise = $client->connect(); - Loop::stop(); - } - - public function testConnect(): void - { - $client = new Client( - Config::parse(\getenv('RIDGE_TEST_DSN')) - ); + self::assertPromise($promise); - wait($client->connect()); - - self::assertTrue($client->isConnected()); - - wait($client->disconnect()); - } - - public function testConnectFailure(): void - { - $this->expectException(ConnectException::class); + yield $promise; - $client = Client::create('amqp://127.0.0.2:5673'); + self::assertTrue($client->isConnected()); - wait($client->connect()); + yield $client->disconnect(); + }); } - public function testConnectAuth() + public function testConnectFailure() { - $this->expectException(ConnectException::class); + self::expectException(ConnectException::class); - $client = new Client(new Config('localhost', 5673, 'testuser', 'testpassword')); + Loop::run(function () { + $client = Client::create('amqp://127.0.0.2:5673'); - wait($client->connect()); - wait($client->disconnect()); + yield $client->connect(); + }); } +// +// public function testConnectAuth() +// { +// $client = new Client([ +// 'user' => 'testuser', +// 'password' => 'testpassword', +// 'vhost' => 'testvhost', +// ]); +// $client->connect(); +// $client->disconnect(); +// +// $this->assertTrue(true); +// } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php new file mode 100644 index 0000000..e8e00ce --- /dev/null +++ b/tests/ClientTest.php @@ -0,0 +1,68 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPinnacle\Ridge\Tests; + +use PHPinnacle\Ridge\Channel; +use PHPinnacle\Ridge\Client; +use PHPinnacle\Ridge\Message; + +class ClientTest extends AsyncTest +{ + public function testOpenChannel(Client $client) + { + self::assertPromise($promise = $client->channel()); + self::assertInstanceOf(Channel::class, yield $promise); + + yield $client->disconnect(); + } + + public function testOpenMultipleChannel(Client $client) + { + /** @var Channel $channel1 */ + /** @var Channel $channel2 */ + $channel1 = yield $client->channel(); + $channel2 = yield $client->channel(); + + self::assertInstanceOf(Channel::class, $channel1); + self::assertInstanceOf(Channel::class, $channel2); + self::assertNotEquals($channel1->id(), $channel2->id()); + + /** @var Channel $channel3 */ + $channel3 = yield $client->channel(); + + self::assertInstanceOf(Channel::class, $channel3); + self::assertNotEquals($channel1->id(), $channel3->id()); + self::assertNotEquals($channel2->id(), $channel3->id()); + + yield $client->disconnect(); + } + + public function testDisconnectWithBufferedMessages(Client $client) + { + /** @var Channel $channel */ + $channel = yield $client->channel(); + $count = 0; + + yield $channel->qos(0, 1000); + yield $channel->queueDeclare('disconnect_test', false, false, false, true); + yield $channel->consume(function (Message $message, Channel $channel) use ($client, &$count) { + yield $channel->ack($message); + + self::assertEquals(1, ++$count); + + yield $client->disconnect(); + }, 'disconnect_test'); + + yield $channel->publish('.', '', 'disconnect_test'); + yield $channel->publish('.', '', 'disconnect_test'); + yield $channel->publish('.', '', 'disconnect_test'); + } +} diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 213171c..c84852c 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -11,11 +11,10 @@ namespace PHPinnacle\Ridge\Tests; use PHPinnacle\Ridge\Config; -use PHPUnit\Framework\TestCase; -class ConfigTest extends TestCase +class ConfigTest extends RidgeTest { - public function testCreate(): void + public function testCreate() { $config = new Config(); @@ -26,7 +25,7 @@ public function testCreate(): void self::assertSame('guest', $config->pass); } - public function testUri(): void + public function testUri() { $default = new Config(); $custom = new Config('my-domain.com', 6672); @@ -35,7 +34,7 @@ public function testUri(): void self::assertSame('tcp://my-domain.com:6672', $custom->uri()); } - public function testParse(): void + public function testParse() { $config = Config::parse('amqp://user:pass@localhost:5672/test'); @@ -46,7 +45,7 @@ public function testParse(): void self::assertSame('pass', $config->pass); } - public function testVhost(): void + public function testVhost() { self::assertSame('test', Config::parse('amqp://localhost:5672/test')->vhost); self::assertSame('/', Config::parse('amqp://localhost:5672/')->vhost); diff --git a/tests/RidgeTest.php b/tests/RidgeTest.php new file mode 100644 index 0000000..03c6a48 --- /dev/null +++ b/tests/RidgeTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPinnacle\Ridge\Tests; + +use Amp\Promise; +use PHPinnacle\Ridge\Client; +use PHPinnacle\Ridge\Config; +use PHPUnit\Framework\TestCase; + +abstract class RidgeTest extends TestCase +{ + /** + * @param mixed $value + * + * @return void + */ + protected static function assertPromise($value): void + { + self::assertInstanceOf(Promise::class, $value); + } + + /** + * @return Client + */ + protected static function client(): Client + { + if(!$dsn = \getenv('RIDGE_TEST_DSN')) + { + self::markTestSkipped('No test dsn! Please set RIDGE_TEST_DSN environment variable.'); + } + + $config = Config::parse($dsn); + + return new Client($config); + } +} From a8a4cf6f8433491fe15ae68f310b1dd46a7eb36f Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 22:00:04 +0100 Subject: [PATCH 51/58] debug ci --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e39abd7..e966eca 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -70,6 +70,7 @@ jobs: - name: Run RabbitMQ uses: getong/rabbitmq-action@v1.2 with: + host port: 5672/tcp rabbitmq version: 3.8.2-management-alpine rabbitmq user: admin rabbitmq password: password From 5955eed36d76c58717b764094884a02ee81845cb Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 22:03:01 +0100 Subject: [PATCH 52/58] debug ci --- .github/workflows/continuous-integration.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e966eca..8fe5820 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -47,6 +47,15 @@ jobs: name: PHPUnit runs-on: ubuntu-latest + services: + rabbitmq: + image: rabbitmq:3-management + ports: + - 5672/tcp + env: + RABBITMQ_DEFAULT_USER: admin + RABBITMQ_DEFAULT_PASS: password + options: --health-cmd "rabbitmqctl node_health_check" --health-interval 10s --health-timeout 5s --health-retries 5 env: PHP_EXTENSIONS: mbstring, dom, intl, json, libxml, xml, xmlwriter, sockets @@ -67,17 +76,8 @@ jobs: - name: Install dependencies run: composer update -ov - - name: Run RabbitMQ - uses: getong/rabbitmq-action@v1.2 - with: - host port: 5672/tcp - rabbitmq version: 3.8.2-management-alpine - rabbitmq user: admin - rabbitmq password: password - rabbitmq vhost: vhost - - name: Run tests with phpunit - run: XDEBUG_MODE=coverage RIDGE_TEST_DSN=amqp://admin:password@127.0.0.1:5672/vhost?heartbeat=0 ./vendor/bin/phpunit --coverage-clover=coverage.clover + run: XDEBUG_MODE=coverage RIDGE_TEST_DSN=amqp://admin:password@127.0.0.1:5672/?heartbeat=0 ./vendor/bin/phpunit --coverage-clover=coverage.clover - name: Upload coverage file uses: actions/upload-artifact@v2 From d3b81b2fb6520ab2208720b149d637ff1846fa87 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 22:05:19 +0100 Subject: [PATCH 53/58] debug ci --- .github/workflows/continuous-integration.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 8fe5820..920dd37 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -76,6 +76,11 @@ jobs: - name: Install dependencies run: composer update -ov + - name: Await + uses: jakejarvis/wait-action@master + with: + time: '30s' + - name: Run tests with phpunit run: XDEBUG_MODE=coverage RIDGE_TEST_DSN=amqp://admin:password@127.0.0.1:5672/?heartbeat=0 ./vendor/bin/phpunit --coverage-clover=coverage.clover From 1ddea0838d42a0dc833343489140661c5bce382e Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 22:07:50 +0100 Subject: [PATCH 54/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 920dd37..72051a0 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -51,7 +51,7 @@ jobs: rabbitmq: image: rabbitmq:3-management ports: - - 5672/tcp + - 5672:5672 env: RABBITMQ_DEFAULT_USER: admin RABBITMQ_DEFAULT_PASS: password From 1c34c406d83587d26a3c7c771c7868def5219d3e Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 22:13:29 +0100 Subject: [PATCH 55/58] debug ci --- .github/workflows/continuous-integration.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 72051a0..830674e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -53,8 +53,8 @@ jobs: ports: - 5672:5672 env: - RABBITMQ_DEFAULT_USER: admin - RABBITMQ_DEFAULT_PASS: password + RABBITMQ_DEFAULT_USER: guest + RABBITMQ_DEFAULT_PASS: guest options: --health-cmd "rabbitmqctl node_health_check" --health-interval 10s --health-timeout 5s --health-retries 5 env: @@ -82,7 +82,7 @@ jobs: time: '30s' - name: Run tests with phpunit - run: XDEBUG_MODE=coverage RIDGE_TEST_DSN=amqp://admin:password@127.0.0.1:5672/?heartbeat=0 ./vendor/bin/phpunit --coverage-clover=coverage.clover + run: XDEBUG_MODE=coverage php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover - name: Upload coverage file uses: actions/upload-artifact@v2 From 7624bb5ac48327e23a68e052e76f56b33f05dd82 Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 22:15:38 +0100 Subject: [PATCH 56/58] debug ci --- .github/workflows/continuous-integration.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 830674e..3b82c78 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -78,8 +78,6 @@ jobs: - name: Await uses: jakejarvis/wait-action@master - with: - time: '30s' - name: Run tests with phpunit run: XDEBUG_MODE=coverage php ./vendor/bin/phpunit --configuration ./phpunit.xml --coverage-clover=coverage.clover From 2da1112d645a939df8a4781cdc6bea05595b80ed Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sat, 2 Jan 2021 22:17:01 +0100 Subject: [PATCH 57/58] debug ci --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 3b82c78..c18733d 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -49,7 +49,7 @@ jobs: runs-on: ubuntu-latest services: rabbitmq: - image: rabbitmq:3-management + image: rabbitmq:alpine ports: - 5672:5672 env: From 8f20b7ae5b2e098c998224d02c32473146645d6f Mon Sep 17 00:00:00 2001 From: Masiukevich Maksim Date: Sun, 3 Jan 2021 17:37:55 +0100 Subject: [PATCH 58/58] wrong type casts removed & code reformatted --- .scrutinizer.yml | 21 -- composer.json | 2 +- src/Buffer.php | 67 ++-- src/Channel.php | 422 ++++++++++------------- src/Client.php | 100 ++---- src/Config.php | 80 ++--- src/Connection.php | 63 ++-- src/Constants.php | 206 +++++------ src/Consumer.php | 13 +- src/Events.php | 13 +- src/Exception/ClassInvalid.php | 2 +- src/Exception/ClientException.php | 4 +- src/Exception/ConfigurationException.php | 2 +- src/Exception/ConnectionException.php | 4 +- src/Exception/MethodInvalid.php | 2 +- src/Exception/ProtocolException.php | 7 +- src/Exception/RidgeException.php | 2 +- src/Message.php | 82 ++--- src/MessageReceiver.php | 78 ++--- src/Parser.php | 52 ++- src/Properties.php | 10 +- src/Protocol/AbstractFrame.php | 4 +- src/Protocol/BasicAckFrame.php | 8 +- src/Protocol/BasicCancelFrame.php | 6 +- src/Protocol/BasicCancelOkFrame.php | 6 +- src/Protocol/BasicConsumeFrame.php | 14 +- src/Protocol/BasicConsumeOkFrame.php | 2 +- src/Protocol/BasicDeliverFrame.php | 4 +- src/Protocol/BasicGetEmptyFrame.php | 6 +- src/Protocol/BasicGetFrame.php | 10 +- src/Protocol/BasicGetOkFrame.php | 14 +- src/Protocol/BasicNackFrame.php | 4 +- src/Protocol/BasicPublishFrame.php | 14 +- src/Protocol/BasicQosFrame.php | 12 +- src/Protocol/BasicRecoverFrame.php | 6 +- src/Protocol/BasicRejectFrame.php | 6 +- src/Protocol/BasicReturnFrame.php | 14 +- src/Protocol/ChannelCloseFrame.php | 14 +- src/Protocol/ChannelFlowFrame.php | 4 +- src/Protocol/ChannelFlowOkFrame.php | 4 +- src/Protocol/ChannelOpenFrame.php | 8 +- src/Protocol/ChannelOpenOkFrame.php | 6 +- src/Protocol/ConfirmSelectFrame.php | 6 +- src/Protocol/ConnectionBlockedFrame.php | 6 +- src/Protocol/ConnectionCloseFrame.php | 14 +- src/Protocol/ConnectionOpenFrame.php | 16 +- src/Protocol/ConnectionOpenOkFrame.php | 8 +- src/Protocol/ConnectionSecureFrame.php | 8 +- src/Protocol/ConnectionSecureOkFrame.php | 4 +- src/Protocol/ConnectionStartFrame.php | 6 +- src/Protocol/ConnectionStartOkFrame.php | 14 +- src/Protocol/ConnectionTuneFrame.php | 12 +- src/Protocol/ConnectionTuneOkFrame.php | 12 +- src/Protocol/ContentHeaderFrame.php | 179 ++++------ src/Protocol/ExchangeBindFrame.php | 16 +- src/Protocol/ExchangeDeclareFrame.php | 10 +- src/Protocol/ExchangeDeleteFrame.php | 10 +- src/Protocol/ExchangeUnbindFrame.php | 14 +- src/Protocol/MethodFrame.php | 6 +- src/Protocol/QueueBindFrame.php | 16 +- src/Protocol/QueueDeclareFrame.php | 10 +- src/Protocol/QueueDeclareOkFrame.php | 10 +- src/Protocol/QueueDeleteFrame.php | 8 +- src/Protocol/QueueDeleteOkFrame.php | 4 +- src/Protocol/QueuePurgeFrame.php | 8 +- src/Protocol/QueuePurgeOkFrame.php | 4 +- src/Protocol/QueueUnbindFrame.php | 12 +- src/Queue.php | 6 +- 68 files changed, 780 insertions(+), 1037 deletions(-) delete mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 05385d2..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,21 +0,0 @@ -checks: - php: true - -filter: - paths: - - "src/*" - -tools: - external_code_coverage: - timeout: 600 - -build: - nodes: - analysis: - environment: - php: 8.0.0 - project_setup: - override: true - tests: - override: - - php-scrutinizer-run --enable-security-analysis diff --git a/composer.json b/composer.json index 5e9f8a3..622e8fa 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "php": ">=8.0", "amphp/amp": "v2.5.*", "amphp/socket": "v1.1.*", - "phpinnacle/buffer": "v1.1.*" + "phpinnacle/buffer": "v1.2.*" }, "require-dev": { "phpunit/phpunit": "v9.5.*", diff --git a/src/Buffer.php b/src/Buffer.php index 5e4b943..d5093b3 100644 --- a/src/Buffer.php +++ b/src/Buffer.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -55,12 +55,11 @@ public function appendBits(array $bits): self $value = 0; /** - * @var int $n + * @var int $n * @var bool $bit */ - foreach($bits as $n => $bit) - { - $bit = $bit ? 1 : 0; + foreach ($bits as $n => $bit) { + $bit = $bit ? 1 : 0; $value |= $bit << $n; } @@ -74,11 +73,10 @@ public function appendBits(array $bits): self */ public function consumeBits(int $n): array { - $bits = []; + $bits = []; $value = $this->consumeUint8(); - for($i = 0; $i < $n; ++$i) - { + for ($i = 0; $i < $n; ++$i) { $bits[] = ($value & (1 << $i)) > 0; } @@ -107,11 +105,10 @@ public function appendTable(array $table): self /** * @var string|ByteBuffer $k - * @var mixed $v + * @var mixed $v */ - foreach($table as $k => $v) - { - $k = (string) $k; + foreach ($table as $k => $v) { + $k = (string)$k; $buffer->appendUint8(\strlen($k)); $buffer->append($k); @@ -131,10 +128,9 @@ public function appendTable(array $table): self public function consumeTable(): array { $buffer = $this->shift($this->consumeUint32()); - $data = []; + $data = []; - while(!$buffer->empty()) - { + while (!$buffer->empty()) { $data[$buffer->consume($buffer->consumeUint8())] = $buffer->consumeValue(); } @@ -149,8 +145,7 @@ public function appendArray(array $value): self $buffer = new self(); /** @var mixed $v */ - foreach($value as $v) - { + foreach ($value as $v) { $buffer->appendValue($v); } @@ -167,10 +162,9 @@ public function appendArray(array $value): self public function consumeArray(): array { $buffer = $this->shift($this->consumeUint32()); - $data = []; + $data = []; - while(!$buffer->empty()) - { + while (!$buffer->empty()) { $data[] = $buffer->consumeValue(); } @@ -196,8 +190,7 @@ private function consumeValue(): float|\DateTimeInterface|null|array|bool|int|st { $fieldType = $this->consumeUint8(); - return match ($fieldType) - { + return match ($fieldType) { Constants::FIELD_BOOLEAN => $this->consumeUint8() > 0, Constants::FIELD_SHORT_SHORT_INT => $this->consumeInt8(), Constants::FIELD_SHORT_SHORT_UINT => $this->consumeUint8(), @@ -225,47 +218,39 @@ private function consumeValue(): float|\DateTimeInterface|null|array|bool|int|st */ private function appendValue(mixed $value): void { - if(\is_string($value)) - { + if (\is_string($value)) { $this->appendUint8(Constants::FIELD_LONG_STRING); $this->appendText($value); return; } - if(\is_int($value)) - { + if (\is_int($value)) { $this->appendUint8(Constants::FIELD_LONG_INT); $this->appendInt32($value); return; } - if(\is_bool($value)) - { + if (\is_bool($value)) { $this->appendUint8(Constants::FIELD_BOOLEAN); - $this->appendUint8((int) $value); + $this->appendUint8((int)$value); return; } - if(\is_float($value)) - { + if (\is_float($value)) { $this->appendUint8(Constants::FIELD_DOUBLE); $this->appendDouble($value); return; } - if(\is_array($value)) - { - if(\array_keys($value) === \range(0, \count($value) - 1)) - { + if (\is_array($value)) { + if (\array_keys($value) === \range(0, \count($value) - 1)) { $this->appendUint8(Constants::FIELD_ARRAY); $this->appendArray($value); - } - else - { + } else { $this->appendUint8(Constants::FIELD_TABLE); $this->appendTable($value); } @@ -273,15 +258,13 @@ private function appendValue(mixed $value): void return; } - if(\is_null($value)) - { + if (\is_null($value)) { $this->appendUint8(Constants::FIELD_NULL); return; } - if($value instanceof \DateTimeInterface) - { + if ($value instanceof \DateTimeInterface) { $this->appendUint8(Constants::FIELD_TIMESTAMP); $this->appendTimestamp($value); diff --git a/src/Channel.php b/src/Channel.php index f1b7300..3077116 100644 --- a/src/Channel.php +++ b/src/Channel.php @@ -8,21 +8,22 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; +use PHPinnacle\Ridge\Exception\ProtocolException; use function Amp\call; use Amp\Deferred; use Amp\Promise; final class Channel { - private const STATE_READY = 1; - private const STATE_OPEN = 2; + private const STATE_READY = 1; + private const STATE_OPEN = 2; private const STATE_CLOSING = 3; - private const STATE_CLOSED = 4; - private const STATE_ERROR = 5; + private const STATE_CLOSED = 4; + private const STATE_ERROR = 5; /** Regular AMQP guarantees of published messages delivery. */ private const MODE_REGULAR = 1; @@ -78,12 +79,12 @@ final class Channel public function __construct(int $id, Connection $connection, Properties $properties) { - $this->id = $id; + $this->id = $id; $this->connection = $connection; $this->properties = $properties; - $this->receiver = new MessageReceiver($this, $connection); - $this->consumer = new Consumer($this, $this->receiver); - $this->events = new Events($this, $this->receiver); + $this->receiver = new MessageReceiver($this, $connection); + $this->consumer = new Consumer($this, $this->receiver); + $this->events = new Events($this, $this->receiver); } public function id(): int @@ -104,10 +105,8 @@ public function events(): Events public function open(string $outOfBand = ''): Promise { return call( - function() use ($outOfBand) - { - if($this->state !== self::STATE_READY) - { + function () use ($outOfBand) { + if ($this->state !== self::STATE_READY) { throw Exception\ChannelException::notReady($this->id); } @@ -139,15 +138,12 @@ function() use ($outOfBand) public function close(int $code = 0, string $reason = ''): Promise { return call( - function() use ($code, $reason) - { - if($this->state === self::STATE_CLOSED) - { + function () use ($code, $reason) { + if ($this->state === self::STATE_CLOSED) { throw Exception\ChannelException::alreadyClosed($this->id); } - if($this->state === self::STATE_CLOSING) - { + if ($this->state === self::STATE_CLOSING) { return; } @@ -184,8 +180,7 @@ function() use ($code, $reason) public function qos(int $prefetchSize = 0, int $prefetchCount = 0, bool $global = false): Promise { return call( - function() use ($prefetchSize, $prefetchCount, $global) - { + function () use ($prefetchSize, $prefetchCount, $global) { yield $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) @@ -216,13 +211,11 @@ public function consume bool $exclusive = false, bool $noWait = false, array $arguments = [] - ): Promise - { + ): Promise { $flags = [$noLocal, $noAck, $exclusive, $noWait]; return call( - function() use ($callback, $queue, $consumerTag, $flags, $noWait, $arguments) - { + function () use ($callback, $queue, $consumerTag, $flags, $noWait, $arguments) { yield $this->connection->method($this->id, (new Buffer) ->appendUint16(60) ->appendUint16(20) @@ -233,13 +226,11 @@ function() use ($callback, $queue, $consumerTag, $flags, $noWait, $arguments) ->appendTable($arguments) ); - if($noWait === false) - { + if ($noWait === false) { /** @var Protocol\BasicConsumeOkFrame $frame */ $frame = yield $this->await(Protocol\BasicConsumeOkFrame::class); - if('' === $consumerTag) - { + if ('' === $consumerTag) { $consumerTag = $frame->consumerTag; } } @@ -257,8 +248,7 @@ function() use ($callback, $queue, $consumerTag, $flags, $noWait, $arguments) public function cancel(string $consumerTag, bool $noWait = false): Promise { return call( - function() use ($consumerTag, $noWait) - { + function () use ($consumerTag, $noWait) { yield $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) @@ -270,8 +260,7 @@ function() use ($consumerTag, $noWait) ->appendUint8(206) ); - if($noWait === false) - { + if ($noWait === false) { yield $this->await(Protocol\BasicCancelOkFrame::class); } @@ -282,19 +271,24 @@ function() use ($consumerTag, $noWait) /** * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ProtocolException */ public function ack(Message $message, bool $multiple = false): Promise { return call( - function() use ($message, $multiple) - { + function () use ($message, $multiple) { + if ($message->deliveryTag === null) { + throw ProtocolException::unsupportedDeliveryTag(); + } + yield $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) ->appendUint32(13) ->appendUint16(60) ->appendUint16(80) - ->appendInt64((int) $message->deliveryTag()) + ->appendInt64($message->deliveryTag) ->appendBits([$multiple]) ->appendUint8(206) ); @@ -304,19 +298,24 @@ function() use ($message, $multiple) /** * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ProtocolException */ public function nack(Message $message, bool $multiple = false, bool $requeue = true): Promise { return call( - function() use ($message, $multiple, $requeue) - { + function () use ($message, $multiple, $requeue) { + if ($message->deliveryTag === null) { + throw ProtocolException::unsupportedDeliveryTag(); + } + yield $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) ->appendUint32(13) ->appendUint16(60) ->appendUint16(120) - ->appendInt64((int) $message->deliveryTag()) + ->appendInt64($message->deliveryTag) ->appendBits([$multiple, $requeue]) ->appendUint8(206) ); @@ -326,18 +325,23 @@ function() use ($message, $multiple, $requeue) /** * @return Promise + * + * @throws \PHPinnacle\Ridge\Exception\ProtocolException */ public function reject(Message $message, bool $requeue = true): Promise { - return call(function() use ($message, $requeue) - { + return call(function () use ($message, $requeue) { + if ($message->deliveryTag === null) { + throw ProtocolException::unsupportedDeliveryTag(); + } + yield $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) ->appendUint32(13) ->appendUint16(60) ->appendUint16(90) - ->appendInt64((int) $message->deliveryTag()) + ->appendInt64($message->deliveryTag) ->appendBits([$requeue]) ->appendUint8(206) ); @@ -350,8 +354,7 @@ public function reject(Message $message, bool $requeue = true): Promise public function recover(bool $requeue = false): Promise { return call( - function() use ($requeue) - { + function () use ($requeue) { $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) @@ -375,10 +378,8 @@ public function get(string $queue = '', bool $noAck = false): Promise static $getting = false; return call( - function() use ($queue, $noAck, &$getting) - { - if($getting) - { + function () use ($queue, $noAck, &$getting) { + if ($getting) { throw Exception\ChannelException::getInProgress(); } @@ -402,8 +403,7 @@ function() use ($queue, $noAck, &$getting) $this->await(Protocol\BasicGetEmptyFrame::class) ]); - if($frame instanceof Protocol\BasicGetEmptyFrame) - { + if ($frame instanceof Protocol\BasicGetEmptyFrame) { $getting = false; return null; @@ -412,20 +412,18 @@ function() use ($queue, $noAck, &$getting) /** @var Protocol\ContentHeaderFrame $header */ $header = yield $this->await(Protocol\ContentHeaderFrame::class); - $buffer = new Buffer; + $buffer = new Buffer; $remaining = $header->bodySize; - while($remaining > 0) - { + while ($remaining > 0) { /** @var Protocol\ContentBodyFrame $body */ $body = yield $this->await(Protocol\ContentBodyFrame::class); - $buffer->append((string) $body->payload); + $buffer->append((string)$body->payload); - $remaining -= (int) $body->size; + $remaining -= (int)$body->size; - if($remaining < 0) - { + if ($remaining < 0) { $this->state = self::STATE_ERROR; throw Exception\ChannelException::bodyOverflow($remaining); @@ -459,11 +457,9 @@ public function publish array $headers = [], bool $mandatory = false, bool $immediate = false - ): Promise - { + ): Promise { return call( - function() use ($body, $exchange, $routingKey, $headers, $mandatory, $immediate) - { + function () use ($body, $exchange, $routingKey, $headers, $mandatory, $immediate) { yield $this->doPublish($body, $exchange, $routingKey, $headers, $mandatory, $immediate); return $this->mode === self::MODE_CONFIRM ? ++$this->deliveryTag : null; @@ -479,10 +475,8 @@ function() use ($body, $exchange, $routingKey, $headers, $mandatory, $immediate) public function txSelect(): Promise { return call( - function() - { - if($this->mode !== self::MODE_REGULAR) - { + function () { + if ($this->mode !== self::MODE_REGULAR) { throw Exception\ChannelException::notRegularFor("transactional"); } @@ -510,10 +504,8 @@ function() public function txCommit(): Promise { return call( - function() - { - if($this->mode !== self::MODE_TRANSACTIONAL) - { + function () { + if ($this->mode !== self::MODE_TRANSACTIONAL) { throw Exception\ChannelException::notTransactional(); } @@ -539,10 +531,8 @@ function() public function txRollback(): Promise { return call( - function() - { - if($this->mode !== self::MODE_TRANSACTIONAL) - { + function () { + if ($this->mode !== self::MODE_TRANSACTIONAL) { throw Exception\ChannelException::notTransactional(); } @@ -568,10 +558,8 @@ function() public function confirmSelect(bool $noWait = false): Promise { return call( - function() use ($noWait) - { - if($this->mode !== self::MODE_REGULAR) - { + function () use ($noWait) { + if ($this->mode !== self::MODE_REGULAR) { throw Exception\ChannelException::notRegularFor("confirm"); } @@ -585,12 +573,11 @@ function() use ($noWait) ->appendUint8(206) ); - if($noWait === false) - { + if ($noWait === false) { yield $this->await(Protocol\ConfirmSelectOkFrame::class); } - $this->mode = self::MODE_CONFIRM; + $this->mode = self::MODE_CONFIRM; $this->deliveryTag = 0; } ); @@ -608,13 +595,11 @@ public function queueDeclare bool $autoDelete = false, bool $noWait = false, array $arguments = [] - ): Promise - { + ): Promise { $flags = [$passive, $durable, $exclusive, $autoDelete, $noWait]; return call( - function() use ($queue, $flags, $noWait, $arguments) - { + function () use ($queue, $flags, $noWait, $arguments) { yield $this->connection->method($this->id, (new Buffer) ->appendUint16(50) ->appendUint16(10) @@ -624,8 +609,7 @@ function() use ($queue, $flags, $noWait, $arguments) ->appendTable($arguments) ); - if($noWait) - { + if ($noWait) { return null; } @@ -647,11 +631,9 @@ public function queueBind string $routingKey = '', bool $noWait = false, array $arguments = [] - ): Promise - { + ): Promise { return call( - function() use ($queue, $exchange, $routingKey, $noWait, $arguments) - { + function () use ($queue, $exchange, $routingKey, $noWait, $arguments) { yield $this->connection->method($this->id, (new Buffer) ->appendUint16(50) ->appendUint16(20) @@ -663,8 +645,7 @@ function() use ($queue, $exchange, $routingKey, $noWait, $arguments) ->appendTable($arguments) ); - if($noWait) - { + if ($noWait) { return; } @@ -683,11 +664,9 @@ public function queueUnbind string $routingKey = '', bool $noWait = false, array $arguments = [] - ): Promise - { + ): Promise { return call( - function() use ($queue, $exchange, $routingKey, $noWait, $arguments) - { + function () use ($queue, $exchange, $routingKey, $noWait, $arguments) { yield $this->connection->method($this->id, (new Buffer) ->appendUint16(50) ->appendUint16(50) @@ -698,8 +677,7 @@ function() use ($queue, $exchange, $routingKey, $noWait, $arguments) ->appendTable($arguments) ); - if($noWait) - { + if ($noWait) { return; } @@ -714,8 +692,7 @@ function() use ($queue, $exchange, $routingKey, $noWait, $arguments) public function queuePurge(string $queue = '', bool $noWait = false): Promise { return call( - function() use ($queue, $noWait) - { + function () use ($queue, $noWait) { yield $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) @@ -728,8 +705,7 @@ function() use ($queue, $noWait) ->appendUint8(206) ); - if($noWait) - { + if ($noWait) { return 0; } @@ -750,13 +726,11 @@ public function queueDelete bool $ifUnused = false, bool $ifEmpty = false, bool $noWait = false - ): Promise - { + ): Promise { $flags = [$ifUnused, $ifEmpty, $noWait]; return call( - function() use ($queue, $flags, $noWait) - { + function () use ($queue, $flags, $noWait) { yield $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) @@ -769,8 +743,7 @@ function() use ($queue, $flags, $noWait) ->appendUint8(206) ); - if($noWait) - { + if ($noWait) { return 0; } @@ -795,13 +768,11 @@ public function exchangeDeclare bool $internal = false, bool $noWait = false, array $arguments = [] - ): Promise - { + ): Promise { $flags = [$passive, $durable, $autoDelete, $internal, $noWait]; return call( - function() use ($exchange, $exchangeType, $flags, $noWait, $arguments) - { + function () use ($exchange, $exchangeType, $flags, $noWait, $arguments) { yield $this->connection->method($this->id, (new Buffer) ->appendUint16(40) ->appendUint16(10) @@ -812,8 +783,7 @@ function() use ($exchange, $exchangeType, $flags, $noWait, $arguments) ->appendTable($arguments) ); - if($noWait) - { + if ($noWait) { return; } @@ -832,11 +802,9 @@ public function exchangeBind string $routingKey = '', bool $noWait = false, array $arguments = [] - ): Promise - { + ): Promise { return call( - function() use ($destination, $source, $routingKey, $noWait, $arguments) - { + function () use ($destination, $source, $routingKey, $noWait, $arguments) { yield $this->connection->method($this->id, (new Buffer) ->appendUint16(40) ->appendUint16(30) @@ -848,8 +816,7 @@ function() use ($destination, $source, $routingKey, $noWait, $arguments) ->appendTable($arguments) ); - if($noWait) - { + if ($noWait) { return; } @@ -868,11 +835,9 @@ public function exchangeUnbind string $routingKey = '', bool $noWait = false, array $arguments = [] - ): Promise - { + ): Promise { return call( - function() use ($destination, $source, $routingKey, $noWait, $arguments) - { + function () use ($destination, $source, $routingKey, $noWait, $arguments) { yield $this->connection->method($this->id, (new Buffer) ->appendUint16(40) ->appendUint16(40) @@ -884,8 +849,7 @@ function() use ($destination, $source, $routingKey, $noWait, $arguments) ->appendTable($arguments) ); - if($noWait) - { + if ($noWait) { return; } @@ -900,8 +864,7 @@ function() use ($destination, $source, $routingKey, $noWait, $arguments) public function exchangeDelete(string $exchange, bool $unused = false, bool $noWait = false): Promise { return call( - function() use ($exchange, $unused, $noWait) - { + function () use ($exchange, $unused, $noWait) { yield $this->connection->write((new Buffer) ->appendUint8(1) ->appendUint16($this->id) @@ -914,8 +877,7 @@ function() use ($exchange, $unused, $noWait) ->appendUint8(206) ); - if($noWait) - { + if ($noWait) { return; } @@ -932,23 +894,22 @@ public function doPublish array $headers = [], bool $mandatory = false, bool $immediate = false - ): Promise - { - $flags = 0; - $contentType = ''; + ): Promise { + $flags = 0; + $contentType = ''; $contentEncoding = ''; - $type = ''; - $replyTo = ''; - $expiration = ''; - $messageId = ''; - $correlationId = ''; - $userId = ''; - $appId = ''; - $clusterId = ''; + $type = ''; + $replyTo = ''; + $expiration = ''; + $messageId = ''; + $correlationId = ''; + $userId = ''; + $appId = ''; + $clusterId = ''; $deliveryMode = null; - $priority = null; - $timestamp = null; + $priority = null; + $timestamp = null; $headersBuffer = null; @@ -967,126 +928,112 @@ public function doPublish $size = 14; - if(isset($headers['content-type'])) - { - $flags |= 32768; - $contentType = (string) $headers['content-type']; - $size += 1 + \strlen($contentType); + if (isset($headers['content-type'])) { + $flags |= 32768; + $contentType = (string)$headers['content-type']; + $size += 1 + \strlen($contentType); unset($headers['content-type']); } - if(isset($headers['content-encoding'])) - { - $flags |= 16384; - $contentEncoding = (string) $headers['content-encoding']; - $size += 1 + \strlen($contentEncoding); + if (isset($headers['content-encoding'])) { + $flags |= 16384; + $contentEncoding = (string)$headers['content-encoding']; + $size += 1 + \strlen($contentEncoding); unset($headers['content-encoding']); } - if(isset($headers['delivery-mode'])) - { - $flags |= 4096; - $deliveryMode = (int) $headers['delivery-mode']; + if (isset($headers['delivery-mode'])) { + $flags |= 4096; + $deliveryMode = (int)$headers['delivery-mode']; ++$size; unset($headers['delivery-mode']); } - if(isset($headers['priority'])) - { - $flags |= 2048; - $priority = (int) $headers['priority']; + if (isset($headers['priority'])) { + $flags |= 2048; + $priority = (int)$headers['priority']; ++$size; unset($headers['priority']); } - if(isset($headers['correlation-id'])) - { - $flags |= 1024; - $correlationId = (string) $headers['correlation-id']; - $size += 1 + \strlen($correlationId); + if (isset($headers['correlation-id'])) { + $flags |= 1024; + $correlationId = (string)$headers['correlation-id']; + $size += 1 + \strlen($correlationId); unset($headers['correlation-id']); } - if(isset($headers['reply-to'])) - { - $flags |= 512; - $replyTo = (string) $headers['reply-to']; - $size += 1 + \strlen($replyTo); + if (isset($headers['reply-to'])) { + $flags |= 512; + $replyTo = (string)$headers['reply-to']; + $size += 1 + \strlen($replyTo); unset($headers['reply-to']); } - if(isset($headers['expiration'])) - { - $flags |= 256; - $expiration = (string) $headers['expiration']; - $size += 1 + \strlen($expiration); + if (isset($headers['expiration'])) { + $flags |= 256; + $expiration = (string)$headers['expiration']; + $size += 1 + \strlen($expiration); unset($headers['expiration']); } - if(isset($headers['message-id'])) - { - $flags |= 128; - $messageId = (string) $headers['message-id']; - $size += 1 + \strlen($messageId); + if (isset($headers['message-id'])) { + $flags |= 128; + $messageId = (string)$headers['message-id']; + $size += 1 + \strlen($messageId); unset($headers['message-id']); } - if(isset($headers['timestamp'])) - { - $flags |= 64; - $timestamp = (int) $headers['timestamp']; - $size += 8; + if (isset($headers['timestamp'])) { + $flags |= 64; + $timestamp = (int)$headers['timestamp']; + $size += 8; unset($headers['timestamp']); } - if(isset($headers['type'])) - { + if (isset($headers['type'])) { $flags |= 32; - $type = (string) $headers['type']; - $size += 1 + \strlen($type); + $type = (string)$headers['type']; + $size += 1 + \strlen($type); unset($headers['type']); } - if(isset($headers['user-id'])) - { - $flags |= 16; - $userId = (string) $headers['user-id']; - $size += 1 + \strlen($userId); + if (isset($headers['user-id'])) { + $flags |= 16; + $userId = (string)$headers['user-id']; + $size += 1 + \strlen($userId); unset($headers['user-id']); } - if(isset($headers['app-id'])) - { + if (isset($headers['app-id'])) { $flags |= 8; - $appId = (string) $headers['app-id']; - $size += 1 + \strlen($appId); + $appId = (string)$headers['app-id']; + $size += 1 + \strlen($appId); unset($headers['app-id']); } - if(isset($headers['cluster-id'])) - { - $flags |= 4; - $clusterId = (string) $headers['cluster-id']; - $size += 1 + \strlen($clusterId); + if (isset($headers['cluster-id'])) { + $flags |= 4; + $clusterId = (string)$headers['cluster-id']; + $size += 1 + \strlen($clusterId); unset($headers['cluster-id']); } - if(!empty($headers)) - { - $flags |= 8192; + if (!empty($headers)) { + $flags |= 8192; $headersBuffer = new Buffer; $headersBuffer->appendTable($headers); $size += $headersBuffer->size(); @@ -1101,86 +1048,70 @@ public function doPublish ->appendUint64(\strlen($body)) ->appendUint16($flags); - if($flags & 32768) - { + if ($flags & 32768) { $buffer->appendString($contentType); } - if($flags & 16384) - { + if ($flags & 16384) { $buffer->appendString($contentEncoding); } - if($flags & 8192 && $headersBuffer !== null) - { + if ($flags & 8192 && $headersBuffer !== null) { $buffer->append($headersBuffer); } - if($flags & 4096) - { - $buffer->appendUint8((int) $deliveryMode); + if ($flags & 4096 && $deliveryMode !== null) { + $buffer->appendUint8($deliveryMode); } - if($flags & 2048) - { - $buffer->appendUint8((int) $priority); + if ($flags & 2048 && $priority !== null) { + $buffer->appendUint8($priority); } - if($flags & 1024) - { + if ($flags & 1024) { $buffer->appendString($correlationId); } - if($flags & 512) - { + if ($flags & 512) { $buffer->appendString($replyTo); } - if($flags & 256) - { + if ($flags & 256) { $buffer->appendString($expiration); } - if($flags & 128) - { + if ($flags & 128) { $buffer->appendString($messageId); } - if($flags & 64 && $timestamp !== null) - { + if ($flags & 64 && $timestamp !== null) { + /** @noinspection PhpUnhandledExceptionInspection */ $buffer->appendTimestamp(new \DateTimeImmutable(\sprintf('@%s', $timestamp))); } - if($flags & 32) - { + if ($flags & 32) { $buffer->appendString($type); } - if($flags & 16) - { + if ($flags & 16) { $buffer->appendString($userId); } - if($flags & 8) - { + if ($flags & 8) { $buffer->appendString($appId); } - if($flags & 4) - { + if ($flags & 4) { $buffer->appendString($clusterId); } $buffer->appendUint8(206); - if(!empty($body)) - { + if (!empty($body)) { $chunks = \str_split($body, $this->properties->maxFrame()); - if($chunks !== false) - { - foreach($chunks as $chunk) - { + if ($chunks !== false) { + foreach ($chunks as $chunk) { $buffer ->appendUint8(3) ->appendUint16($this->id) @@ -1211,8 +1142,7 @@ private function await(string $frame): Promise $this->connection->subscribe( $this->id, $frame, - static function(Protocol\AbstractFrame $frame) use ($deferred) - { + static function (Protocol\AbstractFrame $frame) use ($deferred) { $deferred->resolve($frame); return true; diff --git a/src/Client.php b/src/Client.php index e0238c2..9d135de 100644 --- a/src/Client.php +++ b/src/Client.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -20,8 +20,8 @@ final class Client { private const STATE_NOT_CONNECTED = 0; - private const STATE_CONNECTING = 1; - private const STATE_CONNECTED = 2; + private const STATE_CONNECTING = 1; + private const STATE_CONNECTED = 2; private const STATE_DISCONNECTING = 3; /** @@ -69,8 +69,7 @@ public static function create(string $dsn): self */ public function properties(): Properties { - if($this->state !== self::STATE_CONNECTED) - { + if ($this->state !== self::STATE_CONNECTED) { throw Exception\ClientException::notConnected(); } @@ -85,10 +84,8 @@ public function properties(): Properties public function connect(): Promise { return call( - function() - { - if($this->state !== self::STATE_NOT_CONNECTED) - { + function () { + if ($this->state !== self::STATE_NOT_CONNECTED) { throw Exception\ClientException::alreadyConnected(); } @@ -117,8 +114,7 @@ function() yield $this->connectionOpen(); asyncCall( - function() - { + function () { yield $this->await(Protocol\ConnectionCloseFrame::class); $buffer = new Buffer; @@ -148,26 +144,21 @@ function() public function disconnect(int $code = 0, string $reason = ''): Promise { return call( - function() use ($code, $reason) - { - if(\in_array($this->state, [self::STATE_NOT_CONNECTED, self::STATE_DISCONNECTING])) - { + function () use ($code, $reason) { + if (\in_array($this->state, [self::STATE_NOT_CONNECTED, self::STATE_DISCONNECTING])) { return; } - if($this->state !== self::STATE_CONNECTED) - { + if ($this->state !== self::STATE_CONNECTED) { throw Exception\ClientException::notConnected(); } $this->state = self::STATE_DISCONNECTING; - if($code === 0) - { + if ($code === 0) { $promises = []; - foreach($this->channels as $id => $channel) - { + foreach ($this->channels as $id => $channel) { $promises[] = $channel->close($code, $reason); } @@ -191,16 +182,13 @@ function() use ($code, $reason) public function channel(): Promise { return call( - function() - { - if($this->state !== self::STATE_CONNECTED) - { + function () { + if ($this->state !== self::STATE_CONNECTED) { throw Exception\ClientException::notConnected(); } - try - { - $id = $this->findChannelId(); + try { + $id = $this->findChannelId(); $channel = new Channel($id, $this->connection, $this->properties); $this->channels[$id] = $channel; @@ -208,8 +196,7 @@ function() yield $channel->open(); yield $channel->qos($this->config->qosSize, $this->config->qosCount, $this->config->qosGlobal); - asyncCall(function() use ($id) - { + asyncCall(function () use ($id) { /** @var Protocol\ChannelCloseFrame|Protocol\ChannelCloseOkFrame $frame */ $frame = yield Promise\first([ $this->await(Protocol\ChannelCloseFrame::class, $id), @@ -218,8 +205,7 @@ function() $this->connection->cancel($id); - if($frame instanceof Protocol\ChannelCloseFrame) - { + if ($frame instanceof Protocol\ChannelCloseFrame) { $buffer = new Buffer; $buffer ->appendUint8(1) @@ -236,9 +222,7 @@ function() }); return $channel; - } - catch(\Throwable $error) - { + } catch (\Throwable $error) { throw Exception\ClientException::unexpectedResponse($error); } } @@ -258,13 +242,11 @@ public function isConnected(): bool private function connectionStart(): Promise { return call( - function() - { + function () { /** @var Protocol\ConnectionStartFrame $start */ $start = yield $this->await(Protocol\ConnectionStartFrame::class); - if(!\str_contains($start->mechanisms, 'AMQPLAIN')) - { + if (!\str_contains($start->mechanisms, 'AMQPLAIN')) { throw Exception\ClientException::notSupported($start->mechanisms); } @@ -273,7 +255,7 @@ function() $buffer = new Buffer; $buffer ->appendTable([ - 'LOGIN' => $this->config->user, + 'LOGIN' => $this->config->user, 'PASSWORD' => $this->config->pass, ]) ->discard(4); @@ -284,7 +266,7 @@ function() ->appendUint16(11) ->appendTable([]) ->appendString('AMQPLAIN') - ->appendText((string) $buffer) + ->appendText((string)$buffer) ->appendString('en_US'); return $this->connection->method(0, $frameBuffer); @@ -298,20 +280,18 @@ function() private function connectionTune(): Promise { return call( - function() - { + function () { /** @var Protocol\ConnectionTuneFrame $tune */ $tune = yield $this->await(Protocol\ConnectionTuneFrame::class); $heartbeatInterval = $this->config->heartbeat; - if($heartbeatInterval !== 0) - { + if ($heartbeatInterval !== 0) { $heartbeatInterval = \min($heartbeatInterval, $tune->heartbeat); } $maxChannel = \min($this->config->maxChannel, $tune->channelMax); - $maxFrame = \min($this->config->maxFrame, $tune->frameMax); + $maxFrame = \min($this->config->maxFrame, $tune->frameMax); $buffer = new Buffer; $buffer @@ -329,8 +309,7 @@ function() $this->properties->tune($maxChannel, $maxFrame); - if($heartbeatInterval > 0) - { + if ($heartbeatInterval > 0) { $this->connection->heartbeat($heartbeatInterval); } } @@ -343,11 +322,10 @@ function() private function connectionOpen(): Promise { return call( - function() - { - $vhost = $this->config->vhost; + function () { + $vhost = $this->config->vhost; $capabilities = ''; - $insist = false; + $insist = false; $buffer = new Buffer; $buffer @@ -374,8 +352,7 @@ function() private function connectionClose(int $code, string $reason): Promise { return call( - function() use ($code, $reason) - { + function () use ($code, $reason) { $buffer = new Buffer; $buffer ->appendUint8(1) @@ -402,10 +379,8 @@ function() use ($code, $reason) private function findChannelId(): int { /** first check in range [next, max] ... */ - for($id = $this->nextChannelId; $id <= $this->config->maxChannel; ++$id) - { - if(!isset($this->channels[$id])) - { + for ($id = $this->nextChannelId; $id <= $this->config->maxChannel; ++$id) { + if (!isset($this->channels[$id])) { $this->nextChannelId = $id + 1; return $id; @@ -413,10 +388,8 @@ private function findChannelId(): int } /** then check in range [min, next) ... */ - for($id = 1; $id < $this->nextChannelId; ++$id) - { - if(!isset($this->channels[$id])) - { + for ($id = 1; $id < $this->nextChannelId; ++$id) { + if (!isset($this->channels[$id])) { $this->nextChannelId = $id + 1; return $id; @@ -441,8 +414,7 @@ private function await(string $frame, int $channel = 0): Promise $this->connection->subscribe( $channel, $frame, - static function(Protocol\AbstractFrame $frame) use ($deferred) - { + static function (Protocol\AbstractFrame $frame) use ($deferred) { $deferred->resolve($frame); return true; diff --git a/src/Config.php b/src/Config.php index 877b801..00f6f6c 100644 --- a/src/Config.php +++ b/src/Config.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -16,11 +16,11 @@ final class Config { - private const DEFAULT_HOST = 'localhost'; - private const DEFAULT_PORT = 5672; - private const DEFAULT_VHOST = '/'; - private const DEFAULT_USER = 'guest'; - private const DEFAULT_PASS = 'guest'; + private const DEFAULT_HOST = 'localhost'; + private const DEFAULT_PORT = 5672; + private const DEFAULT_VHOST = '/'; + private const DEFAULT_USER = 'guest'; + private const DEFAULT_PASS = 'guest'; /** * @var string @@ -102,12 +102,11 @@ public function __construct( string $user = self::DEFAULT_USER, string $pass = self::DEFAULT_PASS, string $vhost = null - ) - { - $this->host = $host; - $this->port = $port; - $this->user = $user; - $this->pass = $pass; + ) { + $this->host = $host; + $this->port = $port; + $this->user = $user; + $this->pass = $pass; $this->vhost = $vhost ?: self::DEFAULT_VHOST; } @@ -116,27 +115,23 @@ public function __construct( */ public static function parse(string $dsn): self { - if($dsn === '') - { + if ($dsn === '') { throw ConfigurationException::emptyDSN(); } $parts = \parse_url($dsn); - if($parts === false) - { + if ($parts === false) { throw ConfigurationException::incorrectDSN($dsn); } \parse_str($parts['query'] ?? '', $options); - if(isset($parts['path']) && $parts['path'] !== '') - { + if (isset($parts['path']) && $parts['path'] !== '') { /** @var string|false $vhost */ $vhost = \substr($parts['path'], 1); - if($vhost !== false) - { + if ($vhost !== false) { $parts['path'] = $vhost; } } @@ -149,49 +144,40 @@ public static function parse(string $dsn): self $parts['path'] ?? self::DEFAULT_VHOST, ); - if(isset($options['timeout'])) - { - $self->timeout = (int) $options['timeout']; + if (isset($options['timeout'])) { + $self->timeout = (int)$options['timeout']; } - if(isset($options['heartbeat'])) - { - $self->heartbeat = (int) $options['heartbeat']; + if (isset($options['heartbeat'])) { + $self->heartbeat = (int)$options['heartbeat']; } - if(isset($options['max_frame'])) - { - $self->maxFrame = (int) $options['max_frame']; + if (isset($options['max_frame'])) { + $self->maxFrame = (int)$options['max_frame']; } - if(isset($options['max_channel'])) - { - $self->maxChannel = (int) $options['max_channel']; + if (isset($options['max_channel'])) { + $self->maxChannel = (int)$options['max_channel']; } - if(isset($options['qos_size'])) - { - $self->qosSize = (int) $options['qos_size']; + if (isset($options['qos_size'])) { + $self->qosSize = (int)$options['qos_size']; } - if(isset($options['qos_count'])) - { - $self->qosCount = (int) $options['qos_count']; + if (isset($options['qos_count'])) { + $self->qosCount = (int)$options['qos_count']; } - if(isset($options['qos_global'])) - { - $self->qosGlobal = (bool) $options['qos_global']; + if (isset($options['qos_global'])) { + $self->qosGlobal = (bool)$options['qos_global']; } - if(isset($options['tcp_nodelay'])) - { - $self->tcpNoDelay = (bool) $options['tcp_nodelay']; + if (isset($options['tcp_nodelay'])) { + $self->tcpNoDelay = (bool)$options['tcp_nodelay']; } - if(isset($options['tcp_attempts'])) - { - $self->tcpAttempts = (int) $options['tcp_attempts']; + if (isset($options['tcp_attempts'])) { + $self->tcpAttempts = (int)$options['tcp_attempts']; } return $self; diff --git a/src/Connection.php b/src/Connection.php index a968888..7b4b3a1 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -55,7 +55,7 @@ final class Connection public function __construct(string $uri) { - $this->uri = $uri; + $this->uri = $uri; $this->parser = new Parser; } @@ -66,14 +66,10 @@ public function write(Buffer $payload): Promise { $this->lastWrite = Loop::now(); - if($this->socket !== null) - { - try - { + if ($this->socket !== null) { + try { return $this->socket->write($payload->flush()); - } - catch(\Throwable $throwable) - { + } catch (\Throwable $throwable) { throw ConnectionException::writeFailed($throwable); } } @@ -114,41 +110,33 @@ public function cancel(int $channel): void public function open(int $timeout, int $maxAttempts, bool $noDelay): Promise { return call( - function() use ($timeout, $maxAttempts, $noDelay) - { + function () use ($timeout, $maxAttempts, $noDelay) { $context = new ConnectContext(); - if($maxAttempts > 0) - { + if ($maxAttempts > 0) { $context = $context->withMaxAttempts($maxAttempts); } - if($timeout > 0) - { + if ($timeout > 0) { $context = $context->withConnectTimeout($timeout); } - if($noDelay) - { + if ($noDelay) { $context = $context->withTcpNoDelay(); } $this->socket = yield connect($this->uri, $context); asyncCall( - function() - { - if($this->socket === null) - { + function () { + if ($this->socket === null) { throw ConnectionException::socketClosed(); } - while(null !== $chunk = yield $this->socket->read()) - { + while (null !== $chunk = yield $this->socket->read()) { $this->parser->append($chunk); - while($frame = $this->parser->parse()) - { + while ($frame = $this->parser->parse()) { /** @var AbstractFrame $frame */ $class = \get_class($frame); @@ -157,11 +145,9 @@ function() * @psalm-var int $i * @psalm-var callable(AbstractFrame):Promise $callback */ - foreach($this->callbacks[(int) $frame->channel][$class] ?? [] as $i => $callback) - { - if(yield call($callback, $frame)) - { - unset($this->callbacks[(int) $frame->channel][$class][$i]); + foreach ($this->callbacks[(int)$frame->channel][$class] ?? [] as $i => $callback) { + if (yield call($callback, $frame)) { + unset($this->callbacks[(int)$frame->channel][$class][$i]); } } } @@ -178,22 +164,19 @@ public function heartbeat(int $interval): void { $this->heartbeatWatcherId = Loop::repeat( $interval, - function(string $watcherId) use ($interval) - { - if($this->socket === null) - { + function (string $watcherId) use ($interval) { + if ($this->socket === null) { Loop::cancel($watcherId); return; } $currentTime = Loop::now(); - $lastWrite = $this->lastWrite ?: $currentTime; + $lastWrite = $this->lastWrite ?: $currentTime; $nextHeartbeat = $lastWrite + $interval; - if($currentTime >= $nextHeartbeat) - { + if ($currentTime >= $nextHeartbeat) { yield $this->write((new Buffer) ->appendUint8(8) ->appendUint16(0) @@ -211,15 +194,13 @@ public function close(): void { $this->callbacks = []; - if($this->heartbeatWatcherId !== null) - { + if ($this->heartbeatWatcherId !== null) { Loop::cancel($this->heartbeatWatcherId); $this->heartbeatWatcherId = null; } - if($this->socket !== null) - { + if ($this->socket !== null) { $this->socket->close(); } } diff --git a/src/Constants.php b/src/Constants.php index 965ea88..2ffae93 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -16,130 +16,130 @@ final class Constants { public const CONNECTION_CHANNEL = 0; - public const FRAME_METHOD = 1; - public const FRAME_HEADER = 2; - public const FRAME_BODY = 3; + public const FRAME_METHOD = 1; + public const FRAME_HEADER = 2; + public const FRAME_BODY = 3; public const FRAME_HEARTBEAT = 8; - public const FRAME_MIN_SIZE = 4096; - public const FRAME_END = 0xCE; + public const FRAME_MIN_SIZE = 4096; + public const FRAME_END = 0xCE; - public const STATUS_REPLY_SUCCESS = 200; - public const STATUS_CONTENT_TOO_LARGE = 311; - public const STATUS_NO_ROUTE = 312; - public const STATUS_NO_CONSUMERS = 313; - public const STATUS_CONNECTION_FORCED = 320; - public const STATUS_INVALID_PATH = 402; - public const STATUS_ACCESS_REFUSED = 403; - public const STATUS_NOT_FOUND = 404; - public const STATUS_RESOURCE_LOCKED = 405; + public const STATUS_REPLY_SUCCESS = 200; + public const STATUS_CONTENT_TOO_LARGE = 311; + public const STATUS_NO_ROUTE = 312; + public const STATUS_NO_CONSUMERS = 313; + public const STATUS_CONNECTION_FORCED = 320; + public const STATUS_INVALID_PATH = 402; + public const STATUS_ACCESS_REFUSED = 403; + public const STATUS_NOT_FOUND = 404; + public const STATUS_RESOURCE_LOCKED = 405; public const STATUS_PRECONDITION_FAILED = 406; - public const STATUS_FRAME_ERROR = 501; - public const STATUS_SYNTAX_ERROR = 502; - public const STATUS_COMMAND_INVALID = 503; - public const STATUS_CHANNEL_ERROR = 504; - public const STATUS_UNEXPECTED_FRAME = 505; - public const STATUS_RESOURCE_ERROR = 506; - public const STATUS_NOT_ALLOWED = 530; - public const STATUS_NOT_IMPLEMENTED = 540; - public const STATUS_INTERNAL_ERROR = 541; + public const STATUS_FRAME_ERROR = 501; + public const STATUS_SYNTAX_ERROR = 502; + public const STATUS_COMMAND_INVALID = 503; + public const STATUS_CHANNEL_ERROR = 504; + public const STATUS_UNEXPECTED_FRAME = 505; + public const STATUS_RESOURCE_ERROR = 506; + public const STATUS_NOT_ALLOWED = 530; + public const STATUS_NOT_IMPLEMENTED = 540; + public const STATUS_INTERNAL_ERROR = 541; public const CLASS_CONNECTION = 10; - public const CLASS_CHANNEL = 20; - public const CLASS_ACCESS = 30; - public const CLASS_EXCHANGE = 40; - public const CLASS_QUEUE = 50; - public const CLASS_BASIC = 60; - public const CLASS_TX = 90; - public const CLASS_CONFIRM = 85; + public const CLASS_CHANNEL = 20; + public const CLASS_ACCESS = 30; + public const CLASS_EXCHANGE = 40; + public const CLASS_QUEUE = 50; + public const CLASS_BASIC = 60; + public const CLASS_TX = 90; + public const CLASS_CONFIRM = 85; - public const METHOD_CONNECTION_START = 10; - public const METHOD_CONNECTION_START_OK = 11; - public const METHOD_CONNECTION_SECURE = 20; + public const METHOD_CONNECTION_START = 10; + public const METHOD_CONNECTION_START_OK = 11; + public const METHOD_CONNECTION_SECURE = 20; public const METHOD_CONNECTION_SECURE_OK = 21; - public const METHOD_CONNECTION_TUNE = 30; - public const METHOD_CONNECTION_TUNE_OK = 31; - public const METHOD_CONNECTION_OPEN = 40; - public const METHOD_CONNECTION_OPEN_OK = 41; - public const METHOD_CONNECTION_CLOSE = 50; - public const METHOD_CONNECTION_CLOSE_OK = 51; - public const METHOD_CONNECTION_BLOCKED = 60; + public const METHOD_CONNECTION_TUNE = 30; + public const METHOD_CONNECTION_TUNE_OK = 31; + public const METHOD_CONNECTION_OPEN = 40; + public const METHOD_CONNECTION_OPEN_OK = 41; + public const METHOD_CONNECTION_CLOSE = 50; + public const METHOD_CONNECTION_CLOSE_OK = 51; + public const METHOD_CONNECTION_BLOCKED = 60; public const METHOD_CONNECTION_UNBLOCKED = 61; - public const METHOD_CHANNEL_OPEN = 10; - public const METHOD_CHANNEL_OPEN_OK = 11; - public const METHOD_CHANNEL_FLOW = 20; - public const METHOD_CHANNEL_FLOW_OK = 21; - public const METHOD_CHANNEL_CLOSE = 40; + public const METHOD_CHANNEL_OPEN = 10; + public const METHOD_CHANNEL_OPEN_OK = 11; + public const METHOD_CHANNEL_FLOW = 20; + public const METHOD_CHANNEL_FLOW_OK = 21; + public const METHOD_CHANNEL_CLOSE = 40; public const METHOD_CHANNEL_CLOSE_OK = 41; - public const METHOD_ACCESS_REQUEST = 10; + public const METHOD_ACCESS_REQUEST = 10; public const METHOD_ACCESS_REQUEST_OK = 11; - public const METHOD_EXCHANGE_DECLARE = 10; + public const METHOD_EXCHANGE_DECLARE = 10; public const METHOD_EXCHANGE_DECLARE_OK = 11; - public const METHOD_EXCHANGE_DELETE = 20; - public const METHOD_EXCHANGE_DELETE_OK = 21; - public const METHOD_EXCHANGE_BIND = 30; - public const METHOD_EXCHANGE_BIND_OK = 31; - public const METHOD_EXCHANGE_UNBIND = 40; - public const METHOD_EXCHANGE_UNBIND_OK = 51; + public const METHOD_EXCHANGE_DELETE = 20; + public const METHOD_EXCHANGE_DELETE_OK = 21; + public const METHOD_EXCHANGE_BIND = 30; + public const METHOD_EXCHANGE_BIND_OK = 31; + public const METHOD_EXCHANGE_UNBIND = 40; + public const METHOD_EXCHANGE_UNBIND_OK = 51; - public const METHOD_QUEUE_DECLARE = 10; + public const METHOD_QUEUE_DECLARE = 10; public const METHOD_QUEUE_DECLARE_OK = 11; - public const METHOD_QUEUE_BIND = 20; - public const METHOD_QUEUE_BIND_OK = 21; - public const METHOD_QUEUE_PURGE = 30; - public const METHOD_QUEUE_PURGE_OK = 31; - public const METHOD_QUEUE_DELETE = 40; - public const METHOD_QUEUE_DELETE_OK = 41; - public const METHOD_QUEUE_UNBIND = 50; - public const METHOD_QUEUE_UNBIND_OK = 51; + public const METHOD_QUEUE_BIND = 20; + public const METHOD_QUEUE_BIND_OK = 21; + public const METHOD_QUEUE_PURGE = 30; + public const METHOD_QUEUE_PURGE_OK = 31; + public const METHOD_QUEUE_DELETE = 40; + public const METHOD_QUEUE_DELETE_OK = 41; + public const METHOD_QUEUE_UNBIND = 50; + public const METHOD_QUEUE_UNBIND_OK = 51; - public const METHOD_BASIC_QOS = 10; - public const METHOD_BASIC_QOS_OK = 11; - public const METHOD_BASIC_CONSUME = 20; - public const METHOD_BASIC_CONSUME_OK = 21; - public const METHOD_BASIC_CANCEL = 30; - public const METHOD_BASIC_CANCEL_OK = 31; - public const METHOD_BASIC_PUBLISH = 40; - public const METHOD_BASIC_RETURN = 50; - public const METHOD_BASIC_DELIVER = 60; - public const METHOD_BASIC_GET = 70; - public const METHOD_BASIC_GET_OK = 71; - public const METHOD_BASIC_GET_EMPTY = 72; - public const METHOD_BASIC_ACK = 80; - public const METHOD_BASIC_REJECT = 90; + public const METHOD_BASIC_QOS = 10; + public const METHOD_BASIC_QOS_OK = 11; + public const METHOD_BASIC_CONSUME = 20; + public const METHOD_BASIC_CONSUME_OK = 21; + public const METHOD_BASIC_CANCEL = 30; + public const METHOD_BASIC_CANCEL_OK = 31; + public const METHOD_BASIC_PUBLISH = 40; + public const METHOD_BASIC_RETURN = 50; + public const METHOD_BASIC_DELIVER = 60; + public const METHOD_BASIC_GET = 70; + public const METHOD_BASIC_GET_OK = 71; + public const METHOD_BASIC_GET_EMPTY = 72; + public const METHOD_BASIC_ACK = 80; + public const METHOD_BASIC_REJECT = 90; public const METHOD_BASIC_RECOVER_ASYNC = 100; - public const METHOD_BASIC_RECOVER = 110; - public const METHOD_BASIC_RECOVER_OK = 111; - public const METHOD_BASIC_NACK = 120; + public const METHOD_BASIC_RECOVER = 110; + public const METHOD_BASIC_RECOVER_OK = 111; + public const METHOD_BASIC_NACK = 120; - public const METHOD_TX_SELECT = 10; - public const METHOD_TX_SELECT_OK = 11; - public const METHOD_TX_COMMIT = 20; - public const METHOD_TX_COMMIT_OK = 21; - public const METHOD_TX_ROLLBACK = 30; + public const METHOD_TX_SELECT = 10; + public const METHOD_TX_SELECT_OK = 11; + public const METHOD_TX_COMMIT = 20; + public const METHOD_TX_COMMIT_OK = 21; + public const METHOD_TX_ROLLBACK = 30; public const METHOD_TX_ROLLBACK_OK = 31; - public const METHOD_CONFIRM_SELECT = 10; + public const METHOD_CONFIRM_SELECT = 10; public const METHOD_CONFIRM_SELECT_OK = 11; - public const FIELD_BOOLEAN = 0x74; // 't' - public const FIELD_SHORT_SHORT_INT = 0x62; // 'b' + public const FIELD_BOOLEAN = 0x74; // 't' + public const FIELD_SHORT_SHORT_INT = 0x62; // 'b' public const FIELD_SHORT_SHORT_UINT = 0x42; // 'B' - public const FIELD_SHORT_INT = 0x55; // 'U' - public const FIELD_SHORT_UINT = 0x75; // 'u' - public const FIELD_LONG_INT = 0x49; // 'I' - public const FIELD_LONG_UINT = 0x69; // 'i' - public const FIELD_LONG_LONG_INT = 0x4C; // 'L' - public const FIELD_LONG_LONG_UINT = 0x6C; // 'l' - public const FIELD_FLOAT = 0x66; // 'f' - public const FIELD_DOUBLE = 0x64; // 'd' - public const FIELD_DECIMAL = 0x44; // 'D' - public const FIELD_SHORT_STRING = 0x73; // 's' - public const FIELD_LONG_STRING = 0x53; // 'S' - public const FIELD_ARRAY = 0x41; // 'A' - public const FIELD_TIMESTAMP = 0x54; // 'T' - public const FIELD_TABLE = 0x46; // 'F' - public const FIELD_NULL = 0x56; // 'V' + public const FIELD_SHORT_INT = 0x55; // 'U' + public const FIELD_SHORT_UINT = 0x75; // 'u' + public const FIELD_LONG_INT = 0x49; // 'I' + public const FIELD_LONG_UINT = 0x69; // 'i' + public const FIELD_LONG_LONG_INT = 0x4C; // 'L' + public const FIELD_LONG_LONG_UINT = 0x6C; // 'l' + public const FIELD_FLOAT = 0x66; // 'f' + public const FIELD_DOUBLE = 0x64; // 'd' + public const FIELD_DECIMAL = 0x44; // 'D' + public const FIELD_SHORT_STRING = 0x73; // 's' + public const FIELD_LONG_STRING = 0x53; // 'S' + public const FIELD_ARRAY = 0x41; // 'A' + public const FIELD_TIMESTAMP = 0x54; // 'T' + public const FIELD_TABLE = 0x46; // 'F' + public const FIELD_NULL = 0x56; // 'V' } diff --git a/src/Consumer.php b/src/Consumer.php index 5fac714..f4defdd 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -34,22 +34,19 @@ final class Consumer public function __construct(Channel $channel, MessageReceiver $receiver) { - $this->channel = $channel; + $this->channel = $channel; $this->receiver = $receiver; } public function start(): void { $this->receiver->onMessage( - function(Message $message) - { - if(!$tag = $message->consumerTag()) - { + function (Message $message) { + if (!$tag = $message->consumerTag) { return; } - if(!isset($this->listeners[$tag])) - { + if (!isset($this->listeners[$tag])) { return; } diff --git a/src/Events.php b/src/Events.php index d0ee600..b221468 100644 --- a/src/Events.php +++ b/src/Events.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -28,7 +28,7 @@ final class Events public function __construct(Channel $channel, MessageReceiver $receiver) { - $this->channel = $channel; + $this->channel = $channel; $this->receiver = $receiver; } @@ -49,10 +49,8 @@ public function onNack(callable $listener): self public function onReturn(callable $listener): self { $this->receiver->onMessage( - function(Message $message) use ($listener) - { - if(!$message->returned()) - { + function (Message $message) use ($listener) { + if (!$message->returned) { return; } @@ -71,8 +69,7 @@ private function onFrame(string $frame, callable $callback): void { $this->receiver->onFrame( $frame, - function(Protocol\AcknowledgmentFrame $frame) use ($callback) - { + function (Protocol\AcknowledgmentFrame $frame) use ($callback) { /** @psalm-suppress MixedArgumentTypeCoercion */ asyncCall($callback, $frame->deliveryTag, $frame->multiple, $this->channel); } diff --git a/src/Exception/ClassInvalid.php b/src/Exception/ClassInvalid.php index 8024ffd..ada21b3 100644 --- a/src/Exception/ClassInvalid.php +++ b/src/Exception/ClassInvalid.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge\Exception; diff --git a/src/Exception/ClientException.php b/src/Exception/ClientException.php index c422f23..d7b2b40 100644 --- a/src/Exception/ClientException.php +++ b/src/Exception/ClientException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge\Exception; @@ -18,7 +18,7 @@ final class ClientException extends RidgeException { public static function unexpectedResponse(\Throwable $error): self { - return new self('Unexpected response.', (int) $error->getCode(), $error); + return new self('Unexpected response.', (int)$error->getCode(), $error); } public static function notConnected(): self diff --git a/src/Exception/ConfigurationException.php b/src/Exception/ConfigurationException.php index 36ee67f..d25661c 100644 --- a/src/Exception/ConfigurationException.php +++ b/src/Exception/ConfigurationException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge\Exception; diff --git a/src/Exception/ConnectionException.php b/src/Exception/ConnectionException.php index d036ed1..b952207 100644 --- a/src/Exception/ConnectionException.php +++ b/src/Exception/ConnectionException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge\Exception; @@ -21,7 +21,7 @@ public static function writeFailed(\Throwable $previous): self { return new self( \sprintf('Error writing to socket: %s', $previous->getMessage()), - (int) $previous->getCode(), + (int)$previous->getCode(), $previous ); } diff --git a/src/Exception/MethodInvalid.php b/src/Exception/MethodInvalid.php index 4eaf265..0ed160f 100644 --- a/src/Exception/MethodInvalid.php +++ b/src/Exception/MethodInvalid.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge\Exception; diff --git a/src/Exception/ProtocolException.php b/src/Exception/ProtocolException.php index cb4c584..74c0978 100644 --- a/src/Exception/ProtocolException.php +++ b/src/Exception/ProtocolException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge\Exception; @@ -56,4 +56,9 @@ public static function unknownValueType(mixed $value): self return new self(\sprintf('Unhandled value type `%s`%s.', \gettype($value), $class)); } + + public static function unsupportedDeliveryTag(): self + { + return new self('Delivery tag can\'t be null'); + } } diff --git a/src/Exception/RidgeException.php b/src/Exception/RidgeException.php index c7a2c1e..a1fd0ab 100644 --- a/src/Exception/RidgeException.php +++ b/src/Exception/RidgeException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge\Exception; diff --git a/src/Message.php b/src/Message.php index 104d3ac..3d1a3ea 100644 --- a/src/Message.php +++ b/src/Message.php @@ -15,44 +15,60 @@ final class Message { /** + * @psalm-readonly + * * @var string */ - private $content; + public $content; /** + * @psalm-readonly + * * @var string */ - private $exchange; + public $exchange; /** + * @psalm-readonly + * * @var string */ - private $routingKey; + public $routingKey; /** + * @psalm-readonly + * * @var string|null */ - private $consumerTag; + public $consumerTag; /** + * @psalm-readonly + * * @var int|null */ - private $deliveryTag; + public $deliveryTag; /** + * @psalm-readonly + * * @var bool */ - private $redelivered; + public $redelivered; /** + * @psalm-readonly + * * @var bool */ - private $returned; + public $returned; /** + * @psalm-readonly + * * @var array */ - private $headers; + public $headers; public function __construct( string $content, @@ -64,54 +80,14 @@ public function __construct( bool $returned = false, array $headers = [] ) { - $this->content = $content; - $this->exchange = $exchange; - $this->routingKey = $routingKey; + $this->content = $content; + $this->exchange = $exchange; + $this->routingKey = $routingKey; $this->consumerTag = $consumerTag; $this->deliveryTag = $deliveryTag; $this->redelivered = $redelivered; - $this->returned = $returned; - $this->headers = $headers; - } - - public function content(): string - { - return $this->content; - } - - public function exchange(): string - { - return $this->exchange; - } - - public function routingKey(): string - { - return $this->routingKey; - } - - public function consumerTag(): ?string - { - return $this->consumerTag; - } - - public function deliveryTag(): ?int - { - return $this->deliveryTag; - } - - public function redelivered(): bool - { - return $this->redelivered; - } - - public function returned(): bool - { - return $this->returned; - } - - public function headers(): array - { - return $this->headers; + $this->returned = $returned; + $this->headers = $headers; } public function header(string $name, mixed $default = null): mixed diff --git a/src/MessageReceiver.php b/src/MessageReceiver.php index a8e2707..e778f47 100644 --- a/src/MessageReceiver.php +++ b/src/MessageReceiver.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -68,9 +68,9 @@ final class MessageReceiver public function __construct(Channel $channel, Connection $connection) { - $this->channel = $channel; + $this->channel = $channel; $this->connection = $connection; - $this->buffer = new Buffer; + $this->buffer = new Buffer; } public function start(): void @@ -101,35 +101,32 @@ public function onFrame(string $frame, callable $callback): void public function receiveReturn(Protocol\BasicReturnFrame $frame): void { - if($this->state !== self::STATE_WAIT) - { + if ($this->state !== self::STATE_WAIT) { return; } $this->return = $frame; - $this->state = self::STATE_HEAD; + $this->state = self::STATE_HEAD; } public function receiveDeliver(Protocol\BasicDeliverFrame $frame): void { - if($this->state !== self::STATE_WAIT) - { + if ($this->state !== self::STATE_WAIT) { return; } $this->deliver = $frame; - $this->state = self::STATE_HEAD; + $this->state = self::STATE_HEAD; } public function receiveHeader(Protocol\ContentHeaderFrame $frame): void { - if($this->state !== self::STATE_HEAD) - { + if ($this->state !== self::STATE_HEAD) { return; } - $this->state = self::STATE_BODY; - $this->header = $frame; + $this->state = self::STATE_BODY; + $this->header = $frame; $this->remaining = $frame->bodySize; $this->runCallbacks(); @@ -137,17 +134,15 @@ public function receiveHeader(Protocol\ContentHeaderFrame $frame): void public function receiveBody(Protocol\ContentBodyFrame $frame): void { - if($this->state !== self::STATE_BODY) - { + if ($this->state !== self::STATE_BODY) { return; } - $this->buffer->append((string) $frame->payload); + $this->buffer->append((string)$frame->payload); - $this->remaining -= (int) $frame->size; + $this->remaining -= (int)$frame->size; - if($this->remaining < 0) - { + if ($this->remaining < 0) { throw Exception\ChannelException::bodyOverflow($this->remaining); } @@ -159,13 +154,11 @@ public function receiveBody(Protocol\ContentBodyFrame $frame): void */ private function runCallbacks(): void { - if($this->remaining !== 0) - { + if ($this->remaining !== 0) { return; } - if($this->return) - { + if ($this->return) { $message = new Message( $this->buffer->flush(), $this->return->exchange, @@ -176,31 +169,28 @@ private function runCallbacks(): void true, $this->header !== null ? $this->header->toArray() : [] ); - } - else if($this->deliver) - { - $message = new Message( - $this->buffer->flush(), - $this->deliver->exchange, - $this->deliver->routingKey, - $this->deliver->consumerTag, - $this->deliver->deliveryTag, - $this->deliver->redelivered, - false, - $this->header !== null ? $this->header->toArray() : [] - ); - } - else - { - throw Exception\ChannelException::frameOrder(); + } else { + if ($this->deliver) { + $message = new Message( + $this->buffer->flush(), + $this->deliver->exchange, + $this->deliver->routingKey, + $this->deliver->consumerTag, + $this->deliver->deliveryTag, + $this->deliver->redelivered, + false, + $this->header !== null ? $this->header->toArray() : [] + ); + } else { + throw Exception\ChannelException::frameOrder(); + } } - $this->return = null; + $this->return = null; $this->deliver = null; - $this->header = null; + $this->header = null; - foreach($this->callbacks as $callback) - { + foreach ($this->callbacks as $callback) { /** @psalm-suppress MixedArgumentTypeCoercion */ asyncCall($callback, $message); } diff --git a/src/Parser.php b/src/Parser.php index 80959c8..7c85d6b 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -37,39 +37,35 @@ public function append(string $chunk): void */ public function parse(): ?Protocol\AbstractFrame { - if($this->buffer->size() < 7) - { + if ($this->buffer->size() < 7) { return null; } - $size = $this->buffer->readUint32(3); + $size = $this->buffer->readUint32(3); $length = $size + 8; - if($this->buffer->size() < $length) - { + if ($this->buffer->size() < $length) { return null; } - $type = $this->buffer->readUint8(); - $channel = $this->buffer->readUint16(1); - $payload = $this->buffer->read($size, 7); + $type = $this->buffer->readUint8(); + $channel = $this->buffer->readUint16(1); + $payload = $this->buffer->read($size, 7); $frameEnd = $this->buffer->readUint8($length - 1); $this->buffer->discard($length); - if($frameEnd !== Constants::FRAME_END) - { + if ($frameEnd !== Constants::FRAME_END) { throw Exception\ProtocolException::invalidFrameEnd($frameEnd); } - switch($type) - { + switch ($type) { case Constants::FRAME_HEADER: $frame = Protocol\ContentHeaderFrame::unpack(new Buffer($payload)); break; case Constants::FRAME_BODY: - $frame = new Protocol\ContentBodyFrame; + $frame = new Protocol\ContentBodyFrame; $frame->payload = $payload; break; @@ -86,8 +82,8 @@ public function parse(): ?Protocol\AbstractFrame } /** @var Protocol\AbstractFrame $frame */ - $frame->type = $type; - $frame->size = $size; + $frame->type = $type; + $frame->size = $size; $frame->channel = $channel; return $frame; @@ -101,11 +97,10 @@ public function parse(): ?Protocol\AbstractFrame */ private function consumeMethodFrame(Buffer $buffer): Protocol\MethodFrame { - $classId = $buffer->consumeUint16(); + $classId = $buffer->consumeUint16(); $methodId = $buffer->consumeUint16(); - return match ($classId) - { + return match ($classId) { Constants::CLASS_BASIC => $this->consumeBasicFrame($methodId, $buffer), Constants::CLASS_CONNECTION => $this->consumeConnectionFrame($methodId, $buffer), Constants::CLASS_CHANNEL => $this->consumeChannelFrame($methodId, $buffer), @@ -125,8 +120,7 @@ private function consumeMethodFrame(Buffer $buffer): Protocol\MethodFrame */ private function consumeBasicFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - return match ($methodId) - { + return match ($methodId) { Constants::METHOD_BASIC_DELIVER => Protocol\BasicDeliverFrame::unpack($buffer), Constants::METHOD_BASIC_GET => Protocol\BasicGetFrame::unpack($buffer), Constants::METHOD_BASIC_GET_OK => Protocol\BasicGetOkFrame::unpack($buffer), @@ -157,8 +151,7 @@ private function consumeBasicFrame(int $methodId, Buffer $buffer): Protocol\Meth */ private function consumeConnectionFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - return match ($methodId) - { + return match ($methodId) { Constants::METHOD_CONNECTION_START => Protocol\ConnectionStartFrame::unpack($buffer), Constants::METHOD_CONNECTION_START_OK => Protocol\ConnectionStartOkFrame::unpack($buffer), Constants::METHOD_CONNECTION_SECURE => Protocol\ConnectionSecureFrame::unpack($buffer), @@ -183,8 +176,7 @@ private function consumeConnectionFrame(int $methodId, Buffer $buffer): Protocol */ private function consumeChannelFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - return match ($methodId) - { + return match ($methodId) { Constants::METHOD_CHANNEL_OPEN => Protocol\ChannelOpenFrame::unpack($buffer), Constants::METHOD_CHANNEL_OPEN_OK => Protocol\ChannelOpenOkFrame::unpack($buffer), Constants::METHOD_CHANNEL_FLOW => Protocol\ChannelFlowFrame::unpack($buffer), @@ -203,8 +195,7 @@ private function consumeChannelFrame(int $methodId, Buffer $buffer): Protocol\Me */ private function consumeExchangeFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - return match ($methodId) - { + return match ($methodId) { Constants::METHOD_EXCHANGE_DECLARE => Protocol\ExchangeDeclareFrame::unpack($buffer), Constants::METHOD_EXCHANGE_DECLARE_OK => new Protocol\ExchangeDeclareOkFrame, Constants::METHOD_EXCHANGE_DELETE => Protocol\ExchangeDeleteFrame::unpack($buffer), @@ -225,8 +216,7 @@ private function consumeExchangeFrame(int $methodId, Buffer $buffer): Protocol\M */ private function consumeQueueFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - return match ($methodId) - { + return match ($methodId) { Constants::METHOD_QUEUE_DECLARE => Protocol\QueueDeclareFrame::unpack($buffer), Constants::METHOD_QUEUE_DECLARE_OK => Protocol\QueueDeclareOkFrame::unpack($buffer), Constants::METHOD_QUEUE_BIND => Protocol\QueueBindFrame::unpack($buffer), @@ -246,8 +236,7 @@ private function consumeQueueFrame(int $methodId, Buffer $buffer): Protocol\Meth */ private function consumeTxFrame(int $methodId): Protocol\MethodFrame { - return match ($methodId) - { + return match ($methodId) { Constants::METHOD_TX_SELECT => new Protocol\TxSelectFrame, Constants::METHOD_TX_SELECT_OK => new Protocol\TxSelectOkFrame, Constants::METHOD_TX_COMMIT => new Protocol\TxCommitFrame, @@ -264,8 +253,7 @@ private function consumeTxFrame(int $methodId): Protocol\MethodFrame */ private function consumeConfirmFrame(int $methodId, Buffer $buffer): Protocol\MethodFrame { - return match ($methodId) - { + return match ($methodId) { Constants::METHOD_CONFIRM_SELECT => Protocol\ConfirmSelectFrame::unpack($buffer), Constants::METHOD_CONFIRM_SELECT_OK => new Protocol\ConfirmSelectOkFrame, default => throw new Exception\MethodInvalid(Constants::CLASS_CONFIRM, $methodId), diff --git a/src/Properties.php b/src/Properties.php index 645f1e6..344b711 100644 --- a/src/Properties.php +++ b/src/Properties.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -63,9 +63,9 @@ final class Properties */ public function __construct(string $platform, string $product, string $version, array $capabilities) { - $this->platform = $platform; - $this->product = $product; - $this->version = $version; + $this->platform = $platform; + $this->product = $product; + $this->version = $version; $this->capabilities = $capabilities; } @@ -90,7 +90,7 @@ public static function create(array $config): self public function tune(int $maxChannel, int $maxFrame): void { $this->maxChannel = $maxChannel; - $this->maxFrame = $maxFrame; + $this->maxFrame = $maxFrame; } public function capable(string $ability): bool diff --git a/src/Protocol/AbstractFrame.php b/src/Protocol/AbstractFrame.php index bda45fb..c87d7ca 100644 --- a/src/Protocol/AbstractFrame.php +++ b/src/Protocol/AbstractFrame.php @@ -36,9 +36,9 @@ abstract class AbstractFrame public function __construct(?int $type = null, ?int $channel = null, ?int $size = null, ?string $payload = null) { - $this->type = $type; + $this->type = $type; $this->channel = $channel; - $this->size = $size; + $this->size = $size; $this->payload = $payload; } } \ No newline at end of file diff --git a/src/Protocol/BasicAckFrame.php b/src/Protocol/BasicAckFrame.php index d81353d..cde5d0d 100644 --- a/src/Protocol/BasicAckFrame.php +++ b/src/Protocol/BasicAckFrame.php @@ -27,17 +27,17 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->deliveryTag = $buffer->consumeInt64(); - [$self->multiple] = $buffer->consumeBits(1); - + [$self->multiple] = $buffer->consumeBits(1); + return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendInt64($this->deliveryTag); $buffer->appendBits([$this->multiple]); - + return $buffer; } } diff --git a/src/Protocol/BasicCancelFrame.php b/src/Protocol/BasicCancelFrame.php index 5214c97..261ce40 100644 --- a/src/Protocol/BasicCancelFrame.php +++ b/src/Protocol/BasicCancelFrame.php @@ -37,8 +37,8 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->consumerTag = $buffer->consumeString(); - [$self->nowait] = $buffer->consumeBits(1); - + [$self->nowait] = $buffer->consumeBits(1); + return $self; } @@ -47,7 +47,7 @@ public function pack(): Buffer $buffer = parent::pack(); $buffer->appendString($this->consumerTag); $buffer->appendBits([$this->nowait]); - + return $buffer; } } diff --git a/src/Protocol/BasicCancelOkFrame.php b/src/Protocol/BasicCancelOkFrame.php index 597ce9f..25f4ad2 100644 --- a/src/Protocol/BasicCancelOkFrame.php +++ b/src/Protocol/BasicCancelOkFrame.php @@ -19,7 +19,7 @@ class BasicCancelOkFrame extends MethodFrame * @var string */ public $consumerTag; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_CANCEL_OK); @@ -32,7 +32,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->consumerTag = $buffer->consumeString(); - + return $self; } @@ -40,7 +40,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendString($this->consumerTag); - + return $buffer; } } diff --git a/src/Protocol/BasicConsumeFrame.php b/src/Protocol/BasicConsumeFrame.php index 2c7f23d..36d2227 100644 --- a/src/Protocol/BasicConsumeFrame.php +++ b/src/Protocol/BasicConsumeFrame.php @@ -66,17 +66,17 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->reserved1 = $buffer->consumeInt16(); - $self->queue = $buffer->consumeString(); + $self->reserved1 = $buffer->consumeInt16(); + $self->queue = $buffer->consumeString(); $self->consumerTag = $buffer->consumeString(); - + [$self->noLocal, $self->noAck, $self->exclusive, $self->nowait] = $buffer->consumeBits(4); - + $self->arguments = $buffer->consumeTable(); - + return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); @@ -85,7 +85,7 @@ public function pack(): Buffer $buffer->appendString($this->consumerTag); $buffer->appendBits([$this->noLocal, $this->noAck, $this->exclusive, $this->nowait]); $buffer->appendTable($this->arguments); - + return $buffer; } } diff --git a/src/Protocol/BasicConsumeOkFrame.php b/src/Protocol/BasicConsumeOkFrame.php index bcaf863..5d53636 100644 --- a/src/Protocol/BasicConsumeOkFrame.php +++ b/src/Protocol/BasicConsumeOkFrame.php @@ -30,7 +30,7 @@ public function __construct() */ public static function unpack(Buffer $buffer): self { - $self = new self; + $self = new self; $self->consumerTag = $buffer->consumeString(); return $self; diff --git a/src/Protocol/BasicDeliverFrame.php b/src/Protocol/BasicDeliverFrame.php index 1dd628a..3717575 100644 --- a/src/Protocol/BasicDeliverFrame.php +++ b/src/Protocol/BasicDeliverFrame.php @@ -30,11 +30,11 @@ public function __construct() */ public static function unpack(Buffer $buffer): self { - $self = new self; + $self = new self; $self->consumerTag = $buffer->consumeString(); $self->deliveryTag = $buffer->consumeInt64(); [$self->redelivered] = $buffer->consumeBits(1); - $self->exchange = $buffer->consumeString(); + $self->exchange = $buffer->consumeString(); $self->routingKey = $buffer->consumeString(); return $self; diff --git a/src/Protocol/BasicGetEmptyFrame.php b/src/Protocol/BasicGetEmptyFrame.php index 6c44571..dfc3a26 100644 --- a/src/Protocol/BasicGetEmptyFrame.php +++ b/src/Protocol/BasicGetEmptyFrame.php @@ -19,7 +19,7 @@ class BasicGetEmptyFrame extends MethodFrame * @var string */ public $clusterId = ''; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_GET_EMPTY); @@ -32,7 +32,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->clusterId = $buffer->consumeString(); - + return $self; } @@ -40,7 +40,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendString($this->clusterId); - + return $buffer; } } diff --git a/src/Protocol/BasicGetFrame.php b/src/Protocol/BasicGetFrame.php index bad4ea1..7f205fe 100644 --- a/src/Protocol/BasicGetFrame.php +++ b/src/Protocol/BasicGetFrame.php @@ -29,7 +29,7 @@ class BasicGetFrame extends MethodFrame * @var bool */ public $noAck = false; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_GET); @@ -42,9 +42,9 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->reserved1 = $buffer->consumeInt16(); - $self->queue = $buffer->consumeString(); - [$self->noAck] = $buffer->consumeBits(1); - + $self->queue = $buffer->consumeString(); + [$self->noAck] = $buffer->consumeBits(1); + return $self; } @@ -54,7 +54,7 @@ public function pack(): Buffer $buffer->appendInt16($this->reserved1); $buffer->appendString($this->queue); $buffer->appendBits([$this->noAck]); - + return $buffer; } } diff --git a/src/Protocol/BasicGetOkFrame.php b/src/Protocol/BasicGetOkFrame.php index cb31fda..4a8099b 100644 --- a/src/Protocol/BasicGetOkFrame.php +++ b/src/Protocol/BasicGetOkFrame.php @@ -19,7 +19,7 @@ class BasicGetOkFrame extends MessageFrame * @var int */ public $messageCount; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_GET_OK); @@ -31,12 +31,12 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->deliveryTag = $buffer->consumeInt64(); + $self->deliveryTag = $buffer->consumeInt64(); [$self->redelivered] = $buffer->consumeBits(1); - $self->exchange = $buffer->consumeString(); - $self->routingKey = $buffer->consumeString(); - $self->messageCount = $buffer->consumeInt32(); - + $self->exchange = $buffer->consumeString(); + $self->routingKey = $buffer->consumeString(); + $self->messageCount = $buffer->consumeInt32(); + return $self; } @@ -48,7 +48,7 @@ public function pack(): Buffer $buffer->appendString($this->exchange); $buffer->appendString($this->routingKey); $buffer->appendInt32($this->messageCount); - + return $buffer; } } diff --git a/src/Protocol/BasicNackFrame.php b/src/Protocol/BasicNackFrame.php index 02c2b6e..467952f 100644 --- a/src/Protocol/BasicNackFrame.php +++ b/src/Protocol/BasicNackFrame.php @@ -30,7 +30,7 @@ public function __construct() */ public static function unpack(Buffer $buffer): self { - $self = new self; + $self = new self; $self->deliveryTag = $buffer->consumeInt64(); [$self->multiple, $self->requeue] = $buffer->consumeBits(2); @@ -43,7 +43,7 @@ public function pack(): Buffer $buffer = parent::pack(); $buffer->appendInt64($this->deliveryTag); $buffer->appendBits([$this->multiple, $this->requeue]); - + return $buffer; } } diff --git a/src/Protocol/BasicPublishFrame.php b/src/Protocol/BasicPublishFrame.php index a8ff2d7..a418837 100644 --- a/src/Protocol/BasicPublishFrame.php +++ b/src/Protocol/BasicPublishFrame.php @@ -39,7 +39,7 @@ class BasicPublishFrame extends MethodFrame * @var bool */ public $immediate = false; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_PUBLISH); @@ -51,15 +51,15 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->reserved1 = $buffer->consumeInt16(); - $self->exchange = $buffer->consumeString(); + $self->reserved1 = $buffer->consumeInt16(); + $self->exchange = $buffer->consumeString(); $self->routingKey = $buffer->consumeString(); - + [$self->mandatory, $self->immediate] = $buffer->consumeBits(2); - + return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); @@ -67,7 +67,7 @@ public function pack(): Buffer $buffer->appendString($this->exchange); $buffer->appendString($this->routingKey); $buffer->appendBits([$this->mandatory, $this->immediate]); - + return $buffer; } } diff --git a/src/Protocol/BasicQosFrame.php b/src/Protocol/BasicQosFrame.php index 24dda12..71795cb 100644 --- a/src/Protocol/BasicQosFrame.php +++ b/src/Protocol/BasicQosFrame.php @@ -29,22 +29,22 @@ class BasicQosFrame extends MethodFrame * @var bool */ public $global = false; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_QOS); } /** - * @throws \PHPinnacle\Buffer\BufferOverflow + * @throws \PHPinnacle\Buffer\BufferOverflow */ public static function unpack(Buffer $buffer): self { $self = new self; - $self->prefetchSize = $buffer->consumeInt32(); + $self->prefetchSize = $buffer->consumeInt32(); $self->prefetchCount = $buffer->consumeInt16(); - [$self->global] = $buffer->consumeBits(1); - + [$self->global] = $buffer->consumeBits(1); + return $self; } @@ -54,7 +54,7 @@ public function pack(): Buffer $buffer->appendInt32($this->prefetchSize); $buffer->appendInt16($this->prefetchCount); $buffer->appendBits([$this->global]); - + return $buffer; } } diff --git a/src/Protocol/BasicRecoverFrame.php b/src/Protocol/BasicRecoverFrame.php index 737346b..859f2ca 100644 --- a/src/Protocol/BasicRecoverFrame.php +++ b/src/Protocol/BasicRecoverFrame.php @@ -19,7 +19,7 @@ class BasicRecoverFrame extends MethodFrame * @var bool */ public $requeue = false; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_RECOVER); @@ -32,7 +32,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; [$self->requeue] = $buffer->consumeBits(1); - + return $self; } @@ -40,7 +40,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendBits([$this->requeue]); - + return $buffer; } } diff --git a/src/Protocol/BasicRejectFrame.php b/src/Protocol/BasicRejectFrame.php index 46ff9fb..63aed25 100644 --- a/src/Protocol/BasicRejectFrame.php +++ b/src/Protocol/BasicRejectFrame.php @@ -32,8 +32,8 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->deliveryTag = $buffer->consumeInt64(); - [$self->requeue] = $buffer->consumeBits(1); - + [$self->requeue] = $buffer->consumeBits(1); + return $self; } @@ -42,7 +42,7 @@ public function pack(): Buffer $buffer = parent::pack(); $buffer->appendInt64($this->deliveryTag); $buffer->appendBits([$this->requeue]); - + return $buffer; } } diff --git a/src/Protocol/BasicReturnFrame.php b/src/Protocol/BasicReturnFrame.php index 5c904cc..f30a8a2 100644 --- a/src/Protocol/BasicReturnFrame.php +++ b/src/Protocol/BasicReturnFrame.php @@ -34,7 +34,7 @@ class BasicReturnFrame extends MethodFrame * @var string */ public $routingKey; - + public function __construct() { parent::__construct(Constants::CLASS_BASIC, Constants::METHOD_BASIC_RETURN); @@ -46,14 +46,14 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->replyCode = $buffer->consumeInt16(); - $self->replyText = $buffer->consumeString(); - $self->exchange = $buffer->consumeString(); + $self->replyCode = $buffer->consumeInt16(); + $self->replyText = $buffer->consumeString(); + $self->exchange = $buffer->consumeString(); $self->routingKey = $buffer->consumeString(); - + return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); @@ -61,7 +61,7 @@ public function pack(): Buffer $buffer->appendString($this->replyText); $buffer->appendString($this->exchange); $buffer->appendString($this->routingKey); - + return $buffer; } } diff --git a/src/Protocol/ChannelCloseFrame.php b/src/Protocol/ChannelCloseFrame.php index c40a913..e99fa72 100644 --- a/src/Protocol/ChannelCloseFrame.php +++ b/src/Protocol/ChannelCloseFrame.php @@ -34,7 +34,7 @@ class ChannelCloseFrame extends MethodFrame * @var int */ public $closeMethodId; - + public function __construct() { parent::__construct(Constants::CLASS_CHANNEL, Constants::METHOD_CHANNEL_CLOSE); @@ -46,12 +46,12 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - - $self->replyCode = $buffer->consumeInt16(); - $self->replyText = $buffer->consumeString(); - $self->closeClassId = $buffer->consumeInt16(); + + $self->replyCode = $buffer->consumeInt16(); + $self->replyText = $buffer->consumeString(); + $self->closeClassId = $buffer->consumeInt16(); $self->closeMethodId = $buffer->consumeInt16(); - + return $self; } @@ -62,7 +62,7 @@ public function pack(): Buffer $buffer->appendString($this->replyText); $buffer->appendInt16($this->closeClassId); $buffer->appendInt16($this->closeMethodId); - + return $buffer; } } diff --git a/src/Protocol/ChannelFlowFrame.php b/src/Protocol/ChannelFlowFrame.php index 6f9f356..7998ef7 100644 --- a/src/Protocol/ChannelFlowFrame.php +++ b/src/Protocol/ChannelFlowFrame.php @@ -32,10 +32,10 @@ public static function unpack(Buffer $buffer): self { $self = new self; [$self->active] = $buffer->consumeBits(1); - + return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); diff --git a/src/Protocol/ChannelFlowOkFrame.php b/src/Protocol/ChannelFlowOkFrame.php index cf97f4d..85c5954 100644 --- a/src/Protocol/ChannelFlowOkFrame.php +++ b/src/Protocol/ChannelFlowOkFrame.php @@ -32,7 +32,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; [$self->active] = $buffer->consumeBits(1); - + return $self; } @@ -40,7 +40,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendBits([$this->active]); - + return $buffer; } } diff --git a/src/Protocol/ChannelOpenFrame.php b/src/Protocol/ChannelOpenFrame.php index f49967c..1a19044 100644 --- a/src/Protocol/ChannelOpenFrame.php +++ b/src/Protocol/ChannelOpenFrame.php @@ -19,7 +19,7 @@ class ChannelOpenFrame extends MethodFrame * @var string */ public $outOfBand = ''; - + public function __construct() { parent::__construct(Constants::CLASS_CHANNEL, Constants::METHOD_CHANNEL_OPEN); @@ -31,9 +31,9 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - + $self->outOfBand = $buffer->consumeString(); - + return $self; } @@ -41,7 +41,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendString($this->outOfBand); - + return $buffer; } } diff --git a/src/Protocol/ChannelOpenOkFrame.php b/src/Protocol/ChannelOpenOkFrame.php index 665a9da..d01ab4e 100644 --- a/src/Protocol/ChannelOpenOkFrame.php +++ b/src/Protocol/ChannelOpenOkFrame.php @@ -19,7 +19,7 @@ class ChannelOpenOkFrame extends MethodFrame * @var string */ public $channelId = ''; - + public function __construct() { parent::__construct(Constants::CLASS_CHANNEL, Constants::METHOD_CHANNEL_OPEN_OK); @@ -32,7 +32,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->channelId = $buffer->consumeText(); - + return $self; } @@ -40,7 +40,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendText($this->channelId); - + return $buffer; } } diff --git a/src/Protocol/ConfirmSelectFrame.php b/src/Protocol/ConfirmSelectFrame.php index e7d5651..5be8224 100644 --- a/src/Protocol/ConfirmSelectFrame.php +++ b/src/Protocol/ConfirmSelectFrame.php @@ -19,7 +19,7 @@ class ConfirmSelectFrame extends MethodFrame * @var bool */ public $nowait = false; - + public function __construct() { parent::__construct(Constants::CLASS_CONFIRM, Constants::METHOD_CONFIRM_SELECT); @@ -32,7 +32,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; [$self->nowait] = $buffer->consumeBits(1); - + return $self; } @@ -40,7 +40,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendBits([$this->nowait]); - + return $buffer; } } diff --git a/src/Protocol/ConnectionBlockedFrame.php b/src/Protocol/ConnectionBlockedFrame.php index c65666f..e5b0614 100644 --- a/src/Protocol/ConnectionBlockedFrame.php +++ b/src/Protocol/ConnectionBlockedFrame.php @@ -23,7 +23,7 @@ class ConnectionBlockedFrame extends MethodFrame public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_BLOCKED); - + $this->channel = Constants::CONNECTION_CHANNEL; } @@ -34,7 +34,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->reason = $buffer->consumeString(); - + return $self; } @@ -42,7 +42,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendString($this->reason); - + return $buffer; } } diff --git a/src/Protocol/ConnectionCloseFrame.php b/src/Protocol/ConnectionCloseFrame.php index 110e6a6..b1ae8ce 100644 --- a/src/Protocol/ConnectionCloseFrame.php +++ b/src/Protocol/ConnectionCloseFrame.php @@ -38,7 +38,7 @@ class ConnectionCloseFrame extends MethodFrame public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_CLOSE); - + $this->channel = Constants::CONNECTION_CHANNEL; } @@ -48,14 +48,14 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->replyCode = $buffer->consumeInt16(); - $self->replyText = $buffer->consumeString(); - $self->closeClassId = $buffer->consumeInt16(); + $self->replyCode = $buffer->consumeInt16(); + $self->replyText = $buffer->consumeString(); + $self->closeClassId = $buffer->consumeInt16(); $self->closeMethodId = $buffer->consumeInt16(); - + return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); @@ -63,7 +63,7 @@ public function pack(): Buffer $buffer->appendString($this->replyText); $buffer->appendInt16($this->closeClassId); $buffer->appendInt16($this->closeMethodId); - + return $buffer; } } diff --git a/src/Protocol/ConnectionOpenFrame.php b/src/Protocol/ConnectionOpenFrame.php index 2392b8a..03d6ec1 100644 --- a/src/Protocol/ConnectionOpenFrame.php +++ b/src/Protocol/ConnectionOpenFrame.php @@ -29,11 +29,11 @@ class ConnectionOpenFrame extends MethodFrame * @var bool */ public $insist = false; - + public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_OPEN); - + $this->channel = Constants::CONNECTION_CHANNEL; } @@ -43,20 +43,20 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->virtualHost = $buffer->consumeString(); - $self->capabilities = $buffer->consumeString(); - [$self->insist] = $buffer->consumeBits(1); - + $self->virtualHost = $buffer->consumeString(); + $self->capabilities = $buffer->consumeString(); + [$self->insist] = $buffer->consumeBits(1); + return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendString($this->virtualHost); $buffer->appendString($this->capabilities); $buffer->appendBits([$this->insist]); - + return $buffer; } } diff --git a/src/Protocol/ConnectionOpenOkFrame.php b/src/Protocol/ConnectionOpenOkFrame.php index 5b3946d..4121553 100644 --- a/src/Protocol/ConnectionOpenOkFrame.php +++ b/src/Protocol/ConnectionOpenOkFrame.php @@ -19,11 +19,11 @@ class ConnectionOpenOkFrame extends MethodFrame * @var string */ public $knownHosts = ''; - + public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_OPEN_OK); - + $this->channel = Constants::CONNECTION_CHANNEL; } @@ -34,7 +34,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->knownHosts = $buffer->consumeString(); - + return $self; } @@ -42,7 +42,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendString($this->knownHosts); - + return $buffer; } } diff --git a/src/Protocol/ConnectionSecureFrame.php b/src/Protocol/ConnectionSecureFrame.php index e518e87..d94d4cf 100644 --- a/src/Protocol/ConnectionSecureFrame.php +++ b/src/Protocol/ConnectionSecureFrame.php @@ -19,11 +19,11 @@ class ConnectionSecureFrame extends MethodFrame * @var string */ public $challenge; - + public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_SECURE); - + $this->channel = Constants::CONNECTION_CHANNEL; } @@ -34,7 +34,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->challenge = $buffer->consumeText(); - + return $self; } @@ -42,7 +42,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendText($this->challenge); - + return $buffer; } } diff --git a/src/Protocol/ConnectionSecureOkFrame.php b/src/Protocol/ConnectionSecureOkFrame.php index d20f358..1167f43 100644 --- a/src/Protocol/ConnectionSecureOkFrame.php +++ b/src/Protocol/ConnectionSecureOkFrame.php @@ -19,11 +19,11 @@ class ConnectionSecureOkFrame extends MethodFrame * @var string */ public $response; - + public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_SECURE_OK); - + $this->channel = Constants::CONNECTION_CHANNEL; } diff --git a/src/Protocol/ConnectionStartFrame.php b/src/Protocol/ConnectionStartFrame.php index 69874a2..4698590 100644 --- a/src/Protocol/ConnectionStartFrame.php +++ b/src/Protocol/ConnectionStartFrame.php @@ -58,7 +58,7 @@ public function __construct() */ public static function unpack(Buffer $buffer): self { - $self = new self; + $self = new self; $self->versionMajor = $buffer->consumeUint8(); $self->versionMinor = $buffer->consumeUint8(); @@ -73,8 +73,8 @@ public static function unpack(Buffer $buffer): self $serverProperties = $buffer->consumeTable(); $self->serverProperties = $serverProperties; - $self->mechanisms = $buffer->consumeText(); - $self->locales = $buffer->consumeText(); + $self->mechanisms = $buffer->consumeText(); + $self->locales = $buffer->consumeText(); return $self; } diff --git a/src/Protocol/ConnectionStartOkFrame.php b/src/Protocol/ConnectionStartOkFrame.php index 647b088..f1de6e7 100644 --- a/src/Protocol/ConnectionStartOkFrame.php +++ b/src/Protocol/ConnectionStartOkFrame.php @@ -34,11 +34,11 @@ class ConnectionStartOkFrame extends MethodFrame * @var string */ public $locale = 'en_US'; - + public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_START_OK); - + $this->channel = Constants::CONNECTION_CHANNEL; } @@ -49,10 +49,10 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->clientProperties = $buffer->consumeTable(); - $self->mechanism = $buffer->consumeString(); - $self->response = $buffer->consumeText(); - $self->locale = $buffer->consumeString(); - + $self->mechanism = $buffer->consumeString(); + $self->response = $buffer->consumeText(); + $self->locale = $buffer->consumeString(); + return $self; } @@ -63,7 +63,7 @@ public function pack(): Buffer $buffer->appendString($this->mechanism); $buffer->appendText($this->response); $buffer->appendString($this->locale); - + return $buffer; } } diff --git a/src/Protocol/ConnectionTuneFrame.php b/src/Protocol/ConnectionTuneFrame.php index af534f2..d5e4d45 100644 --- a/src/Protocol/ConnectionTuneFrame.php +++ b/src/Protocol/ConnectionTuneFrame.php @@ -29,11 +29,11 @@ class ConnectionTuneFrame extends MethodFrame * @var int */ public $heartbeat = 0; - + public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_TUNE); - + $this->channel = Constants::CONNECTION_CHANNEL; } @@ -44,9 +44,9 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->channelMax = $buffer->consumeInt16(); - $self->frameMax = $buffer->consumeInt32(); - $self->heartbeat = $buffer->consumeInt16(); - + $self->frameMax = $buffer->consumeInt32(); + $self->heartbeat = $buffer->consumeInt16(); + return $self; } @@ -56,7 +56,7 @@ public function pack(): Buffer $buffer->appendInt16($this->channelMax); $buffer->appendInt32($this->frameMax); $buffer->appendInt16($this->heartbeat); - + return $buffer; } } diff --git a/src/Protocol/ConnectionTuneOkFrame.php b/src/Protocol/ConnectionTuneOkFrame.php index 8637a4c..9dc5fef 100644 --- a/src/Protocol/ConnectionTuneOkFrame.php +++ b/src/Protocol/ConnectionTuneOkFrame.php @@ -29,11 +29,11 @@ class ConnectionTuneOkFrame extends MethodFrame * @var int */ public $heartbeat = 0; - + public function __construct() { parent::__construct(Constants::CLASS_CONNECTION, Constants::METHOD_CONNECTION_TUNE_OK); - + $this->channel = Constants::CONNECTION_CHANNEL; } @@ -44,9 +44,9 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->channelMax = $buffer->consumeInt16(); - $self->frameMax = $buffer->consumeInt32(); - $self->heartbeat = $buffer->consumeInt16(); - + $self->frameMax = $buffer->consumeInt32(); + $self->heartbeat = $buffer->consumeInt16(); + return $self; } @@ -56,7 +56,7 @@ public function pack(): Buffer $buffer->appendInt16($this->channelMax); $buffer->appendInt32($this->frameMax); $buffer->appendInt16($this->heartbeat); - + return $buffer; } } diff --git a/src/Protocol/ContentHeaderFrame.php b/src/Protocol/ContentHeaderFrame.php index 065183d..bc4366d 100644 --- a/src/Protocol/ContentHeaderFrame.php +++ b/src/Protocol/ContentHeaderFrame.php @@ -15,20 +15,20 @@ class ContentHeaderFrame extends AbstractFrame { - private const FLAG_CONTENT_TYPE = 0x8000; + private const FLAG_CONTENT_TYPE = 0x8000; private const FLAG_CONTENT_ENCODING = 0x4000; - private const FLAG_HEADERS = 0x2000; - private const FLAG_DELIVERY_MODE = 0x1000; - private const FLAG_PRIORITY = 0x0800; - private const FLAG_CORRELATION_ID = 0x0400; - private const FLAG_REPLY_TO = 0x0200; - private const FLAG_EXPIRATION = 0x0100; - private const FLAG_MESSAGE_ID = 0x0080; - private const FLAG_TIMESTAMP = 0x0040; - private const FLAG_TYPE = 0x0020; - private const FLAG_USER_ID = 0x0010; - private const FLAG_APP_ID = 0x0008; - private const FLAG_CLUSTER_ID = 0x0004; + private const FLAG_HEADERS = 0x2000; + private const FLAG_DELIVERY_MODE = 0x1000; + private const FLAG_PRIORITY = 0x0800; + private const FLAG_CORRELATION_ID = 0x0400; + private const FLAG_REPLY_TO = 0x0200; + private const FLAG_EXPIRATION = 0x0100; + private const FLAG_MESSAGE_ID = 0x0080; + private const FLAG_TIMESTAMP = 0x0040; + private const FLAG_TYPE = 0x0020; + private const FLAG_USER_ID = 0x0010; + private const FLAG_APP_ID = 0x0008; + private const FLAG_CLUSTER_ID = 0x0004; /** * @var int @@ -132,78 +132,64 @@ public static function unpack(Buffer $buffer): self { $self = new self; - $self->classId = $buffer->consumeUint16(); - $self->weight = $buffer->consumeUint16(); + $self->classId = $buffer->consumeUint16(); + $self->weight = $buffer->consumeUint16(); $self->bodySize = $buffer->consumeUint64(); - $self->flags = $flags = $buffer->consumeUint16(); + $self->flags = $flags = $buffer->consumeUint16(); - if($flags & self::FLAG_CONTENT_TYPE) - { + if ($flags & self::FLAG_CONTENT_TYPE) { $self->contentType = $buffer->consumeString(); } - if($flags & self::FLAG_CONTENT_ENCODING) - { + if ($flags & self::FLAG_CONTENT_ENCODING) { $self->contentEncoding = $buffer->consumeString(); } - if($flags & self::FLAG_HEADERS) - { + if ($flags & self::FLAG_HEADERS) { $self->headers = $buffer->consumeTable(); } - if($flags & self::FLAG_DELIVERY_MODE) - { + if ($flags & self::FLAG_DELIVERY_MODE) { $self->deliveryMode = $buffer->consumeUint8(); } - if($flags & self::FLAG_PRIORITY) - { + if ($flags & self::FLAG_PRIORITY) { $self->priority = $buffer->consumeUint8(); } - if($flags & self::FLAG_CORRELATION_ID) - { + if ($flags & self::FLAG_CORRELATION_ID) { $self->correlationId = $buffer->consumeString(); } - if($flags & self::FLAG_REPLY_TO) - { + if ($flags & self::FLAG_REPLY_TO) { $self->replyTo = $buffer->consumeString(); } - if($flags & self::FLAG_EXPIRATION) - { + if ($flags & self::FLAG_EXPIRATION) { $self->expiration = $buffer->consumeString(); } - if($flags & self::FLAG_MESSAGE_ID) - { + if ($flags & self::FLAG_MESSAGE_ID) { $self->messageId = $buffer->consumeString(); } - if($flags & self::FLAG_TIMESTAMP) - { + if ($flags & self::FLAG_TIMESTAMP) { $self->timestamp = $buffer->consumeTimestamp(); } - if($flags & self::FLAG_TYPE) - { + if ($flags & self::FLAG_TYPE) { $self->typeHeader = $buffer->consumeString(); } - if($flags & self::FLAG_USER_ID) - { + if ($flags & self::FLAG_USER_ID) { $self->userId = $buffer->consumeString(); } - if($flags & self::FLAG_APP_ID) - { + if ($flags & self::FLAG_APP_ID) { $self->appId = $buffer->consumeString(); } - if($flags & self::FLAG_CLUSTER_ID) - { + if ($flags & self::FLAG_CLUSTER_ID) { $self->clusterId = $buffer->consumeString(); } @@ -222,74 +208,60 @@ public function pack(): Buffer $buffer->appendUint16($flags); - if($flags & self::FLAG_CONTENT_TYPE) - { - $buffer->appendString((string) $this->contentType); + if ($flags & self::FLAG_CONTENT_TYPE && $this->contentType !== null) { + $buffer->appendString($this->contentType); } - if($flags & self::FLAG_CONTENT_ENCODING) - { - $buffer->appendString((string) $this->contentEncoding); + if ($flags & self::FLAG_CONTENT_ENCODING && $this->contentEncoding !== null) { + $buffer->appendString($this->contentEncoding); } - if($flags & self::FLAG_HEADERS) - { + if ($flags & self::FLAG_HEADERS) { $buffer->appendTable($this->headers); } - if($flags & self::FLAG_DELIVERY_MODE) - { - $buffer->appendUint8((int) $this->deliveryMode); + if ($flags & self::FLAG_DELIVERY_MODE && $this->deliveryMode !== null) { + $buffer->appendUint8($this->deliveryMode); } - if($flags & self::FLAG_PRIORITY) - { - $buffer->appendUint8((int) $this->priority); + if ($flags & self::FLAG_PRIORITY && $this->priority) { + $buffer->appendUint8($this->priority); } - if($flags & self::FLAG_CORRELATION_ID) - { - $buffer->appendString((string) $this->correlationId); + if ($flags & self::FLAG_CORRELATION_ID && $this->correlationId !== null) { + $buffer->appendString($this->correlationId); } - if($flags & self::FLAG_REPLY_TO) - { - $buffer->appendString((string) $this->replyTo); + if ($flags & self::FLAG_REPLY_TO && $this->replyTo !== null) { + $buffer->appendString($this->replyTo); } - if($flags & self::FLAG_EXPIRATION) - { - $buffer->appendString((string) $this->expiration); + if ($flags & self::FLAG_EXPIRATION && $this->expiration !== null) { + $buffer->appendString($this->expiration); } - if($flags & self::FLAG_MESSAGE_ID) - { - $buffer->appendString((string) $this->messageId); + if ($flags & self::FLAG_MESSAGE_ID && $this->messageId !== null) { + $buffer->appendString($this->messageId); } - if($flags & self::FLAG_TIMESTAMP && $this->timestamp !== null) - { + if ($flags & self::FLAG_TIMESTAMP && $this->timestamp !== null) { $buffer->appendTimestamp($this->timestamp); } - if($flags & self::FLAG_TYPE) - { - $buffer->appendString((string) $this->typeHeader); + if ($flags & self::FLAG_TYPE && $this->typeHeader !== null) { + $buffer->appendString($this->typeHeader); } - if($flags & self::FLAG_USER_ID) - { - $buffer->appendString((string) $this->userId); + if ($flags & self::FLAG_USER_ID && $this->userId !== null) { + $buffer->appendString($this->userId); } - if($flags & self::FLAG_APP_ID) - { - $buffer->appendString((string) $this->appId); + if ($flags & self::FLAG_APP_ID && $this->appId !== null) { + $buffer->appendString($this->appId); } - if($flags & self::FLAG_CLUSTER_ID) - { - $buffer->appendString((string) $this->clusterId); + if ($flags & self::FLAG_CLUSTER_ID && $this->clusterId !== null) { + $buffer->appendString($this->clusterId); } return $buffer; @@ -299,68 +271,55 @@ public function toArray(): array { $headers = $this->headers ?: []; - if($this->contentType !== null) - { + if ($this->contentType !== null) { $headers['content-type'] = $this->contentType; } - if($this->contentEncoding !== null) - { + if ($this->contentEncoding !== null) { $headers['content-encoding'] = $this->contentEncoding; } - if($this->deliveryMode !== null) - { + if ($this->deliveryMode !== null) { $headers['delivery-mode'] = $this->deliveryMode; } - if($this->priority !== null) - { + if ($this->priority !== null) { $headers['priority'] = $this->priority; } - if($this->correlationId !== null) - { + if ($this->correlationId !== null) { $headers['correlation-id'] = $this->correlationId; } - if($this->replyTo !== null) - { + if ($this->replyTo !== null) { $headers['reply-to'] = $this->replyTo; } - if($this->expiration !== null) - { + if ($this->expiration !== null) { $headers['expiration'] = $this->expiration; } - if($this->messageId !== null) - { + if ($this->messageId !== null) { $headers['message-id'] = $this->messageId; } - if($this->timestamp !== null) - { + if ($this->timestamp !== null) { $headers['timestamp'] = $this->timestamp; } - if($this->typeHeader !== null) - { + if ($this->typeHeader !== null) { $headers['type'] = $this->typeHeader; } - if($this->userId !== null) - { + if ($this->userId !== null) { $headers['user-id'] = $this->userId; } - if($this->appId !== null) - { + if ($this->appId !== null) { $headers['app-id'] = $this->appId; } - if($this->clusterId !== null) - { + if ($this->clusterId !== null) { $headers['cluster-id'] = $this->clusterId; } diff --git a/src/Protocol/ExchangeBindFrame.php b/src/Protocol/ExchangeBindFrame.php index 7afc6f9..83bd50f 100644 --- a/src/Protocol/ExchangeBindFrame.php +++ b/src/Protocol/ExchangeBindFrame.php @@ -56,16 +56,16 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->reserved1 = $buffer->consumeInt16(); + $self->reserved1 = $buffer->consumeInt16(); $self->destination = $buffer->consumeString(); - $self->source = $buffer->consumeString(); - $self->routingKey = $buffer->consumeString(); - [$self->nowait] = $buffer->consumeBits(1); - $self->arguments = $buffer->consumeTable(); - + $self->source = $buffer->consumeString(); + $self->routingKey = $buffer->consumeString(); + [$self->nowait] = $buffer->consumeBits(1); + $self->arguments = $buffer->consumeTable(); + return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); @@ -75,7 +75,7 @@ public function pack(): Buffer $buffer->appendString($this->routingKey); $buffer->appendBits([$this->nowait]); $buffer->appendTable($this->arguments); - + return $buffer; } } diff --git a/src/Protocol/ExchangeDeclareFrame.php b/src/Protocol/ExchangeDeclareFrame.php index b1699fe..dfafbcb 100644 --- a/src/Protocol/ExchangeDeclareFrame.php +++ b/src/Protocol/ExchangeDeclareFrame.php @@ -71,17 +71,17 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->reserved1 = $buffer->consumeInt16(); - $self->exchange = $buffer->consumeString(); + $self->reserved1 = $buffer->consumeInt16(); + $self->exchange = $buffer->consumeString(); $self->exchangeType = $buffer->consumeString(); [$self->passive, $self->durable, $self->autoDelete, $self->internal, $self->nowait] = $buffer->consumeBits(5); $self->arguments = $buffer->consumeTable(); - + return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); @@ -90,7 +90,7 @@ public function pack(): Buffer $buffer->appendString($this->exchangeType); $buffer->appendBits([$this->passive, $this->durable, $this->autoDelete, $this->internal, $this->nowait]); $buffer->appendTable($this->arguments); - + return $buffer; } } diff --git a/src/Protocol/ExchangeDeleteFrame.php b/src/Protocol/ExchangeDeleteFrame.php index 00ccef1..34307eb 100644 --- a/src/Protocol/ExchangeDeleteFrame.php +++ b/src/Protocol/ExchangeDeleteFrame.php @@ -46,12 +46,12 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - + $self->reserved1 = $buffer->consumeInt16(); - $self->exchange = $buffer->consumeString(); - + $self->exchange = $buffer->consumeString(); + [$self->ifUnused, $self->nowait] = $buffer->consumeBits(2); - + return $self; } @@ -61,7 +61,7 @@ public function pack(): Buffer $buffer->appendInt16($this->reserved1); $buffer->appendString($this->exchange); $buffer->appendBits([$this->ifUnused, $this->nowait]); - + return $buffer; } } diff --git a/src/Protocol/ExchangeUnbindFrame.php b/src/Protocol/ExchangeUnbindFrame.php index e62ad18..1d59089 100644 --- a/src/Protocol/ExchangeUnbindFrame.php +++ b/src/Protocol/ExchangeUnbindFrame.php @@ -56,13 +56,13 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->reserved1 = $buffer->consumeInt16(); + $self->reserved1 = $buffer->consumeInt16(); $self->destination = $buffer->consumeString(); - $self->source = $buffer->consumeString(); - $self->routingKey = $buffer->consumeString(); - [$self->nowait] = $buffer->consumeBits(1); - $self->arguments = $buffer->consumeTable(); - + $self->source = $buffer->consumeString(); + $self->routingKey = $buffer->consumeString(); + [$self->nowait] = $buffer->consumeBits(1); + $self->arguments = $buffer->consumeTable(); + return $self; } @@ -75,7 +75,7 @@ public function pack(): Buffer $buffer->appendString($this->routingKey); $buffer->appendBits([$this->nowait]); $buffer->appendTable($this->arguments); - + return $buffer; } } diff --git a/src/Protocol/MethodFrame.php b/src/Protocol/MethodFrame.php index d165760..87248ae 100644 --- a/src/Protocol/MethodFrame.php +++ b/src/Protocol/MethodFrame.php @@ -29,7 +29,7 @@ public function __construct(?int $classId = null, ?int $methodId = null) { parent::__construct(Constants::FRAME_METHOD); - $this->classId = $classId; + $this->classId = $classId; $this->methodId = $methodId; } @@ -37,8 +37,8 @@ public function pack(): Buffer { $buffer = new Buffer; $buffer - ->appendUint16((int) $this->classId) - ->appendUint16((int) $this->methodId); + ->appendUint16((int)$this->classId) + ->appendUint16((int)$this->methodId); return $buffer; } diff --git a/src/Protocol/QueueBindFrame.php b/src/Protocol/QueueBindFrame.php index 1f6074c..7525937 100644 --- a/src/Protocol/QueueBindFrame.php +++ b/src/Protocol/QueueBindFrame.php @@ -44,7 +44,7 @@ class QueueBindFrame extends MethodFrame * @var array */ public $arguments = []; - + public function __construct() { parent::__construct(Constants::CLASS_QUEUE, Constants::METHOD_QUEUE_BIND); @@ -56,13 +56,13 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->reserved1 = $buffer->consumeInt16(); - $self->queue = $buffer->consumeString(); - $self->exchange = $buffer->consumeString(); + $self->reserved1 = $buffer->consumeInt16(); + $self->queue = $buffer->consumeString(); + $self->exchange = $buffer->consumeString(); $self->routingKey = $buffer->consumeString(); - [$self->nowait] = $buffer->consumeBits(1); - $self->arguments = $buffer->consumeTable(); - + [$self->nowait] = $buffer->consumeBits(1); + $self->arguments = $buffer->consumeTable(); + return $self; } @@ -75,7 +75,7 @@ public function pack(): Buffer $buffer->appendString($this->routingKey); $buffer->appendBits([$this->nowait]); $buffer->appendTable($this->arguments); - + return $buffer; } } diff --git a/src/Protocol/QueueDeclareFrame.php b/src/Protocol/QueueDeclareFrame.php index 7e0ee0e..f4d7c43 100644 --- a/src/Protocol/QueueDeclareFrame.php +++ b/src/Protocol/QueueDeclareFrame.php @@ -67,12 +67,12 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->reserved1 = $buffer->consumeInt16(); - $self->queue = $buffer->consumeString(); - + $self->queue = $buffer->consumeString(); + [$self->passive, $self->durable, $self->exclusive, $self->autoDelete, $self->nowait] = $buffer->consumeBits(5); - + $self->arguments = $buffer->consumeTable(); - + return $self; } @@ -83,7 +83,7 @@ public function pack(): Buffer $buffer->appendString($this->queue); $buffer->appendBits([$this->passive, $this->durable, $this->exclusive, $this->autoDelete, $this->nowait]); $buffer->appendTable($this->arguments); - + return $buffer; } } diff --git a/src/Protocol/QueueDeclareOkFrame.php b/src/Protocol/QueueDeclareOkFrame.php index 390cf0f..e225704 100644 --- a/src/Protocol/QueueDeclareOkFrame.php +++ b/src/Protocol/QueueDeclareOkFrame.php @@ -29,7 +29,7 @@ class QueueDeclareOkFrame extends MethodFrame * @var int */ public $consumerCount; - + public function __construct() { parent::__construct(Constants::CLASS_QUEUE, Constants::METHOD_QUEUE_DECLARE_OK); @@ -41,20 +41,20 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->queue = $buffer->consumeString(); - $self->messageCount = $buffer->consumeInt32(); + $self->queue = $buffer->consumeString(); + $self->messageCount = $buffer->consumeInt32(); $self->consumerCount = $buffer->consumeInt32(); return $self; } - + public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendString($this->queue); $buffer->appendInt32($this->messageCount); $buffer->appendInt32($this->consumerCount); - + return $buffer; } } diff --git a/src/Protocol/QueueDeleteFrame.php b/src/Protocol/QueueDeleteFrame.php index b6ae5a9..6317335 100644 --- a/src/Protocol/QueueDeleteFrame.php +++ b/src/Protocol/QueueDeleteFrame.php @@ -52,10 +52,10 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->reserved1 = $buffer->consumeInt16(); - $self->queue = $buffer->consumeString(); - + $self->queue = $buffer->consumeString(); + [$self->ifUnused, $self->ifEmpty, $self->nowait] = $buffer->consumeBits(3); - + return $self; } @@ -65,7 +65,7 @@ public function pack(): Buffer $buffer->appendInt16($this->reserved1); $buffer->appendString($this->queue); $buffer->appendBits([$this->ifUnused, $this->ifEmpty, $this->nowait]); - + return $buffer; } } diff --git a/src/Protocol/QueueDeleteOkFrame.php b/src/Protocol/QueueDeleteOkFrame.php index e499c03..1018ade 100644 --- a/src/Protocol/QueueDeleteOkFrame.php +++ b/src/Protocol/QueueDeleteOkFrame.php @@ -32,7 +32,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->messageCount = $buffer->consumeInt32(); - + return $self; } @@ -40,7 +40,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendInt32($this->messageCount); - + return $buffer; } } diff --git a/src/Protocol/QueuePurgeFrame.php b/src/Protocol/QueuePurgeFrame.php index 02b2c50..e320bcc 100644 --- a/src/Protocol/QueuePurgeFrame.php +++ b/src/Protocol/QueuePurgeFrame.php @@ -42,9 +42,9 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->reserved1 = $buffer->consumeInt16(); - $self->queue = $buffer->consumeString(); - [$self->nowait] = $buffer->consumeBits(1); - + $self->queue = $buffer->consumeString(); + [$self->nowait] = $buffer->consumeBits(1); + return $self; } @@ -54,7 +54,7 @@ public function pack(): Buffer $buffer->appendInt16($this->reserved1); $buffer->appendString($this->queue); $buffer->appendBits([$this->nowait]); - + return $buffer; } } diff --git a/src/Protocol/QueuePurgeOkFrame.php b/src/Protocol/QueuePurgeOkFrame.php index 5c3fd69..b4bc3ee 100644 --- a/src/Protocol/QueuePurgeOkFrame.php +++ b/src/Protocol/QueuePurgeOkFrame.php @@ -32,7 +32,7 @@ public static function unpack(Buffer $buffer): self { $self = new self; $self->messageCount = $buffer->consumeInt32(); - + return $self; } @@ -40,7 +40,7 @@ public function pack(): Buffer { $buffer = parent::pack(); $buffer->appendInt32($this->messageCount); - + return $buffer; } } diff --git a/src/Protocol/QueueUnbindFrame.php b/src/Protocol/QueueUnbindFrame.php index 92d454b..1b8e846 100644 --- a/src/Protocol/QueueUnbindFrame.php +++ b/src/Protocol/QueueUnbindFrame.php @@ -51,12 +51,12 @@ public function __construct() public static function unpack(Buffer $buffer): self { $self = new self; - $self->reserved1 = $buffer->consumeInt16(); - $self->queue = $buffer->consumeString(); - $self->exchange = $buffer->consumeString(); + $self->reserved1 = $buffer->consumeInt16(); + $self->queue = $buffer->consumeString(); + $self->exchange = $buffer->consumeString(); $self->routingKey = $buffer->consumeString(); - $self->arguments = $buffer->consumeTable(); - + $self->arguments = $buffer->consumeTable(); + return $self; } @@ -68,7 +68,7 @@ public function pack(): Buffer $buffer->appendString($this->exchange); $buffer->appendString($this->routingKey); $buffer->appendTable($this->arguments); - + return $buffer; } } diff --git a/src/Queue.php b/src/Queue.php index e1dc4dc..0458b6c 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -declare(strict_types = 1); +declare(strict_types=1); namespace PHPinnacle\Ridge; @@ -31,8 +31,8 @@ final class Queue public function __construct(string $name, int $messages, int $consumers) { - $this->name = $name; - $this->messages = $messages; + $this->name = $name; + $this->messages = $messages; $this->consumers = $consumers; }