-
-
Notifications
You must be signed in to change notification settings - Fork 74
8.4 | Asymmetric Visibility support #851
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
Comments
@DanielEScherzer Thank you for working on this proposal and yes, opening a dedicated issue, like this, to discuss proposed implementation details for the more complex syntaxes is exactly as intended 👍🏻 (this is also noted under "Contribution Process" in the original issue). Tokenizer
While not mentioned anywhere in the RFC (nor made explicitly above), I've just done some checking and it looks like PHP introduced three new PHP native tokens class Foo
{
// This is supported.
public private(set) string $barA = 'baz';
private(set) protected string $barB = 'baz';
// Invalid use (fatal error), but PHP tokenizer supported, so should be supported in PHPCS too.
public(set) function foo() {}
// All of the below are parse errors.
public private (set) string $barE = 'baz';
public private( set) string $barF = 'baz';
public private(set ) string $barG = 'baz';
public private ( set ) string $barH = 'baz';
public private /*comment*/ (set) string $barI = 'baz';
} Based on that, your proposal for the Tokenizer related changes is exactly what is needed and should be straight-forward to implement. You have my blessing to go ahead with this part. ✅ File::getMemberProperties() and File::getMethodParameters()Before I give an opinion about the current proposals, I'd like to understand the reasoning behind them better, so would you mind expanding a bit on the various "why"'s ? Why introduce new I suspect there will be a reason behind proposing it like this and I'd like to understand this reason before discussing the implementation details. |
So that it is clear what the get visibility is, separate from the set visibility
So when there is asymmetric visibility, the property is not "public", "protected", or "private" in the sense of pre-asymmetric visibility meaning, so I'm trying to not change the behavior of For For
Since I figured that would have the smallest impact for sniffs that are not expecting asymmetric visibility - I care ~0 if we decide to always include the new indexes
The intent is that for any pre-existing sniff, it will work 100% the same when analyzing code that doesn't use asymmetric visibility; if it does use asymmetric visibility, then the sniff probably won't break, but it depends on if it checks for the visibility to be equal to something (is this private?) or not equal (is this non-public?) since that determines how the new "asymmetrical" value would be treated. |
@DanielEScherzer Thank you for your thoughts on this, but I don't think this is the way to go and I fear that the currently proposed solution for getMemberProperties()I'd like to propose the following alternative instead:
This way, there is no breaking change for existing sniffs. And sniffs can assert everything they need anyway:
getMethodParameter()Basically, I'd say this should behave the same, with the caveat that that method provides token positions too. So:
Is there any reason you can think of why the above would not be sufficient ? Adding the community cc-list for additional opinions on our competing proposals: /cc @asispts @dingo-d @fredden @GaryJones @greg0ire @kukulich @michalbundyra @Ocramius @sirbrillig @stronk7 @weierophinney @wimg |
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_SET
are defined if not already defined by PHP (for use when running on lower versions)PHP_CodeSniffer\Util\Tokens::$scopeModifiers
and::$contextSensitiveKeywords
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
, andnullable_type
are unchanged and not repeated here)Does not use asymmetric visibilitity
scope
would remain one ofpublic
,private
, orprotected
.The
get_scope
,get_scope_specified
, andset_scope
are 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 ofpublic
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
Abbreviated form results in
get_scope_specified
being falsegetMethodParameters()
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
property_set_visibility
is one of public/protected/privateset_visibility_token
is an integer for the stack pointer, can never be falseproperty_get_visibility
is one of public/protected/privateget_visibility_token
is an integer for the stack pointer, or false ifpublic
is implied via short formThe text was updated successfully, but these errors were encountered: