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

FunctionToConstantFixer - handle get_class() -> __CLASS__ as well #2944

Closed
wants to merge 5 commits into from
Closed

FunctionToConstantFixer - handle get_class() -> __CLASS__ as well #2944

wants to merge 5 commits into from

Conversation

SpacePossum
Copy link
Contributor

ping @kalessil :)

@@ -31,8 +31,9 @@
* @var string[]
*/
private static $availableFunctions = [
'phpversion' => 'PHP_VERSION',
'get_class' => 'T_CLASS',
Copy link
Member

Choose a reason for hiding this comment

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

I think the constant you meant is __CLASS__?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rotf, yeah thanks :)

@@ -126,6 +126,30 @@ public function provideTestCases()
'<?php echo phpversion(); echo php_sapi_name(); echo M_PI;',
['functions' => ['pi', 'phpversion']],
],
'get_class => T_CLASS' => [
Copy link
Member

Choose a reason for hiding this comment

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

Please add a test case with a trait instead of a class and one with a call to get_class() from outside a class. I think the code should not be changed for the latter as the result is not the same (false + warning vs. "").

Copy link
Contributor

Choose a reason for hiding this comment

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

Trait context can be fixed as well without any side effects: https://3v4l.org/i6M96

Checking that the call happening in a method makes sense (we don't do this, but I'll fix this), @SpacePossum is it possible or needs significant efforts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH I think it is an odd thing that this wasn't patched in PHP to act the same when they added the warning.
Not sure checking the calling get_class outside class "" vs. false is worth the effort. The reason for that is that it makes no sense anyway to do it, as all it is is a very expensive way to get false or ''.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, skipping kalessil/phpinspectionsea#425 then as well.

Copy link
Member

Choose a reason for hiding this comment

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

👍 regarding get_class() from outside a class. I would still add a test case with a trait though.

@kalessil
Copy link
Contributor

Awesome, thanks @SpacePossum !

@SpacePossum SpacePossum changed the title FunctionToConstantFixer - get_class() -> T_CLASS FunctionToConstantFixer - get_class() -> __CLASS__ Jul 28, 2017
@julienfalque julienfalque added this to the 2.5.0 milestone Jul 28, 2017
@keradus keradus changed the title FunctionToConstantFixer - get_class() -> __CLASS__ FunctionToConstantFixer - handle get_class() -> __CLASS__ as well Jul 30, 2017
@keradus
Copy link
Member

keradus commented Jul 30, 2017

Thank you @SpacePossum.

@keradus keradus closed this in 4e57cce Jul 30, 2017
@keradus keradus deleted the master_FunctionToConstantFixer_T_CLASS branch July 30, 2017 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants