Skip to content

[deprecation] Deprecate AddAssertArrayFromClassMethodDocblockRector - #8341

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-assert-array-from-class-method-docblock
Aug 10, 2026
Merged

[deprecation] Deprecate AddAssertArrayFromClassMethodDocblockRector#8341
TomasVotruba merged 1 commit into
mainfrom
deprecate-assert-array-from-class-method-docblock

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The rule reads a @param docblock type and injects a runtime Assert::all*() call at the top of the method.

 class SomeClass
 {
     /**
      * @param int[] $items
      */
     public function run(array $items)
     {
+        \Webmozart\Assert\Assert::allInteger($items);
     }
 }

Two problems:

  • it pays a runtime cost on every call, including hot paths, to check something static analysis already checks for free
  • it trusts the docblock. A stale or wrong @param turns into a hard runtime failure on input that was always valid.

That trade-off is a project-level decision, not a general upgrade. Write a custom rule where it is wanted.

Changes:

  • rule implements DeprecatedInterface and throws on refactor()
  • test cases + fixtures removed
  • config/set/assert.php and SetList::ASSERT removed, the set held only this rule
  • AssertClassName and ExistingAssertStaticCallResolver removed, they had no other user

…as runtime asserts from docblocks are risky and academic

The rule turns a @param docblock type into a runtime Assert call in every
method body. It pays a runtime cost on every call, and it trusts a docblock
that is often stale or wrong, so the assert can fail on valid input. Write a
custom rule if a project really wants this.
@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 10, 2026 19:18
@TomasVotruba
TomasVotruba force-pushed the deprecate-assert-array-from-class-method-docblock branch from aba7308 to af45c87 Compare August 10, 2026 19:21
@TomasVotruba
TomasVotruba merged commit 8f509ca into main Aug 10, 2026
54 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-assert-array-from-class-method-docblock branch August 10, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant