Skip to content

Conversation

@simbig
Copy link
Contributor

@simbig simbig commented Dec 4, 2025

Summary

  • Add separate PHPStan rules for checking "ID" vs "Id" capitalization:
    • VariableNameIdToIDRule - checks variable names
    • ParameterNameIdToIDRule - checks parameter names
    • MethodNameIdToIDRule - checks method names
    • ClassNameIdToIDRule - checks class names
  • Refactor to abstract CapitalizationOfIDRule base class with shared logic
  • Each rule has its own error identifier for granular baseline control

Usage

Add rules individually to your phpstan.neon:

rules:
    - MLL\Utils\PHPStan\Rules\VariableNameIdToIDRule
    # Enable others as needed:
    # - MLL\Utils\PHPStan\Rules\ParameterNameIdToIDRule
    # - MLL\Utils\PHPStan\Rules\MethodNameIdToIDRule
    # - MLL\Utils\PHPStan\Rules\ClassNameIdToIDRule

Error Identifiers

  • mll.variableNameIdToID
  • mll.parameterNameIdToID
  • mll.methodNameIdToID
  • mll.classNameIdToID

Test plan

  • All existing tests pass
  • Integration tests using PHPStanTestCase
  • PHPStan analysis passes
  • make runs successfully

🤖 Generated with Claude Code

…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>
@simbig simbig force-pushed the extend-variable-name-id-rule branch from 0303166 to 0600a50 Compare December 4, 2025 17:13
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>
@simbig simbig force-pushed the extend-variable-name-id-rule branch from dfd03ac to bef2ac9 Compare December 4, 2025 18:49
Simon Bigelmayr and others added 2 commits December 5, 2025 08:32
…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>
@simbig simbig changed the title feat(phpstan): add configurable CapitalizationOfIDRule feat(phpstan): add separate ID capitalization rules for variables, parameters, methods, and classes Dec 5, 2025
Simon Bigelmayr and others added 9 commits December 5, 2025 09:18
- 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>
@simbig simbig requested a review from spawnia December 5, 2025 10:21
- 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>
@simbig simbig force-pushed the extend-variable-name-id-rule branch from 8df9394 to c852b9b Compare December 5, 2025 14:42
@simbig simbig requested a review from spawnia December 5, 2025 14:46
@simbig simbig requested a review from spawnia December 8, 2025 11:00
@spawnia spawnia merged commit 02b2f53 into master Dec 8, 2025
28 checks passed
@spawnia spawnia deleted the extend-variable-name-id-rule branch December 8, 2025 13:37
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))
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

🎉 This PR is included in version 5.23.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants