Menu

← Back to method.*

Error Identifier: method.unused

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

class UserService
{
	public function getUser(int $id): User
	{
		return $this->findUser($id);
	}

	private function formatName(string $name): string
	{
		return ucfirst($name);
	}

	private function findUser(int $id): User
	{
		// ...
	}
}

Why is it reported? #

A private method is declared but never called anywhere within the class. Since private methods cannot be accessed from outside the class or from child classes, an unused private method is dead code that can be safely removed.

How to fix it #

Remove the unused private method, or start using it if it was intended to be called.

 <?php declare(strict_types = 1);
 
 class UserService
 {
 	public function getUser(int $id): User
 	{
 		return $this->findUser($id);
 	}

-	private function formatName(string $name): string
-	{
-		return ucfirst($name);
-	}
-
 	private function findUser(int $id): User
 	{
 		// ...
 	}
 }

How to ignore this error #

You can use the identifier method.unused to ignore this error using a comment:

// @phpstan-ignore method.unused
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: method.unused

Rules that report this error #

  • PHPStan\Rules\DeadCode\UnusedPrivateMethodRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.