← All results

@phpstan-require-extends on a trait

Group: Advanced PHPDoc types · Category: ecosystem · File: phpdoc_advanced_phpstan_require_extends_trait.php

PHPStan documents the tag on interfaces *and* traits. The interface form is phpdoc_advanced_phpstan_require_extends; this file measures the trait form, which is also Psalm's native @psalm-require-extends shape. References: - PHPStan phpdocs-basics: Enforcing class inheritance for interfaces and traits

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.11Phan 6.0.11 php-ast version 1.1.3 PHP version used to run Phan: 8.5.12 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
phpstan 2.3.7PHPStan - PHP Static Analysis Tool 2.3.7 Enforced reported Lv.2+
phpdoc_advanced_phpstan_require_extends_trait.php:30: Trait Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\NeedsParent requires using class to extend Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\RequiredParent, but Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\BadUser does not. [reported-from-level=2]
With strict-rules
phpdoc_advanced_phpstan_require_extends_trait.php:30: Trait Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\NeedsParent requires using class to extend Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\RequiredParent, but Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\BadUser does not.
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
phpstan-strict 2.3.7PHPStan - PHP Static Analysis Tool 2.3.7 Enforced
phpdoc_advanced_phpstan_require_extends_trait.php:30: Trait Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\NeedsParent requires using class to extend Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\RequiredParent, but Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\BadUser does not.
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
psalm 6.21.4Psalm 6.21.4@72023213487628df0bc5b2e02d68cbac614b7ef5 Enforced (pzoom≠)
phpdoc_advanced_phpstan_require_extends_trait.php:32: Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\NeedsParent requires using class to extend Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\RequiredParent, but Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\BadUser does not [ExtensionRequirementViolation]
pzoom (Psalm port)

No diagnostics from pzoom.

  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
psalm 7 7.21.0Psalm 7.21.0@1a665f0114bd40cf12ad57a1a82066549d92f1b6 Enforced
phpdoc_advanced_phpstan_require_extends_trait.php:32: Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\NeedsParent requires using class to extend Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\RequiredParent, but Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\BadUser does not [ExtensionRequirementViolation]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
mago 1.61.0mago 1.61.0 Not enforced ⚠ 1 false positive
phpdoc_advanced_phpstan_require_extends_trait.php:31: Class `Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\BadUser` must extend required class `conformance\tests\phpdocadvancedphpstanrequireextendstrait\requiredparent` [missing-required-parent]
  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
  • False positives: line(s) 31
Expectation diff
Line 31: Unexpected errors ["Class `Conformance\\Tests\\PhpdocAdvancedPhpstanRequireExtendsTrait\\BadUser` must extend required class `conformance\\tests\\phpdocadvancedphpstanrequireextendstrait\\requiredparent` [missing-required-parent]"]
mir 0.101.0mir 0.101.0 Enforced
phpdoc_advanced_phpstan_require_extends_trait.php:32: InvalidTraitUse: Trait NeedsParent used incorrectly: Class Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\BadUser uses trait NeedsParent but does not extend Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\RequiredParent [MIR1300]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
phpantom 1.1.0phpantom_lsp 1.1.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
pun 0.4.3pun 0.4.3 Enforced
phpdoc_advanced_phpstan_require_extends_trait.php:30: Trait Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\NeedsParent requires using class to extend Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\RequiredParent, but Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\BadUser does not. [class.missingExtends]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
intelephense 1.18.5intelephense 1.18.5 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
phpactor 2026.11.22.0Phpactor 2026.11.22.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
phpy 1.0.19566phpy 1.0.19566 Enforced
phpdoc_advanced_phpstan_require_extends_trait.php:32: trait Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\NeedsParent expects Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait\RequiredParent as a parent class.
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
qodana 263.7307.215PhpStorm 263.7307.215 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
steins 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedPhpstanRequireExtendsTrait;

/**
 * Cross-tool handling of `@phpstan-require-extends` on a trait.
 *
 * PHPStan documents the tag on interfaces *and* traits. The interface form
 * is `phpdoc_advanced_phpstan_require_extends`; this file measures the trait
 * form, which is also Psalm's native `@psalm-require-extends` shape.
 *
 * References:
 * - PHPStan phpdocs-basics: Enforcing class inheritance for interfaces and traits
 */

class RequiredParent
{
}

/**
 * @phpstan-require-extends RequiredParent
 */
trait NeedsParent // T: @phpstan-require-extends
{
}

// Missing the required extends (diagnostic may land on the class or the use).
final class BadUser // E?[req]: using class must extend RequiredParent
{
    use NeedsParent; // E?[req]: using class must extend RequiredParent
}

// Satisfies the requirement.
final class GoodUser extends RequiredParent // V
{
    use NeedsParent;
}