Skip to content
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

Add support for nullsafe object operator ("?->") #5586

Merged
merged 1 commit into from Apr 14, 2021
Merged

Add support for nullsafe object operator ("?->") #5586

merged 1 commit into from Apr 14, 2021

Conversation

kubawerlos
Copy link
Contributor

@kubawerlos kubawerlos commented Mar 31, 2021

The difference where you can use T_OBJECT_OPERATOR, but cannot T_NULLSAFE_OBJECT_OPERATOR is write context (see: https://3v4l.org/PJZJo).

Current list of files having T_OBJECT_OPERATOR:

$ git grep -l T_OBJECT_OPERATOR
src/Fixer/Alias/ArrayPushFixer.php // `T_OBJECT_OPERATOR` always used in write context
src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php // `T_OBJECT_OPERATOR` always used in write context
src/Fixer/PhpUnit/PhpUnitExpectationFixer.php // `T_OBJECT_OPERATOR` used to create token
src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php // `T_OBJECT_OPERATOR` used to create token
src/Tokenizer/Token.php // This is actually handling pair of `T_OBJECT_OPERATOR` and `T_NULLSAFE_OBJECT_OPERATOR`
tests/Test/AbstractFixerTestCase.php // Used to search through our codebase
tests/Tokenizer/TokenTest.php

Initial list of files having T_OBJECT_OPERATOR (there was no single occurrence of T_NULLSAFE_OBJECT_OPERATOR):

$ git grep -l T_OBJECT_OPERATOR
doc/rules/index.rst
doc/rules/operator/object_operator_without_whitespace.rst
src/Fixer/AbstractIncrementOperatorFixer.php
src/Fixer/Alias/ArrayPushFixer.php
src/Fixer/Alias/PowToExponentiationFixer.php
src/Fixer/Casing/ConstantCaseFixer.php
src/Fixer/Casing/LowercaseStaticReferenceFixer.php
src/Fixer/Casing/MagicMethodCasingFixer.php
src/Fixer/Casing/NativeFunctionCasingFixer.php
src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php
src/Fixer/ClassNotation/SelfAccessorFixer.php
src/Fixer/ClassUsage/DateTimeImmutableFixer.php
src/Fixer/ControlStructure/YodaStyleFixer.php
src/Fixer/FunctionNotation/SingleLineThrowFixer.php
src/Fixer/Import/NoUnusedImportsFixer.php
src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php
src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php
src/Fixer/Operator/IncrementStyleFixer.php
src/Fixer/Operator/NewWithBracesFixer.php
src/Fixer/Operator/ObjectOperatorWithoutWhitespaceFixer.php
src/Fixer/Operator/OperatorLinebreakFixer.php
src/Fixer/PhpUnit/PhpUnitExpectationFixer.php
src/Fixer/PhpUnit/PhpUnitMockFixer.php
src/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixer.php
src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php
src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php
src/Fixer/Whitespace/MethodChainingIndentationFixer.php
src/Tokenizer/Analyzer/FunctionsAnalyzer.php
src/Tokenizer/Token.php
src/Tokenizer/TokensAnalyzer.php
src/Tokenizer/Transformer/CurlyBraceTransformer.php
tests/Test/AbstractFixerTestCase.php
tests/Tokenizer/TokenTest.php

Closes #5584

@coveralls
Copy link

coveralls commented Mar 31, 2021

Coverage Status

Coverage increased (+0.007%) to 91.857% when pulling 91b5d10 on kubawerlos:support_nullsafe_object_operator into 61b9090 on FriendsOfPHP:2.18.

@kubawerlos kubawerlos marked this pull request as ready for review April 1, 2021 19:21
@keradus keradus modified the milestones: 2.18.5, 2.18.6 Apr 2, 2021
Copy link
Member

@keradus keradus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good as a fix!

only wish for future - we should find a way to cleanup Token to serve as DTO and not have all that extra logic

@keradus
Copy link
Member

keradus commented Apr 14, 2021

Thank you @kubawerlos.

@keradus keradus merged commit 456ba4f into PHP-CS-Fixer:2.18 Apr 14, 2021
@kubawerlos kubawerlos deleted the support_nullsafe_object_operator branch April 14, 2021 19:11
yield [
'<?php return $this->myObject1?->{$index}+$b === "";',
//null,
//['equal' => true, 'identical' => true]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kubawerlos , should we uncomment? please take over and cleanup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handled in #5646

keradus added a commit that referenced this pull request Apr 18, 2021
This PR was merged into the 3.0 branch.

Discussion
----------

DX: YodaStyleFixerTest - fix CI

I noticed it here:
 https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5641/checks?check_run_id=2374783267

FYI @kubawerlos , looks like coming from #5586

Commits
-------

e9cdb51 DX: YodaStyleFixerTest - fix CI
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.

Compiler optimized native function invocation incorrectly detected after nullsafe operator
3 participants