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 on private trait method #3637

Closed
jacekkarczmarczyk opened this issue Jul 20, 2020 · 4 comments
Closed

false positive on private trait method #3637

jacekkarczmarczyk opened this issue Jul 20, 2020 · 4 comments

Comments

@jacekkarczmarczyk
Copy link

jacekkarczmarczyk commented Jul 20, 2020

Bug report

phpstan: 0.12.33, bleeding edge

If a private trait method is not used in some class phpstan raises a warning that the method is not used even if it's used in other class

Code snippet that reproduces the problem

https://phpstan.org/r/72f07c19-65b2-4ab6-a12b-d42cd37cd60f

<?php declare(strict_types = 1);

trait Foo {
	private function bar(): void {} // Method Namaste::bar() is unused.
	private function baz(): void {} // Method HelloWorld::bar() is unused.
}

class HelloWorld
{
	use Foo;
	
	public function hello(): void {
		$this->bar();
	}
}

class Namaste
{
	use Foo;
	
	public function hello(): void {
		$this->baz();
	}
}

Expected output

no error

@enumag
Copy link
Contributor

enumag commented Jul 22, 2020

Yeah, it doesn't really make sense to report unused trait methods and properties in the context of each class they're used. However it would make sense to report them without class context if they aren't used in ANY class that uses the trait.

@ondrejmirtes
Copy link
Member

However it would make sense to report them without class context if they aren't used in ANY class that uses the trait.

This is hard as it has to work with parallelized processing.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@5958c29

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants