From f7c9d37d8797e93201ba8d39082c4e25c9caaada Mon Sep 17 00:00:00 2001 From: Aaron Bauman Date: Tue, 24 Mar 2026 09:56:47 -0400 Subject: [PATCH] Conditional class definition for assert class to support next version of webmozart/assert --- composer.json | 2 +- src/Assert.php | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 77ea4ed2..aa9719e9 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php-http/discovery": "^1.19", "php-http/multipart-stream-builder": "^1.1.2", "psr/http-client": "^1.0", - "webmozart/assert": "^1.9.1" + "webmozart/assert": "^1.9.1 || ^2.0" }, "require-dev": { "ergebnis/composer-normalize": "^2.43", diff --git a/src/Assert.php b/src/Assert.php index 58052b85..4b9e7457 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -16,18 +16,26 @@ /** * We need to override Webmozart\Assert because we want to throw our own Exception. * + * Webmozart\Assert version 2.0 is required for PHP 8.4 support, but + * incompatible with versions 1.x. So unfortunately we need this conditional + * class definition. + * * @author Tobias Nyholm */ -final class Assert extends \Webmozart\Assert\Assert -{ - /** - * @psalm-pure this method is not supposed to perform side-effects - * @psalm-return never - * @param mixed $message - * @return void - */ +if (version_compare(\Composer\InstalledVersions::getVersion('webmozart/assert'), '2.0.0', '>=')) { + final class Assert extends \Webmozart\Assert\Assert + { + protected static function reportInvalidArgument(string $message): never + { + throw new InvalidArgumentException($message); + } + } +} else { + final class Assert extends \Webmozart\Assert\Assert + { protected static function reportInvalidArgument($message): void { - throw new InvalidArgumentException($message); + throw new InvalidArgumentException($message); } + } }