Skip to content

HashFunctionsReturnTypeExtension: init hash-algorithm list lazily - #6345

Merged
staabm merged 2 commits into
phpstan:2.2.xfrom
staabm:lazy-algos
Sep 2, 2026
Merged

HashFunctionsReturnTypeExtension: init hash-algorithm list lazily#6345
staabm merged 2 commits into
phpstan:2.2.xfrom
staabm:lazy-algos

Conversation

@staabm

@staabm staabm commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

we need this list only when we find one of the supported hash functions with a constant 1st arg.

atm we pay the cost for listing the algos on rule creation, no matter how the analyzed code looks like.
its not that expensive (1-2ms), but its easy to prevent

@staabm
staabm marked this pull request as ready for review September 2, 2026 11:04
@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The lazy initialization preserves existing behavior while safely avoiding unnecessary computation.

Pull request overview

Lazily initializes the supported hash algorithm list, avoiding unnecessary startup work when hash functions with constant algorithm arguments are not analyzed.

Changes:

  • Makes the algorithm cache nullable.
  • Populates it on first use with hash_algos().
File summaries
File Description
src/Type/Php/HashFunctionsReturnTypeExtension.php Defers hash algorithm discovery until validation is required.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@staabm
staabm merged commit 03e11c6 into phpstan:2.2.x Sep 2, 2026
782 of 792 checks passed
@staabm
staabm deleted the lazy-algos branch September 2, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants