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

MissingDependency is reported even if guarded for said dependency #8258

Open
ostrolucky opened this issue Jul 13, 2022 · 7 comments
Open

MissingDependency is reported even if guarded for said dependency #8258

ostrolucky opened this issue Jul 13, 2022 · 7 comments

Comments

@ostrolucky
Copy link
Contributor

https://psalm.dev/r/ba929c576a

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/ba929c576a
<?php

class Bar implements Foo {}

function takesAnInt(): void {
    if (!interface_exists(Foo::class)) {
        return;
    }
    
    new Bar();
}
Psalm output (using commit 6d45003):

ERROR: UndefinedClass - 6:27 - Class, interface or enum named Foo does not exist

INFO: MixedArgument - 6:27 - Argument 1 of interface_exists cannot be mixed, expecting string

ERROR: MissingDependency - 10:9 - Bar depends on class or interface foo that does not exist

ERROR: UndefinedClass - 3:22 - Class, interface or enum named Foo does not exist

@orklah
Copy link
Collaborator

orklah commented Jul 13, 2022

Well, as far as Psalm can know, you guarded against a class that doesn't exists because you made a typo in the name and it's exactly what it wants to warn you about.

Or it could also be a case where it's just an issue with the autoloader provided to Psalm, which you also should be warned about.

I'd just suppress those, it's a pretty niche pattern that'd be hard to handle

@orklah orklah closed this as completed Jul 13, 2022
@AndrolGenhald
Copy link
Collaborator

I do think though that the fact that interface_exists works differently than class_exists should be considered a bug.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/20b3f55d85
<?php

class Bar implements Foo {}

function takesAnInt(): void {
    if (!class_exists(Foo::class)) {
        return;
    }
    
    new Bar();
}
Psalm output (using commit 6d45003):

ERROR: MissingDependency - 10:9 - Bar depends on class or interface foo that does not exist

ERROR: UndefinedClass - 3:22 - Class, interface or enum named Foo does not exist

@orklah orklah reopened this Jul 13, 2022
@orklah
Copy link
Collaborator

orklah commented Jul 13, 2022

I'm fine with that :)

@AndrolGenhald
Copy link
Collaborator

@ostrolucky You also have to conditionally define the class (which is terrible for Psalm's analysis), because otherwise PHP will crash if it's autoloaded whether or not you construct it: https://3v4l.org/XZROZ

Conditionally defining does remove the MissingDependency issue though.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/5aff6f4584
<?php

if (interface_exists(Foo::class)) {
	class Bar implements Foo {}
} else {
    class Bar {}
}

function takesAnInt(): void {
    if (!interface_exists(Foo::class)) {
        return;
    }
    
    new Bar();
}
Psalm output (using commit 6d45003):

ERROR: UndefinedClass - 3:22 - Class, interface or enum named Foo does not exist

INFO: MixedArgument - 3:22 - Argument 1 of interface_exists cannot be mixed, expecting string

ERROR: UndefinedClass - 4:23 - Class, interface or enum named Foo does not exist

ERROR: UndefinedClass - 10:27 - Class, interface or enum named Foo does not exist

INFO: MixedArgument - 10:27 - Argument 1 of interface_exists cannot be mixed, expecting string

blizzz added a commit to nextcloud/collectives that referenced this issue Nov 2, 2023
- psalm issue: vimeo/psalm#8258

Signed-off-by: Arthur Schiwon <[email protected]>
blizzz added a commit to nextcloud/collectives that referenced this issue Nov 2, 2023
- psalm issue: vimeo/psalm#8258

Signed-off-by: Arthur Schiwon <[email protected]>
blizzz added a commit to nextcloud/collectives that referenced this issue Nov 3, 2023
- psalm issue: vimeo/psalm#8258

Signed-off-by: Arthur Schiwon <[email protected]>
mejo- pushed a commit to nextcloud/collectives that referenced this issue Nov 7, 2023
- psalm issue: vimeo/psalm#8258

Signed-off-by: Arthur Schiwon <[email protected]>
mejo- pushed a commit to nextcloud/collectives that referenced this issue Nov 7, 2023
- psalm issue: vimeo/psalm#8258

Signed-off-by: Arthur Schiwon <[email protected]>
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

No branches or pull requests

3 participants