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

False positive when reusing an internal interface name in userspace #1649

Closed
1 task done
pfrenssen opened this issue Sep 17, 2023 · 3 comments
Closed
1 task done

False positive when reusing an internal interface name in userspace #1649

pfrenssen opened this issue Sep 17, 2023 · 3 comments
Labels
Milestone

Comments

@pfrenssen
Copy link

Bug description

The InternalInterfacesSniff is intended to detect when classes are extending or implementing internal PHP interfaces. For example the following is illegal and should throw an error:

<?php

class MyDateTimeClass implements DateTimeInterface {}

However when a custom interface is created in a namespace that happens to have the same name as an internal interface, then this shouldn't throw an error. This should be allowed:

<?php

use Foo\Bar\DateTimeInterface;

// This doesn't implement an internal interface and shouldn't throw an error.
class MyDateTimeClass implements DateTimeInterface {}

Discovered in the wild in Drupal code: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php?ref_type=heads

Given the following reproduction scenario

Scan the following code:

<?php

use Foo\Bar\DateTimeInterface;

// This doesn't implement an internal interface and shouldn't throw an error.
class MyDateTimeClass implements DateTimeInterface {}

Result:

The interface DateTimeInterface is intended for type hints only and is not implementable or extendable. (PHPCompatibility.Interfaces.InternalInterfaces.datetimeinterfaceFound)

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of PHPCompatibility.
@jrfnl
Copy link
Member

jrfnl commented Sep 17, 2023

@pfrenssen This is a known issue which will be fixed once namespace and use statement tracking and resolution is available in PHPCSUtils.

@jrfnl jrfnl added the bug label Sep 17, 2023
@rdss-sknott
Copy link
Contributor

I wrote an pull request before i found this issue. Linking it for your convenience #1695

rdss-sknott added a commit to rdss-sknott/PHPCompatibility that referenced this issue Apr 8, 2024
…ue (PHPCompatibility#1649)

* Make InternalInterfacesSniff namespace sensitive
* Make NewInterfaceSniff namespace sensitive
rdss-sknott added a commit to rdss-sknott/PHPCompatibility that referenced this issue Apr 22, 2024
rdss-sknott added a commit to rdss-sknott/PHPCompatibility that referenced this issue Apr 22, 2024
rdss-sknott added a commit to rdss-sknott/PHPCompatibility that referenced this issue Apr 22, 2024
rdss-sknott added a commit to rdss-sknott/PHPCompatibility that referenced this issue Apr 22, 2024
…ue (PHPCompatibility#1649)

* Make InternalInterfacesSniff namespace sensitive
* Make NewInterfaceSniff namespace sensitive
jrfnl pushed a commit that referenced this issue Apr 30, 2024
* Adapting namespace sensitivity from pr (#1695) to issue (#1649)

* Make InternalInterfacesSniff namespace sensitive
* Make NewInterfaceSniff namespace sensitive

* Add test cases for imports from internal namespace
@jrfnl jrfnl added this to the 10.0.0 milestone Apr 30, 2024
@jrfnl
Copy link
Member

jrfnl commented Apr 30, 2024

Fixed via #1700

@jrfnl jrfnl closed this as completed Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants