generated from spawnia/php-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(phpstan): add separate ID capitalization rules for variables, parameters, methods, and classes #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…D capitalization checking - Add CapitalizationOfIDRule that can check variables, parameters, methods, and classes - Refactor VariableNameIdToIDRule to extend CapitalizationOfIDRule with variables-only config - Add NodeNameExtractor interface with focused implementations for each node type - Cache extractors in constructor for better performance - Add 'Identity' to false positives list - Add PHPStan neon configuration support via mllCapitalizationOfID parameters BREAKING CHANGE: None - VariableNameIdToIDRule maintains backwards compatibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
0303166 to
0600a50
Compare
Add integration tests that run PHPStan CLI against fixture files to verify the rule correctly detects ID capitalization violations in methods, parameters, and variables. - Add WrongCapitalization.php fixture with intentional violations - Add CorrectCapitalization.php fixture to verify no false positives - Add CapitalizationOfIDRuleIntegrationTest that uses PHPStan CLI - Ignore fixture files in phpstan.neon to prevent false positives during normal analysis 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
dfd03ac to
bef2ac9
Compare
…tern - Move PHPStan tests from tests/PHPStan/Rules/ to tests/PHPStan/ - Replace CLI-based integration test with PHPStanTestCase-based test - Rename Fixtures/ to data/ to match laravel-utils convention - Keep unit tests for static methods (containsWrongIDCapitalization, fixIDCapitalization) separate from integration tests - Update phpstan.neon ignore path for test data files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…er node type Split the configurable CapitalizationOfIDRule into focused, single-purpose rules: - VariableNameIdToIDRule (checks variables) - ParameterNameIdToIDRule (checks parameters) - MethodNameIdToIDRule (checks methods) - ClassNameIdToIDRule (checks classes) This follows PHPStan community patterns (phpstan-strict-rules) and enables gradual rollout via PHPStan baseline - each rule can be enabled independently. Changes: - Convert CapitalizationOfIDRule to abstract base class - Create separate concrete rules for each node type - Remove NodeNameExtractor classes (no longer needed) - Simplify extension.neon (remove parametersSchema, conditionalTags) - Update tests for new structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add formatNameForMessage() hook for custom name formatting in error messages - Restore $ prefix for variable names in error messages - Remove unused imports from integration test - Add class name test fixture (LabIdProcessor) to test ClassNameIdToIDRule 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
MLL guidelines prohibit @phpstan-ignore-line and @phpstan-ignore-next-line. Move phpstanApi.method and phpstanApi.classConstant ignores to phpstan.neon for the tests/PHPStan/ directory. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Extract method call results to variables before using them as function parameters or in method chains. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Parameters are written with $ in PHP, so the error message should show "$labId" not "labId" for consistency with variable errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Testing that getNodeType() returns a constant is pointless - no logic is involved. The integration test already verifies rules work on actual files, and CapitalizationOfIDRuleTest covers the shared detection logic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The `identifier:` syntax is not supported in older PHPStan versions used with PHP 7.4. Use message pattern matching instead. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
spawnia
reviewed
Dec 5, 2025
- Remove misleading comment from extension.neon - Replace \Safe\preg_match with Str::contains for consistency - Override fixIDCapitalization in ClassNameIdToIDRule (Id -> ID for classes) - Format test arrays with one item per line - Use array<T> notation consistently in PHPDoc - Add test case for $id not causing an error - Add ClassNameIdToIDRuleTest for Id -> ID behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
8df9394 to
c852b9b
Compare
spawnia
reviewed
Dec 5, 2025
github-actions bot
pushed a commit
that referenced
this pull request
Dec 8, 2025
# [5.23.0](v5.22.0...v5.23.0) (2025-12-08) ### Features * **phpstan:** add separate ID capitalization rules for variables, parameters, methods, and classes ([#64](#64)) ([02b2f53](02b2f53))
|
🎉 This PR is included in version 5.23.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
VariableNameIdToIDRule- checks variable namesParameterNameIdToIDRule- checks parameter namesMethodNameIdToIDRule- checks method namesClassNameIdToIDRule- checks class namesCapitalizationOfIDRulebase class with shared logicUsage
Add rules individually to your
phpstan.neon:Error Identifiers
mll.variableNameIdToIDmll.parameterNameIdToIDmll.methodNameIdToIDmll.classNameIdToIDTest plan
makeruns successfully🤖 Generated with Claude Code