From f010b3ef640229a15d722ac50866abfa6de704c9 Mon Sep 17 00:00:00 2001 From: Hasham Ahmad Date: Wed, 10 Jun 2020 17:23:07 -0500 Subject: [PATCH] Framework assertions and collections --- composer.lock | 473 +++++++++++++++--- psalm.xml | 1 + src/Channel/Channel.php | 8 +- src/Channel/ChannelMap.php | 13 +- src/Channel/Subscription/LazySubscription.php | 8 +- .../MessageHandler/MessageHandlerList.php | 7 +- src/Channel/Subscription/Subscription.php | 6 +- src/Channel/Subscription/SubscriptionMap.php | 17 +- .../Subscription/Transport/TransportMap.php | 17 +- src/Envelope.php | 10 +- .../ChannelUnknown.php} | 6 +- .../EnvelopeNotAcceptable.php | 6 +- .../MessageBusException.php} | 6 +- .../SubscriptionUnknown.php} | 6 +- src/MessageBus.php | 7 +- tests/Channel/ChannelMapTest.php | 2 +- tests/Channel/ChannelTest.php | 4 +- .../Subscription/SubscriptionMapTest.php | 2 +- .../Channel/Subscription/SubscriptionTest.php | 2 +- .../Transport/TransportMapTest.php | 2 +- tests/MessageBusTest.php | 4 +- 21 files changed, 478 insertions(+), 129 deletions(-) rename src/{Error/SubscriptionUnknown.php => Exception/ChannelUnknown.php} (59%) rename src/{Error => Exception}/EnvelopeNotAcceptable.php (73%) rename src/{Error/ChannelUnknown.php => Exception/MessageBusException.php} (64%) rename src/{Error/ErrorInterface.php => Exception/SubscriptionUnknown.php} (58%) diff --git a/composer.lock b/composer.lock index 31461c8..32667cc 100644 --- a/composer.lock +++ b/composer.lock @@ -126,16 +126,15 @@ "source": { "type": "git", "url": "https://github.com/daikon-cqrs/data-structure.git", - "reference": "7d7b782079afd1c6d78827597ecf9ae6ff2b6e2e" + "reference": "815032f78c105164ed6d0351c2c958b7e41f38b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/daikon-cqrs/data-structure/zipball/7d7b782079afd1c6d78827597ecf9ae6ff2b6e2e", - "reference": "7d7b782079afd1c6d78827597ecf9ae6ff2b6e2e", + "url": "https://api.github.com/repos/daikon-cqrs/data-structure/zipball/815032f78c105164ed6d0351c2c958b7e41f38b3", + "reference": "815032f78c105164ed6d0351c2c958b7e41f38b3", "shasum": "" }, "require": { - "beberlei/assert": "^3.0", "daikon/interop": "master@dev", "php": "^7.4", "php-ds/php-ds": "^1.2" @@ -168,7 +167,7 @@ "map", "vector" ], - "time": "2020-05-28T02:04:18+00:00" + "time": "2020-06-10T21:13:27+00:00" }, { "name": "daikon/interop", @@ -176,15 +175,16 @@ "source": { "type": "git", "url": "https://github.com/daikon-cqrs/interop.git", - "reference": "9601b4722d7c24a14b073375f3c9092b70bb0b2b" + "reference": "ca222f9208c03ccd1e59a401f2134417bb075c93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/daikon-cqrs/interop/zipball/9601b4722d7c24a14b073375f3c9092b70bb0b2b", - "reference": "9601b4722d7c24a14b073375f3c9092b70bb0b2b", + "url": "https://api.github.com/repos/daikon-cqrs/interop/zipball/ca222f9208c03ccd1e59a401f2134417bb075c93", + "reference": "ca222f9208c03ccd1e59a401f2134417bb075c93", "shasum": "" }, "require": { + "beberlei/assert": "^v3.0", "php": "^7.4" }, "require-dev": { @@ -205,7 +205,7 @@ ], "description": "Interoperability code used across Daikon-CQRS components.", "homepage": "https://github.com/daikon-cqrs/interop", - "time": "2020-05-27T22:29:11+00:00" + "time": "2020-06-10T20:53:58+00:00" }, { "name": "daikon/metadata", @@ -213,12 +213,12 @@ "source": { "type": "git", "url": "https://github.com/daikon-cqrs/metadata.git", - "reference": "b9b7aae13faa3b61ec39d9603e8ff5c94a6a666d" + "reference": "d69ce2d6e95c281db062bb836d40f1bfd0f2a683" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/daikon-cqrs/metadata/zipball/b9b7aae13faa3b61ec39d9603e8ff5c94a6a666d", - "reference": "b9b7aae13faa3b61ec39d9603e8ff5c94a6a666d", + "url": "https://api.github.com/repos/daikon-cqrs/metadata/zipball/d69ce2d6e95c281db062bb836d40f1bfd0f2a683", + "reference": "d69ce2d6e95c281db062bb836d40f1bfd0f2a683", "shasum": "" }, "require": { @@ -248,7 +248,7 @@ "enricher", "metadata" ], - "time": "2020-05-28T02:11:27+00:00" + "time": "2020-06-10T21:19:16+00:00" }, { "name": "php-ds/php-ds", @@ -725,16 +725,16 @@ }, { "name": "composer/xdebug-handler", - "version": "1.4.1", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "1ab9842d69e64fb3a01be6b656501032d1b78cb7" + "reference": "fa2aaf99e2087f013a14f7432c1cd2dd7d8f1f51" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/1ab9842d69e64fb3a01be6b656501032d1b78cb7", - "reference": "1ab9842d69e64fb3a01be6b656501032d1b78cb7", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/fa2aaf99e2087f013a14f7432c1cd2dd7d8f1f51", + "reference": "fa2aaf99e2087f013a14f7432c1cd2dd7d8f1f51", "shasum": "" }, "require": { @@ -769,26 +769,34 @@ { "url": "https://packagist.com", "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" } ], - "time": "2020-03-01T12:26:26+00:00" + "time": "2020-06-04T11:16:35+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", @@ -827,7 +835,21 @@ "constructor", "instantiate" ], - "time": "2019-10-21T16:45:58+00:00" + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "type": "tidelift" + } + ], + "time": "2020-05-29T17:27:14+00:00" }, { "name": "felixfbecker/advanced-json-rpc", @@ -1013,16 +1035,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.4.0", + "version": "v4.5.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120" + "reference": "53c2753d756f5adb586dca79c2ec0e2654dd9463" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120", - "reference": "bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/53c2753d756f5adb586dca79c2ec0e2654dd9463", + "reference": "53c2753d756f5adb586dca79c2ec0e2654dd9463", "shasum": "" }, "require": { @@ -1061,7 +1083,7 @@ "parser", "php" ], - "time": "2020-04-10T16:34:50+00:00" + "time": "2020-06-03T07:24:19+00:00" }, { "name": "ocramius/package-versions", @@ -2707,28 +2729,28 @@ }, { "name": "sebastian/type", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "9e8f42f740afdea51f5f4e8cec2035580e797ee1" + "reference": "bad49207c6f854e7a25cef0ea948ac8ebe3ef9d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/9e8f42f740afdea51f5f4e8cec2035580e797ee1", - "reference": "9e8f42f740afdea51f5f4e8cec2035580e797ee1", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/bad49207c6f854e7a25cef0ea948ac8ebe3ef9d8", + "reference": "bad49207c6f854e7a25cef0ea948ac8ebe3ef9d8", "shasum": "" }, "require": { "php": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -2749,7 +2771,13 @@ ], "description": "Collection of value objects that represent the types of the PHP type system", "homepage": "https://github.com/sebastianbergmann/type", - "time": "2020-02-07T06:13:43+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-01T12:21:09+00:00" }, { "name": "sebastian/version", @@ -2847,26 +2875,29 @@ }, { "name": "symfony/console", - "version": "v5.0.8", + "version": "v5.1.0", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "5fa1caadc8cdaa17bcfb25219f3b53fe294a9935" + "reference": "00bed125812716d09b163f0727ef33bb49bf3448" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/5fa1caadc8cdaa17bcfb25219f3b53fe294a9935", - "reference": "5fa1caadc8cdaa17bcfb25219f3b53fe294a9935", + "url": "https://api.github.com/repos/symfony/console/zipball/00bed125812716d09b163f0727ef33bb49bf3448", + "reference": "00bed125812716d09b163f0727ef33bb49bf3448", "shasum": "" }, "require": { - "php": "^7.2.5", + "php": ">=7.2.5", "symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-php73": "^1.8", - "symfony/service-contracts": "^1.1|^2" + "symfony/polyfill-php80": "^1.15", + "symfony/service-contracts": "^1.1|^2", + "symfony/string": "^5.1" }, "conflict": { "symfony/dependency-injection": "<4.4", + "symfony/dotenv": "<5.1", "symfony/event-dispatcher": "<4.4", "symfony/lock": "<4.4", "symfony/process": "<4.4" @@ -2892,7 +2923,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-master": "5.1-dev" } }, "autoload": { @@ -2933,29 +2964,29 @@ "type": "tidelift" } ], - "time": "2020-03-30T11:42:42+00:00" + "time": "2020-05-30T20:35:19+00:00" }, { "name": "symfony/finder", - "version": "v5.0.8", + "version": "v5.1.0", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "600a52c29afc0d1caa74acbec8d3095ca7e9910d" + "reference": "4298870062bfc667cb78d2b379be4bf5dec5f187" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/600a52c29afc0d1caa74acbec8d3095ca7e9910d", - "reference": "600a52c29afc0d1caa74acbec8d3095ca7e9910d", + "url": "https://api.github.com/repos/symfony/finder/zipball/4298870062bfc667cb78d2b379be4bf5dec5f187", + "reference": "4298870062bfc667cb78d2b379be4bf5dec5f187", "shasum": "" }, "require": { - "php": "^7.2.5" + "php": ">=7.2.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-master": "5.1-dev" } }, "autoload": { @@ -2996,7 +3027,158 @@ "type": "tidelift" } ], - "time": "2020-03-27T16:56:45+00:00" + "time": "2020-05-20T17:43:50+00:00" + }, + { + "name": "symfony/polyfill-intl-grapheme", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-grapheme.git", + "reference": "e094b0770f7833fdf257e6ba4775be4e258230b2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/e094b0770f7833fdf257e6ba4775be4e258230b2", + "reference": "e094b0770f7833fdf257e6ba4775be4e258230b2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Grapheme\\": "" + }, + "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 intl's grapheme_* functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "grapheme", + "intl", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-12T16:47:27+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "1357b1d168eb7f68ad6a134838e46b0b159444a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/1357b1d168eb7f68ad6a134838e46b0b159444a9", + "reference": "1357b1d168eb7f68ad6a134838e46b0b159444a9", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, + "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 for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-12T16:14:59+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -3143,22 +3325,98 @@ ], "time": "2020-05-12T16:47:27+00:00" }, + { + "name": "symfony/polyfill-php80", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "5e30b2799bc1ad68f7feb62b60a73743589438dd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/5e30b2799bc1ad68f7feb62b60a73743589438dd", + "reference": "5e30b2799bc1ad68f7feb62b60a73743589438dd", + "shasum": "" + }, + "require": { + "php": ">=7.0.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "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" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-12T16:47:27+00:00" + }, { "name": "symfony/service-contracts", - "version": "v2.0.1", + "version": "v2.1.2", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "144c5e51266b281231e947b51223ba14acf1a749" + "reference": "66a8f0957a3ca54e4f724e49028ab19d75a8918b" }, "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/66a8f0957a3ca54e4f724e49028ab19d75a8918b", + "reference": "66a8f0957a3ca54e4f724e49028ab19d75a8918b", "shasum": "" }, "require": { - "php": "^7.2.5", + "php": ">=7.2.5", "psr/container": "^1.0" }, "suggest": { @@ -3167,7 +3425,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -3199,7 +3457,106 @@ "interoperability", "standards" ], - "time": "2019-11-18T17:27:11+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-20T17:43:50+00:00" + }, + { + "name": "symfony/string", + "version": "v5.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/string.git", + "reference": "90c2a5103f07feb19069379f3abdcdbacc7753a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/string/zipball/90c2a5103f07feb19069379f3abdcdbacc7753a9", + "reference": "90c2a5103f07feb19069379f3abdcdbacc7753a9", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-intl-grapheme": "~1.0", + "symfony/polyfill-intl-normalizer": "~1.0", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php80": "~1.15" + }, + "require-dev": { + "symfony/error-handler": "^4.4|^5.0", + "symfony/http-client": "^4.4|^5.0", + "symfony/translation-contracts": "^1.1|^2", + "symfony/var-exporter": "^4.4|^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\String\\": "" + }, + "files": [ + "Resources/functions.php" + ], + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "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 String component", + "homepage": "https://symfony.com", + "keywords": [ + "grapheme", + "i18n", + "string", + "unicode", + "utf-8", + "utf8" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-20T17:43:50+00:00" }, { "name": "theseer/fdomdocument", diff --git a/psalm.xml b/psalm.xml index 1041282..3a3524f 100644 --- a/psalm.xml +++ b/psalm.xml @@ -39,6 +39,7 @@ + diff --git a/src/Channel/Channel.php b/src/Channel/Channel.php index 0fbfa6c..4e76f37 100644 --- a/src/Channel/Channel.php +++ b/src/Channel/Channel.php @@ -13,8 +13,8 @@ use Daikon\MessageBus\MessageBusInterface; use Daikon\MessageBus\Channel\Subscription\SubscriptionInterface; use Daikon\MessageBus\Channel\Subscription\SubscriptionMap; -use Daikon\MessageBus\Error\EnvelopeNotAcceptable; -use Daikon\MessageBus\Error\SubscriptionUnknown; +use Daikon\MessageBus\Exception\EnvelopeNotAcceptable; +use Daikon\MessageBus\Exception\SubscriptionUnknown; use Daikon\Metadata\MetadataInterface; use Daikon\Metadata\MetadataEnricherInterface; use Daikon\Metadata\MetadataEnricherList; @@ -39,7 +39,7 @@ public function __construct( $this->subscriptions = $subscriptions; $this->guard = $guard ?? fn(): bool => true; $metadataEnrichers = $metadataEnrichers ?? new MetadataEnricherList; - $this->metadataEnrichers = $metadataEnrichers->prependEnricher(self::METADATA_KEY, $this->key); + $this->metadataEnrichers = $metadataEnrichers->enrichWith(self::METADATA_KEY, $this->key); } public function publish(EnvelopeInterface $envelope, MessageBusInterface $messageBus): void @@ -85,7 +85,7 @@ function (MetadataInterface $metadata, MetadataEnricherInterface $metadataEnrich private function accepts(EnvelopeInterface $envelope): bool { - return (bool)call_user_func($this->guard, $envelope); + return (bool)($this->guard)($envelope); } private function verify(EnvelopeInterface $envelope): void diff --git a/src/Channel/ChannelMap.php b/src/Channel/ChannelMap.php index 3759612..36db6e8 100644 --- a/src/Channel/ChannelMap.php +++ b/src/Channel/ChannelMap.php @@ -8,23 +8,18 @@ namespace Daikon\MessageBus\Channel; -use Daikon\DataStructure\TypedMapInterface; -use Daikon\DataStructure\TypedMapTrait; -use InvalidArgumentException; +use Daikon\DataStructure\TypedMap; +use Daikon\Interop\Assertion; -final class ChannelMap implements TypedMapInterface +final class ChannelMap extends TypedMap { - use TypedMapTrait; - public function __construct(iterable $channels = []) { $mappedChannels = []; /** @var ChannelInterface $channel */ foreach ($channels as $channel) { $channelKey = $channel->getKey(); - if (isset($mappedChannels[$channelKey])) { - throw new InvalidArgumentException("Channel key '$channelKey' is already defined."); - } + Assertion::keyNotExists($mappedChannels, $channelKey, "Channel key '$channelKey' is already defined."); $mappedChannels[$channelKey] = $channel; } diff --git a/src/Channel/Subscription/LazySubscription.php b/src/Channel/Subscription/LazySubscription.php index c140596..e1b5693 100644 --- a/src/Channel/Subscription/LazySubscription.php +++ b/src/Channel/Subscription/LazySubscription.php @@ -16,10 +16,10 @@ final class LazySubscription implements SubscriptionInterface { private string $key; - private SubscriptionInterface $compositeSubscription; - private Closure $factoryCallback; + private SubscriptionInterface $compositeSubscription; + public function __construct( string $key, Closure $transport, @@ -28,7 +28,7 @@ public function __construct( Closure $metadataEnrichers = null ) { $this->key = $key; - $this->factoryCallback = fn(): SubscriptionInterface => + $this->factoryCallback = fn(): Subscription => new Subscription( $this->key, $transport(), @@ -61,7 +61,7 @@ private function getSubscription(): SubscriptionInterface { /** @psalm-suppress TypeDoesNotContainType */ if (!isset($this->compositeSubscription)) { - $this->compositeSubscription = call_user_func($this->factoryCallback); + $this->compositeSubscription = ($this->factoryCallback)(); unset($this->factoryCallback); } return $this->compositeSubscription; diff --git a/src/Channel/Subscription/MessageHandler/MessageHandlerList.php b/src/Channel/Subscription/MessageHandler/MessageHandlerList.php index e9f7be4..8663a0d 100644 --- a/src/Channel/Subscription/MessageHandler/MessageHandlerList.php +++ b/src/Channel/Subscription/MessageHandler/MessageHandlerList.php @@ -8,13 +8,10 @@ namespace Daikon\MessageBus\Channel\Subscription\MessageHandler; -use Daikon\DataStructure\TypedListInterface; -use Daikon\DataStructure\TypedListTrait; +use Daikon\DataStructure\TypedList; -final class MessageHandlerList implements TypedListInterface +final class MessageHandlerList extends TypedList { - use TypedListTrait; - public function __construct(iterable $messageHandlers = []) { $this->init($messageHandlers, [MessageHandlerInterface::class]); diff --git a/src/Channel/Subscription/Subscription.php b/src/Channel/Subscription/Subscription.php index a9e81ea..66c108c 100644 --- a/src/Channel/Subscription/Subscription.php +++ b/src/Channel/Subscription/Subscription.php @@ -12,7 +12,7 @@ use Daikon\MessageBus\Channel\Subscription\MessageHandler\MessageHandlerList; use Daikon\MessageBus\Channel\Subscription\Transport\TransportInterface; use Daikon\MessageBus\EnvelopeInterface; -use Daikon\MessageBus\Error\EnvelopeNotAcceptable; +use Daikon\MessageBus\Exception\EnvelopeNotAcceptable; use Daikon\MessageBus\MessageBusInterface; use Daikon\Metadata\MetadataInterface; use Daikon\Metadata\MetadataEnricherInterface; @@ -42,7 +42,7 @@ public function __construct( $this->messageHandlers = $messageHandlers; $this->guard = $guard ?? fn(): bool => true; $metadataEnrichers = $metadataEnrichers ?? new MetadataEnricherList; - $this->metadataEnrichers = $metadataEnrichers->prependEnricher(self::METADATA_KEY, $this->key); + $this->metadataEnrichers = $metadataEnrichers->enrichWith(self::METADATA_KEY, $this->key); } public function publish(EnvelopeInterface $envelope, MessageBusInterface $messageBus): void @@ -79,7 +79,7 @@ function (MetadataInterface $metadata, MetadataEnricherInterface $metadataEnrich private function accepts(EnvelopeInterface $envelope): bool { - return (bool)call_user_func($this->guard, $envelope); + return (bool)($this->guard)($envelope); } private function verify(EnvelopeInterface $envelope): void diff --git a/src/Channel/Subscription/SubscriptionMap.php b/src/Channel/Subscription/SubscriptionMap.php index ffaaf58..ca01f2c 100644 --- a/src/Channel/Subscription/SubscriptionMap.php +++ b/src/Channel/Subscription/SubscriptionMap.php @@ -8,23 +8,22 @@ namespace Daikon\MessageBus\Channel\Subscription; -use Daikon\DataStructure\TypedMapInterface; -use Daikon\DataStructure\TypedMapTrait; -use InvalidArgumentException; +use Daikon\DataStructure\TypedMap; +use Daikon\Interop\Assertion; -final class SubscriptionMap implements TypedMapInterface +final class SubscriptionMap extends TypedMap { - use TypedMapTrait; - public function __construct(iterable $subscriptions = []) { $mappedSubscriptions = []; /** @var SubscriptionInterface $subscription */ foreach ($subscriptions as $subscription) { $subscriptionKey = $subscription->getKey(); - if (isset($mappedSubscriptions[$subscriptionKey])) { - throw new InvalidArgumentException("Subscription key '$subscriptionKey' is already defined."); - } + Assertion::keyNotExists( + $mappedSubscriptions, + $subscriptionKey, + "Subscription key '$subscriptionKey' is already defined." + ); $mappedSubscriptions[$subscriptionKey] = $subscription; } diff --git a/src/Channel/Subscription/Transport/TransportMap.php b/src/Channel/Subscription/Transport/TransportMap.php index 40cb1d6..c4c1c20 100644 --- a/src/Channel/Subscription/Transport/TransportMap.php +++ b/src/Channel/Subscription/Transport/TransportMap.php @@ -8,23 +8,22 @@ namespace Daikon\MessageBus\Channel\Subscription\Transport; -use Daikon\DataStructure\TypedMapInterface; -use Daikon\DataStructure\TypedMapTrait; -use InvalidArgumentException; +use Daikon\DataStructure\TypedMap; +use Daikon\Interop\Assertion; -final class TransportMap implements TypedMapInterface +final class TransportMap extends TypedMap { - use TypedMapTrait; - public function __construct(iterable $transports = []) { $mappedTransports = []; /** @var TransportInterface $transport */ foreach ($transports as $transport) { $transportKey = $transport->getKey(); - if (isset($mappedTransports[$transportKey])) { - throw new InvalidArgumentException("Transport key '$transportKey' is already defined."); - } + Assertion::keyNotExists( + $mappedTransports, + $transportKey, + "Transport key '$transportKey' is already defined." + ); $mappedTransports[$transportKey] = $transport; } diff --git a/src/Envelope.php b/src/Envelope.php index 7d302ef..66cbf8e 100644 --- a/src/Envelope.php +++ b/src/Envelope.php @@ -9,7 +9,7 @@ namespace Daikon\MessageBus; use DateTimeImmutable; -use Daikon\MessageBus\Error\EnvelopeNotAcceptable; +use Daikon\MessageBus\Exception\EnvelopeNotAcceptable; use Daikon\MessageBus\MessageInterface; use Daikon\Metadata\Metadata; use Daikon\Metadata\MetadataInterface; @@ -96,10 +96,10 @@ public static function fromNative($state): self $messageType = $state['@message_type'] ?? null; if (is_null($messageType) || !is_subclass_of($messageType, MessageInterface::class)) { - throw new EnvelopeNotAcceptable(sprintf( - "Message type '%s' given must be an instance of MessageInterface", - $messageType ?? 'null' - ), EnvelopeNotAcceptable::UNPARSEABLE); + throw new EnvelopeNotAcceptable( + sprintf("Message type '%s' given must be an instance of MessageInterface.", $messageType ?? 'null'), + EnvelopeNotAcceptable::UNPARSEABLE + ); } $metadataType = $state['@metadata_type'] ?? null; diff --git a/src/Error/SubscriptionUnknown.php b/src/Exception/ChannelUnknown.php similarity index 59% rename from src/Error/SubscriptionUnknown.php rename to src/Exception/ChannelUnknown.php index 9c8156c..fe58db3 100644 --- a/src/Error/SubscriptionUnknown.php +++ b/src/Exception/ChannelUnknown.php @@ -6,10 +6,10 @@ * file that was distributed with this source code. */ -namespace Daikon\MessageBus\Error; +namespace Daikon\MessageBus\Exception; -use Exception; +use Daikon\Interop\RuntimeException; -final class SubscriptionUnknown extends Exception implements ErrorInterface +final class ChannelUnknown extends RuntimeException implements MessageBusException { } diff --git a/src/Error/EnvelopeNotAcceptable.php b/src/Exception/EnvelopeNotAcceptable.php similarity index 73% rename from src/Error/EnvelopeNotAcceptable.php rename to src/Exception/EnvelopeNotAcceptable.php index 9d4b45f..d14cce5 100644 --- a/src/Error/EnvelopeNotAcceptable.php +++ b/src/Exception/EnvelopeNotAcceptable.php @@ -6,11 +6,11 @@ * file that was distributed with this source code. */ -namespace Daikon\MessageBus\Error; +namespace Daikon\MessageBus\Exception; -use Exception; +use Daikon\Interop\RuntimeException; -final class EnvelopeNotAcceptable extends Exception implements ErrorInterface +final class EnvelopeNotAcceptable extends RuntimeException implements MessageBusException { public const SUBSCRIPTION_KEY_MISSING = 6000; public const SUBSCRIPTION_KEY_UNEXPECTED = 6001; diff --git a/src/Error/ChannelUnknown.php b/src/Exception/MessageBusException.php similarity index 64% rename from src/Error/ChannelUnknown.php rename to src/Exception/MessageBusException.php index b0432b7..617f6ab 100644 --- a/src/Error/ChannelUnknown.php +++ b/src/Exception/MessageBusException.php @@ -6,10 +6,10 @@ * file that was distributed with this source code. */ -namespace Daikon\MessageBus\Error; +namespace Daikon\MessageBus\Exception; -use Exception; +use Daikon\Interop\DaikonException; -final class ChannelUnknown extends Exception implements ErrorInterface +interface MessageBusException extends DaikonException { } diff --git a/src/Error/ErrorInterface.php b/src/Exception/SubscriptionUnknown.php similarity index 58% rename from src/Error/ErrorInterface.php rename to src/Exception/SubscriptionUnknown.php index dd13f84..66c3ef3 100644 --- a/src/Error/ErrorInterface.php +++ b/src/Exception/SubscriptionUnknown.php @@ -6,8 +6,10 @@ * file that was distributed with this source code. */ -namespace Daikon\MessageBus\Error; +namespace Daikon\MessageBus\Exception; -interface ErrorInterface +use Daikon\Interop\RuntimeException; + +final class SubscriptionUnknown extends RuntimeException implements MessageBusException { } diff --git a/src/MessageBus.php b/src/MessageBus.php index ca662a6..dca3feb 100644 --- a/src/MessageBus.php +++ b/src/MessageBus.php @@ -10,8 +10,8 @@ use Daikon\MessageBus\Channel\ChannelInterface; use Daikon\MessageBus\Channel\ChannelMap; -use Daikon\MessageBus\Error\ChannelUnknown; -use Daikon\MessageBus\Error\EnvelopeNotAcceptable; +use Daikon\MessageBus\Exception\ChannelUnknown; +use Daikon\MessageBus\Exception\EnvelopeNotAcceptable; use Daikon\Metadata\MetadataInterface; use Daikon\Metadata\Metadata; use Daikon\Metadata\MetadataEnricherInterface; @@ -41,9 +41,8 @@ public function publish(MessageInterface $message, string $channelKey, MetadataI throw new ChannelUnknown("Channel '$channelKey' has not been registered on message bus."); } $metadata = $this->enrichMetadata($metadata ?? Metadata::makeEmpty()); - $envelopeType = $this->envelopeType; /** @var EnvelopeInterface $envelope */ - $envelope = $envelopeType::wrap($message, $metadata); + $envelope = $this->envelopeType::wrap($message, $metadata); /** @var ChannelInterface $channel */ $channel = $this->channelMap->get($channelKey); $channel->publish($envelope, $this); diff --git a/tests/Channel/ChannelMapTest.php b/tests/Channel/ChannelMapTest.php index 6f2272a..b6aa2c3 100644 --- a/tests/Channel/ChannelMapTest.php +++ b/tests/Channel/ChannelMapTest.php @@ -8,9 +8,9 @@ namespace Daikon\Tests\MessageBus; +use Daikon\Interop\InvalidArgumentException; use Daikon\MessageBus\Channel\ChannelInterface; use Daikon\MessageBus\Channel\ChannelMap; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; final class ChannelMapTest extends TestCase diff --git a/tests/Channel/ChannelTest.php b/tests/Channel/ChannelTest.php index 79f1c03..1dfd0bc 100644 --- a/tests/Channel/ChannelTest.php +++ b/tests/Channel/ChannelTest.php @@ -14,8 +14,8 @@ use Daikon\MessageBus\Channel\Subscription\SubscriptionMap; use Daikon\MessageBus\Envelope; use Daikon\MessageBus\EnvelopeInterface; -use Daikon\MessageBus\Error\EnvelopeNotAcceptable; -use Daikon\MessageBus\Error\SubscriptionUnknown; +use Daikon\MessageBus\Exception\EnvelopeNotAcceptable; +use Daikon\MessageBus\Exception\SubscriptionUnknown; use Daikon\MessageBus\MessageBusInterface; use Daikon\MessageBus\MessageInterface; use Daikon\Metadata\Metadata; diff --git a/tests/Channel/Subscription/SubscriptionMapTest.php b/tests/Channel/Subscription/SubscriptionMapTest.php index 4780a45..7df5fca 100644 --- a/tests/Channel/Subscription/SubscriptionMapTest.php +++ b/tests/Channel/Subscription/SubscriptionMapTest.php @@ -8,9 +8,9 @@ namespace Daikon\Tests\MessageBus; +use Daikon\Interop\InvalidArgumentException; use Daikon\MessageBus\Channel\Subscription\SubscriptionInterface; use Daikon\MessageBus\Channel\Subscription\SubscriptionMap; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; final class SubscriptionMapTest extends TestCase diff --git a/tests/Channel/Subscription/SubscriptionTest.php b/tests/Channel/Subscription/SubscriptionTest.php index 59c0b0a..a55477e 100644 --- a/tests/Channel/Subscription/SubscriptionTest.php +++ b/tests/Channel/Subscription/SubscriptionTest.php @@ -16,7 +16,7 @@ use Daikon\MessageBus\Channel\Subscription\Transport\TransportInterface; use Daikon\MessageBus\Envelope; use Daikon\MessageBus\EnvelopeInterface; -use Daikon\MessageBus\Error\EnvelopeNotAcceptable; +use Daikon\MessageBus\Exception\EnvelopeNotAcceptable; use Daikon\MessageBus\MessageBusInterface; use Daikon\MessageBus\MessageInterface; use Daikon\Metadata\Metadata; diff --git a/tests/Channel/Subscription/Transport/TransportMapTest.php b/tests/Channel/Subscription/Transport/TransportMapTest.php index fc9ae10..1213aa5 100644 --- a/tests/Channel/Subscription/Transport/TransportMapTest.php +++ b/tests/Channel/Subscription/Transport/TransportMapTest.php @@ -8,9 +8,9 @@ namespace Daikon\Tests\MessageBus; +use Daikon\Interop\InvalidArgumentException; use Daikon\MessageBus\Channel\Subscription\Transport\TransportInterface; use Daikon\MessageBus\Channel\Subscription\Transport\TransportMap; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; final class TransportMapTest extends TestCase diff --git a/tests/MessageBusTest.php b/tests/MessageBusTest.php index efa1569..190ecd1 100644 --- a/tests/MessageBusTest.php +++ b/tests/MessageBusTest.php @@ -12,8 +12,8 @@ use Daikon\MessageBus\Channel\ChannelMap; use Daikon\MessageBus\Envelope; use Daikon\MessageBus\EnvelopeInterface; -use Daikon\MessageBus\Error\ChannelUnknown; -use Daikon\MessageBus\Error\EnvelopeNotAcceptable; +use Daikon\MessageBus\Exception\ChannelUnknown; +use Daikon\MessageBus\Exception\EnvelopeNotAcceptable; use Daikon\MessageBus\MessageBus; use Daikon\MessageBus\MessageInterface; use Daikon\Metadata\Metadata;