Back to Phpstan

method.deprecatedTrait

website/errors/method.deprecatedTrait.md

2.2.1901 B
Original Source

Code example

php
<?php declare(strict_types = 1);

/** @deprecated Use NewHelper instead */
trait OldHelper
{
	public function help(): void {}
}

class Foo
{
	/** @param OldHelper $x */
	public function doFoo($x): void
	{
		$x->help();
	}
}

Why is it reported?

This error is reported by the phpstan-deprecation-rules extension.

A method is called on a value whose type is a deprecated trait. The trait has been marked with @deprecated, indicating it is scheduled for removal. Calling methods on deprecated trait types means the code depends on functionality that will eventually be removed.

How to fix it

Replace the deprecated trait type with its recommended replacement:

diff-php
 class Foo
 {
-	/** @param OldHelper $x */
+	/** @param NewHelper $x */
 	public function doFoo($x): void
 	{
 		$x->help();
 	}
 }