diff --git a/src/Instrument/Transformer/SelfValueVisitor.php b/src/Instrument/Transformer/SelfValueVisitor.php index 5a764b1a..187c190d 100644 --- a/src/Instrument/Transformer/SelfValueVisitor.php +++ b/src/Instrument/Transformer/SelfValueVisitor.php @@ -89,10 +89,6 @@ public function enterNode(Node $node) { if ($node instanceof Namespace_) { $this->namespace = !empty($node->name) ? $node->name->toString() : null; - } elseif ($node instanceof Class_) { - if ($node->name !== null) { - $this->className = new Name($node->name->toString()); - } } elseif ($node instanceof ClassMethod || $node instanceof Closure) { if (isset($node->returnType)) { $node->returnType = $this->resolveType($node->returnType); @@ -115,7 +111,11 @@ public function enterNode(Node $node) $type = $this->resolveClassName($type); } } elseif ($node instanceof ClassLike) { - $this->isInsideTraitOrEnum = $node instanceof Trait_ || $node instanceof Enum_; + if (! $node instanceof Trait_) { + $this->className = new Name($node->name->toString()); + } else { + $this->className = null; + } } return null; @@ -135,7 +135,7 @@ protected function resolveClassName(Name $name): Name return $name; } - if ($this->isInsideTraitOrEnum) { + if ($this->className === null) { return $name; } diff --git a/tests/Go/Instrument/Transformer/_files/php81-file-transformed.php b/tests/Go/Instrument/Transformer/_files/php81-file-transformed.php index b0809015..3d75adec 100644 --- a/tests/Go/Instrument/Transformer/_files/php81-file-transformed.php +++ b/tests/Go/Instrument/Transformer/_files/php81-file-transformed.php @@ -55,11 +55,11 @@ public function label(): string { return static::getLabel($this); } - public static function getLabel(self $value): string { + public static function getLabel(\Go\ParserReflection\Stub\BackedPhp81EnumHTTPStatusWithMethod $value): string { return match ($value) { - self::OK => 'OK', - self::ACCESS_DENIED => 'Access Denied', - self::NOT_FOUND => 'Page Not Found', + \Go\ParserReflection\Stub\BackedPhp81EnumHTTPStatusWithMethod::OK => 'OK', + \Go\ParserReflection\Stub\BackedPhp81EnumHTTPStatusWithMethod::ACCESS_DENIED => 'Access Denied', + \Go\ParserReflection\Stub\BackedPhp81EnumHTTPStatusWithMethod::NOT_FOUND => 'Page Not Found', }; } }