Menu

← Back to phpstan.*

Error Identifier: phpstan.traitNotFound

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);

namespace App\Tests;

trait MyTestHelperTrait
{
	public function helper(): void
	{
		// ...
	}
}

Why is it reported? #

PHPStan found a trait definition in the analysed code, but the trait is not registered in the reflection provider. This typically happens when test traits are not autoloaded because the autoload-dev section in composer.json does not include the directory containing the trait.

This error is not ignorable because PHPStan cannot analyse code that uses a trait it cannot find.

How to fix it #

Configure the autoload-dev section in composer.json to include the directory where the test files are located:

 {
     "autoload-dev": {
         "psr-4": {
-            "App\\Tests\\": "tests/"
+            "App\\Tests\\": "tests/",
+            "App\\Tests\\Helpers\\": "tests/Helpers/"
         }
     }
 }

After updating composer.json, run composer dump-autoload to regenerate the autoloader.

Non-ignorable error #

This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.

Rules that report this error #

  • PHPStan\Testing\NonexistentAnalysedTraitRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.