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

fully_qualified_strict_types - conversion from Foo\Bar::class to Bar::class should not happen for imported function #7652

Open
keradus opened this issue Jan 1, 2024 · 11 comments · May be fixed by #7704 or #7705
Labels
kind/bug topic/fqcn Fully Qualified Class Name usage and conversions

Comments

@keradus
Copy link
Member

keradus commented Jan 1, 2024

<?php

use function Symfony\Component\String\u;

echo Symfony\Component\String\u::class;
echo "\n";
echo u::class;

ref symfony/symfony#53233 (comment)

@keradus keradus changed the title convert of 'Foo\Bar' to 'Bar::class' should not happen for imported function fully_qualified_strict_types - convert of 'Foo\Bar' to 'Bar::class' should not happen for imported function Jan 1, 2024
@keradus keradus changed the title fully_qualified_strict_types - convert of 'Foo\Bar' to 'Bar::class' should not happen for imported function fully_qualified_strict_types - convert of Foo\Bar::class to 'Bar::class' should not happen for imported function Jan 1, 2024
@Wirone
Copy link
Member

Wirone commented Jan 6, 2024

@mvorisek how about this one? Will #7679 fix this one too?

@Wirone Wirone added the topic/fqcn Fully Qualified Class Name usage and conversions label Jan 6, 2024
@mvorisek
Copy link
Contributor

mvorisek commented Jan 6, 2024

This seems like a duplicate of #7460, this is not touch by my PR, but easy to fix after.

@keradus
Copy link
Member Author

keradus commented Jan 7, 2024

I'm not sure if it's really a duplicate.

7460 wants to convert \foo\bar(); into bar(); (feature)
while this PR asks to prevent \foo\bar::class into bar::class conversion (bug)

@mvorisek
Copy link
Contributor

mvorisek commented Jan 8, 2024

#7679 solves all classy bugs :)

@keradus
Copy link
Member Author

keradus commented Jan 8, 2024

can you link a test case in your PR that covers \myNs\myFunction::class case described by this issue?

@Wirone
Copy link
Member

Wirone commented Jan 8, 2024

As I think about it, are we even able to distinguish imports for classes and functions if both can use ::class? Currently we import only classy symbols found in several places. We can safely import functions from FQN-based function call, but for ::class we actually don't know the context 😕. The root cause of this issue shows this clearly...

@mvorisek
Copy link
Contributor

mvorisek commented Jan 8, 2024

u::class is basically a refactorable string. It can refer class, it can refer namespace, ... I belive ::class should be always imported as class or do you want to try to guess the context from the surrounding function usage?

@Wirone
Copy link
Member

Wirone commented Jan 8, 2024

I would rather avoid it, because with token-based logic it would be awfully hard probably. However, importing ::class always as class makes this fixer somehow risky... 🤔. But if it's behind an opt-in flag, then we probably can add such information to the option instead of marking whole fixer as such. @keradus what do you think?

@keradus
Copy link
Member Author

keradus commented Jan 9, 2024

I think you folks are wondering of "how to import such ::class usage with use import statement.

This issue is not about it.

This issue is to prevent this conversion:

input

<?php

use function Symfony\Component\String\u;

echo Symfony\Component\String\u::class;

expected output

no change

actual output

<?php

use function Symfony\Component\String\u;

echo u::class;

@kbond

This comment was marked as outdated.

This comment was marked as outdated.

@Wirone Wirone changed the title fully_qualified_strict_types - convert of Foo\Bar::class to 'Bar::class' should not happen for imported function fully_qualified_strict_types - conversion from Foo\Bar::class to Bar::class should not happen for imported function Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug topic/fqcn Fully Qualified Class Name usage and conversions
Projects
None yet
4 participants