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

Crash when class uses traits which use other traits and extends a class #1010

Open
6 tasks done
wooky opened this issue Jun 14, 2023 · 1 comment
Open
6 tasks done

Comments

@wooky
Copy link

wooky commented Jun 14, 2023

  • PHPMD version: 2.13.0
  • PHP Version: 8.2.6
  • Installation type: composer
  • Operating System / Distribution & Version: Debian 11 (php docker image)

Current Behavior

When a class both (1) uses two or more traits that they themselves use one common trait, and (2) extends some other class, phpmd is unable to proceed with the message Trait method (xxx) has not been applied, because there are collisions with other trait methods on (yyy).

Expected Behavior

This behavior is valid, and so phpmd should proceed without any problems.

Steps To Reproduce:

Create a file:

<?php

class Unrelated {}

trait Base {
	function foo() {}
}

trait Derived1 {
	use Base;
}

trait Derived2 {
	use Base;
}

class Concrete extends Unrelated {
	use Derived1, Derived2;
}

Run phpmd on it, and get the error Trait method foo has not been applied, because there are collisions with other trait methods on \global\Concrete..

Note that if either the line function foo() {} or extends Unrelated get removed, then phpmd continues with no problems.

Checks before submitting

  • Be sure that there isn't already an issue about this. See: Issues list
  • Be sure that there isn't already a pull request about this. See: Pull requests
  • I have added every step to reproduce the bug.
  • If possible I added relevant code examples.
  • This issue is about 1 bug and nothing more.
  • The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".
wooky added a commit to wooky/SimpleWebApps that referenced this issue Jun 14, 2023
* Temp remove phpmd: phpmd/phpmd#1010
* Add PHP_CodeSniffer
* Add phan
* Fix style issues
@Geolim4
Copy link

Geolim4 commented Mar 18, 2024

Same issue here, a bit blocking atm :(

@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants