Skip to content

[test] String class name to class constant rector ignore array keys 1539#1540

Closed
Aerendir wants to merge 2 commits intorectorphp:masterfrom
Aerendir:StringClassNameToClassConstantRector-ignore-array-keys-1539
Closed

[test] String class name to class constant rector ignore array keys 1539#1540
Aerendir wants to merge 2 commits intorectorphp:masterfrom
Aerendir:StringClassNameToClassConstantRector-ignore-array-keys-1539

Conversation

@Aerendir
Copy link
Copy Markdown
Contributor

@Aerendir Aerendir commented Jun 3, 2019

Issue #1539.

@Aerendir Aerendir mentioned this pull request Jun 3, 2019
@TomasVotruba
Copy link
Copy Markdown
Member

First commit says, that keys are ignored.

Would you add test with namespaces class that proves that?

@Aerendir
Copy link
Copy Markdown
Contributor Author

Aerendir commented Jun 3, 2019

@TomasVotruba no, it is not clear my comment: it says that if I call $var['Exception'], then I get the \Exception object.

But instead, the key is transformed into $var[\Exception::class] and this is not correct: it should remain $var['Exception'], also if Exception is the name of an existent class.

@TomasVotruba TomasVotruba changed the title String class name to class constant rector ignore array keys 1539 [test] String class name to class constant rector ignore array keys 1539 Jun 4, 2019
@TomasVotruba
Copy link
Copy Markdown
Member

TomasVotruba commented Jun 4, 2019

But instead, the key is transformed into $var[\Exception::class]

This is expected behavior:

-'SomeClass' => new SomeClass
+'SomeClass::class' => new SomeClass

Imagine the 'SomeClass' would be skipped here and during refactoring the SomeClass would be renamed to AnotherClass but the key skipped:

'SomeClass' => new AnotherClass

@Aerendir
Copy link
Copy Markdown
Contributor Author

Aerendir commented Jun 4, 2019

@TomasVotruba , in my case it is not intended as the name of a class but, instead, as a key by which I can get the Exception.

Maybe I need to change the name of my key to something like ExceptionObj 🤔

@TomasVotruba
Copy link
Copy Markdown
Member

Why is it upper class anyway? How do you use it?

@Aerendir
Copy link
Copy Markdown
Contributor Author

Aerendir commented Jun 4, 2019

@TomasVotruba there is no particular reason: I simply wrote it this way 😅.

You are right: I can simply switch to lowercase, am I right?

@TomasVotruba
Copy link
Copy Markdown
Member

I see :) lowercase would be better in this particular case. We'll see how it's used in the wild

@TomasVotruba
Copy link
Copy Markdown
Member

Resolved by #1565

Thanks for the test case

@Aerendir Aerendir deleted the StringClassNameToClassConstantRector-ignore-array-keys-1539 branch June 5, 2019 14:08
TomasVotruba added a commit that referenced this pull request Dec 20, 2021
rectorphp/rector-src@127ab54 [PHPStan] Clean up PHPStan ignore errors (#1540)
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.

2 participants