From 7cd936de882e675cdfc10668a68b259d85b53ad9 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 11 Mar 2026 10:58:23 +0100 Subject: [PATCH 1/4] Ban `CarbonImmutable` via PHPStan Our codebase is heavily biased towards mutable Carbon. Mixing mutable and immutable semantics makes it hard to reason about code. https://gitlab.mll/documentation/coding-guidelines/-/issues/313 Co-Authored-By: Claude Opus 4.6 --- rules.neon | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rules.neon b/rules.neon index f354ac38..51c95af6 100644 --- a/rules.neon +++ b/rules.neon @@ -14,6 +14,10 @@ parameters: - function: 'clock()' message: 'it is just meant for debugging.' errorTip: 'remove debugging code.' + disallowedClasses: + - class: 'Carbon\CarbonImmutable' + message: 'mixing mutable and immutable Carbon semantics makes code hard to reason about.' + errorTip: 'use Carbon\Carbon instead. See https://gitlab.mll/documentation/coding-guidelines/-/issues/313' disallowedStaticCalls: - method: 'Carbon\Carbon::create()' message: 'it ignores errors.' From 9435a1acc93a036c3f882cbc23500dd251631292 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 11 Mar 2026 11:33:38 +0100 Subject: [PATCH 2/4] feat!: ban `CarbonImmutable` via PHPStan Add `disallowedClasses` rule for `Carbon\CarbonImmutable`. BREAKING CHANGE: Requires `spaze/phpstan-disallowed-calls` ^4.4 (dropped ^2). The `rules.neon` is only loaded on PHP 8.0+ anyway, where ^4.4 applies. https://gitlab.mll/documentation/coding-guidelines/-/issues/313 Co-Authored-By: Claude Opus 4.6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9f3cb7cb..aa6cfec6 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "phpstan/phpstan-strict-rules": "^1 || ^2.0.3", "phpunit/phpunit": "^9.6.22 || ^10.5.45 || ^11.5.10 || ^12.0.5", "rector/rector": "^1.2.10 || ^2.0.9", - "spaze/phpstan-disallowed-calls": "^2 || ^4.4", + "spaze/phpstan-disallowed-calls": "^4.4", "thecodingmachine/phpstan-safe-rule": "^1.2.0" }, "suggest": { From 5accc51ac318e3508d4d36793e529e76fc27ec8c Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 11 Mar 2026 11:48:44 +0100 Subject: [PATCH 3/4] fix(ci): remove spaze from PHP 8.0 CI to fix dependency resolution spaze/phpstan-disallowed-calls ^4.4 requires phpstan ^1.12.6, which conflicts with larastan 1.0.4 (phpstan <1.9) on PHP 8.0. Co-Authored-By: Claude Opus 4.6 --- .github/workflows/validate.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index f221f07b..ee05762f 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -55,7 +55,10 @@ jobs: spaze/phpstan-disallowed-calls - if: matrix.php-version == '8.0' - run: composer remove --dev --no-update rector/rector + run: > + composer remove --dev --no-update + rector/rector + spaze/phpstan-disallowed-calls - if: matrix.php-version == '7.4' || matrix.php-version == '8.0' run: rm -rf src/Enum tests/Enum src/FluidXPlate/Scalars src/Microplate/Scalars tests/FluidXPlate/Scalars tests/Microplate/Scalars @@ -102,7 +105,10 @@ jobs: spaze/phpstan-disallowed-calls - if: matrix.php-version == '8.0' - run: composer remove --dev --no-update rector/rector + run: > + composer remove --dev --no-update + rector/rector + spaze/phpstan-disallowed-calls - if: matrix.php-version == '7.4' || matrix.php-version == '8.0' run: rm -rf src/Enum tests/Enum src/FluidXPlate/Scalars src/Microplate/Scalars tests/FluidXPlate/Scalars tests/Microplate/Scalars From 5bb882e2ede7da9a1ccbe53da1fadc62b58099df Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 11 Mar 2026 11:56:58 +0100 Subject: [PATCH 4/4] fix(ci): remove spaze from PHP 8.0 CI to fix dependency resolution spaze/phpstan-disallowed-calls ^4.4 requires phpstan ^1.12.6, which conflicts with larastan 1.0.4 (phpstan <1.9) on PHP 8.0. Include rules.neon based on whether spaze is installed rather than checking the PHP version, so it works regardless of which PHP versions have spaze removed in CI. Co-Authored-By: Claude Opus 4.6 --- phpstan/include-by-php-version.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpstan/include-by-php-version.php b/phpstan/include-by-php-version.php index 6038baf5..c4cddb98 100644 --- a/phpstan/include-by-php-version.php +++ b/phpstan/include-by-php-version.php @@ -2,9 +2,7 @@ $includes = []; -// PHP 8.0+ can use rules.neon (requires spaze/phpstan-disallowed-calls) -// PHP 7.4 has this package removed via composer, so skip rules.neon -if (version_compare(PHP_VERSION, '8.0', '>=')) { +if (class_exists(\Spaze\PHPStan\Rules\Disallowed\DisallowedHelper::class)) { $includes[] = __DIR__ . '/../rules.neon'; }