Extension access to attributes inside a trait #10268
-
Hi, I'd like to detect attributes inside a trait to compare it with a list of forbidden attributes (building a new feature for my disallowed calls extension). I have this PHP file: <?php
declare(strict_types = 1);
namespace Attributes;
#[AttributeClass1]
trait TraitWithAttributes
{
#[AttributeClass2]
private const TRAIT_CONST = true;
#[AttributeClass3]
private $bar;
#[AttributeClass4]
public function traitMethod(
#[AttributeClass5]
bool $param
): void {
}
}
class ClassWithTraitWithAttributes
{
use TraitWithAttributes;
} I'd like my extension to access those attributes inside the trait, but so far I'm failing at that. My public function getNodeType(): string
{
return Node::class;
} and public function processNode(Node $node, Scope $scope): array
{
var_dump($node::class);
return []; to see the nodes that I have access to:
I'm analyzing the file in public function testRule(): void
{
$this->analyse([__DIR__ . '/../src/AttributesEverywhere.php'], [
[
... I can access the trait attribute The closest I got was to use I have tried both the latest 1.10.x, also the 1.11.x-dev versions but the list of nodes is the same. I'm running PHP 8.3.0. I have read https://phpstan.org/blog/how-phpstan-analyses-traits and hopefully understood that correctly. When I analyze the file with phpstan.org/try, it flags the attribute classes as missing (obviously) https://phpstan.org/r/f5928f46-7bae-4c21-b85c-a88cdc66557d so there's seems to be a way but I can't find it. I'm missing something, any hint, or help how can I access those attributes would be appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I figured out the mystery in your repo :) spaze/phpstan-disallowed-calls#226 |
Beta Was this translation helpful? Give feedback.
I figured out the mystery in your repo :) spaze/phpstan-disallowed-calls#226