Description
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 needed on how to handle this for the tokenizer
- Tokenizer changes needed - property declarations
- Tokenizer changes needed - constructor property promotion
- Updates needed to the predefined token collections in the
Tokens
class- Updates needed to utility functions -
getMemberProperties()
,getMethodParameters()
(for constructor property promotion)
These updates should include special handling for the abbreviated form.- Updates needed to abstract sniffs ?
This needs investigation, but I imagine theAbstractScopeSniff
and theAbstractVariableSniff
might need updates.- Sniff updates needed
Proposal:
tokenizer
- New tokens
T_PUBLIC_SET
,T_PROTECTED_SET
, andT_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:
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
, 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 toasymmetric
scope_specified
istrue
get_scope
is public/protected/privateget_scope_specified
is based on if the get scope is specified, or just implicitly public because only the set scope was specifiedset_scope
is public/protected/private [there is noset_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:
PHP_CodeSniffer/src/Files/File.php
Lines 1365 to 1370 in be74da1
Does not use asymmetric visibility
Unchanged
Uses asymmetric visibility
property_visibility
is set toasymmetric
visibility_token
is set tofalse
- 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 ifpublic
is implied via short form