Skip to content

fix(php): capture interface/enum/trait heritage as class-like nodes#1791

Open
Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/php-interface-enum-heritage
Open

fix(php): capture interface/enum/trait heritage as class-like nodes#1791
Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/php-interface-enum-heritage

Conversation

@Synvoya

@Synvoya Synvoya commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Bug

PHP interfaces, enums, and traits produce no node and no heritage edges. interface B extends A, enum E implements I, and trait T { use U; } are all silently dropped.

Root cause

_PHP_CONFIG.class_types only contained class_declaration, so the generic extractor never treated interface_declaration, enum_declaration, or trait_declaration nodes as class-like. They never became nodes, and the PHP heritage handler (which runs per class-like node) never fired for them.

Minimal repro

<?php
interface Identifiable {}
interface Nameable extends Identifiable {}
enum Suit: string implements Nameable {
    case Hearts = 'H';
    public function label(): string { return 'x'; }
}
trait Named {}
trait Greets { use Named; }

Before: no Nameable/Suit/Greets nodes, no inherits/implements/mixes_in edges.

Fix

  • Add interface_declaration, enum_declaration, and trait_declaration to _PHP_CONFIG.class_types.
  • Enums wrap members in an enum_declaration_list (not a declaration_list), so add it to body_fallback_child_types so enum methods/cases are walked.

After the fix the repro yields:

  • Nameable --inherits--> Identifiable
  • Suit --implements--> Nameable
  • Greets --mixes_in--> Named
  • Suit --method--> label (enum body now walked)

Testing

  • Added test_php_interface_enum_trait_heritage to tests/test_languages.py, mirroring the existing test_php_splits_inherits_implements_mixes_in assertion style. Fails before, passes after.
  • tests/test_languages.py: 315 passed, 13 skipped (was 314 + this new test).

Only class_declaration was registered as a PHP class type, so interface,
enum, and trait declarations produced no node and their heritage edges
(interface extends -> inherits, enum implements -> implements, trait use
-> mixes_in) were dropped entirely.

Add interface_declaration, enum_declaration, and trait_declaration to the
PHP class_types. Enums wrap their members in an enum_declaration_list
rather than a declaration_list, so also add it to body_fallback_child_types
so enum methods/cases get walked.

Adds a regression test covering interface extends, enum implements, trait
use, and an enum-body method.
@Lautaroscu

Copy link
Copy Markdown

good job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants