Skip to content

Conversation

@dereuromark
Copy link
Member

Summary

This PR introduces stricter naming convention enforcement for CakePHP 6.x, aligned with PSR naming conventions.

New Sniffs

ValidPropertyNameSniff (new)

  • Flags underscore-prefixed properties ($_propertyName)
  • Applies to all visibility levels (public, protected, private)

ValidFunctionNameSniff (updated)

  • Now flags underscore-prefixed protected/private methods
  • Exception: Entity accessor/mutator patterns are still allowed (_getFieldName(), _setFieldName())
  • Added T_ENUM support
  • Fixed $_magicMethods property naming (was using underscore prefix itself)

Ruleset Changes

  • Removed PSR2.Classes.PropertyDeclaration.Underscore exclusion - PSR2 property underscore checks now apply
  • Added new Slevomat sniffs for modern PHP:
    • RequireNullCoalesceEqualOperator - Require ??= operator
    • RequireNullSafeObjectOperator - Require ?-> operator
    • RequireSelfReference - Require self:: instead of class name
    • NullTypeHintOnLastPosition - Enforce string|null instead of null|string

Migration

Projects upgrading to CakePHP 6.x should:

  1. Rename underscore-prefixed properties: $_propertyName$propertyName
  2. Rename underscore-prefixed methods (except Entity accessors): _methodName()methodName()

The cakephp/upgrade tool has Rector rules to automate these renames.

Tests

All existing tests pass, new test cases added for:

  • Property underscore detection (class and trait)
  • Method underscore detection with Entity accessor exception

- Update ValidFunctionNameSniff to flag underscore-prefixed protected/private
  methods (except Entity accessor/mutator pattern _get*, _set*)
- Add ValidPropertyNameSniff to flag underscore-prefixed properties
- Remove PSR2.Classes.PropertyDeclaration.Underscore exclusion from ruleset
- Add new Slevomat sniffs:
  - RequireNullCoalesceEqualOperator
  - RequireNullSafeObjectOperator
  - RequireSelfReference
  - NullTypeHintOnLastPosition
- Fix $_magicMethods property naming in sniff itself
- Add T_ENUM support to ValidFunctionNameSniff
@dereuromark
Copy link
Member Author

You're right - removed the custom ValidPropertyNameSniff. The PSR2 built-in handles properties.

Kept the custom ValidFunctionNameSniff though, since it allows the Entity accessor/mutator pattern (_getName, _setField) which the PSR2 method sniff would flag.

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.

2 participants