I figured instead of putting all of the discussions on #734, it might be helpful to have a dedicated task to discuss this - let me know if I was wrong
Proposal:
tokenizer
- New tokens
T_PUBLIC_SET, T_PROTECTED_SET, and T_PRIVATE_SET are defined if not already defined by PHP (for use when running on lower versions)
- They are added to
PHP_CodeSniffer\Util\Tokens::$scopeModifiers and ::$contextSensitiveKeywords
- They are added to
PHP_CodeSniffer\Tokenizers\PHP::$knownLengths
getMemberProperties()
Currently:
|
* <code> |
|
* array( |
|
* 'scope' => string, // Public, private, or protected. |
|
* 'scope_specified' => boolean, // TRUE if the scope was explicitly specified. |
|
* 'is_static' => boolean, // TRUE if the static keyword was found. |
|
* 'is_readonly' => boolean, // TRUE if the readonly keyword was found. |
|
* 'is_final' => boolean, // TRUE if the final keyword was found. |
|
* 'type' => string, // The type of the var (empty if no type specified). |
|
* 'type_token' => integer|false, // The stack pointer to the start of the type |
|
* // or FALSE if there is no type. |
|
* 'type_end_token' => integer|false, // The stack pointer to the end of the type |
|
* // or FALSE if there is no type. |
|
* 'nullable_type' => boolean, // TRUE if the type is preceded by the nullability |
|
* // operator. |
|
* ); |
|
* </code> |
New:
Returns (the is_static, is_readonly, is_final, type, type_token, type_end_token, and nullable_type are unchanged and not repeated here)
Does not use asymmetric visibilitity
scope would remain one of public, private, or protected.
The get_scope, get_scope_specified, and set_scope are not included in the array if asymmetric visibility is not used.
return [
'scope' => 'public', // or private or protected,
'scope_specified' => true, // can also be false
...
];
Uses asymmetric visibility
If get and set visibility are both explicitly provided (or just set visibility public(set) is provided, and the get visibility of public is implicit) then even if the visibilities are the same asymmetric visibility handling is triggered:
scope is set to asymmetric
scope_specified is true
get_scope is public/protected/private
get_scope_specified is based on if the get scope is specified, or just implicitly public because only the set scope was specified
set_scope is public/protected/private [there is no set_scope_specified because it must be specified for asymmetric properties]
For the
These updates should include special handling for the abbreviated form.
Abbreviated form results in get_scope_specified being false
return [
'scope' => 'asymmetric', // always (for asymmetric properties)
'scope_specified' => true, // always (for asymmetric properties)
'get_scope' => 'public', // or protected, or private
'get_scope_specified' => true, // can also be false
'set_scope' => 'private', // or public, or protected
...
];
getMethodParameters()
Currently:
|
* Parameters declared using PHP 8 constructor property promotion, have these additional array indexes: |
|
* 'property_visibility' => string, // The property visibility as declared. |
|
* 'visibility_token' => integer|false, // The stack pointer to the visibility modifier token |
|
* // or FALSE if the visibility is not explicitly declared. |
|
* 'property_readonly' => boolean, // TRUE if the readonly keyword was found. |
|
* 'readonly_token' => integer, // The stack pointer to the readonly modifier token. |
Does not use asymmetric visibility
Unchanged
Uses asymmetric visibility
property_visibility is set to asymmetric
visibility_token is set to false
- new array key
property_set_visibility is one of public/protected/private
- new array key
set_visibility_token is an integer for the stack pointer, can never be false
- new array key
property_get_visibility is one of public/protected/private
- new array key
get_visibility_token is an integer for the stack pointer, or false if public is implied via short form
I figured instead of putting all of the discussions on #734, it might be helpful to have a dedicated task to discuss this - let me know if I was wrong
Proposal:
tokenizer
T_PUBLIC_SET,T_PROTECTED_SET, andT_PRIVATE_SETare defined if not already defined by PHP (for use when running on lower versions)PHP_CodeSniffer\Util\Tokens::$scopeModifiersand::$contextSensitiveKeywordsPHP_CodeSniffer\Tokenizers\PHP::$knownLengthsgetMemberProperties()Currently:
PHP_CodeSniffer/src/Files/File.php
Lines 1842 to 1857 in be74da1
New:
Returns (the
is_static,is_readonly,is_final,type,type_token,type_end_token, andnullable_typeare unchanged and not repeated here)Does not use asymmetric visibilitity
scopewould remain one ofpublic,private, orprotected.The
get_scope,get_scope_specified, andset_scopeare not included in the array if asymmetric visibility is not used.Uses asymmetric visibility
If get and set visibility are both explicitly provided (or just set visibility
public(set)is provided, and the get visibility ofpublicis implicit) then even if the visibilities are the same asymmetric visibility handling is triggered:scopeis set toasymmetricscope_specifiedistrueget_scopeis public/protected/privateget_scope_specifiedis based on if the get scope is specified, or just implicitly public because only the set scope was specifiedset_scopeis public/protected/private [there is noset_scope_specifiedbecause it must be specified for asymmetric properties]For the
Abbreviated form results in
get_scope_specifiedbeing falsegetMethodParameters()Currently:
PHP_CodeSniffer/src/Files/File.php
Lines 1365 to 1370 in be74da1
Does not use asymmetric visibility
Unchanged
Uses asymmetric visibility
property_visibilityis set toasymmetricvisibility_tokenis set tofalseproperty_set_visibilityis one of public/protected/privateset_visibility_tokenis an integer for the stack pointer, can never be falseproperty_get_visibilityis one of public/protected/privateget_visibility_tokenis an integer for the stack pointer, or false ifpublicis implied via short form