Skip to content

PHP extractor misses class_constant_access_expression (enum and constant references) #230

Closed

Description

@erhanurgun

Summary

The PHP extractor wires up function_call_expression and member_call_expression into calls edges, but it never visits class_constant_access_expression. That means references to enums and class constants do not produce any graph edges, so constant-heavy codebases show up in graph analyses as isolated nodes that look like dead code.

Current behavior

Minimal reproducer:

<?php

namespace App\Support;

class TimeConstant
{
    public const int HOUR_IN_SECONDS = 3600;
}

class CacheService
{
    public function ttl(): int
    {
        return TimeConstant::HOUR_IN_SECONDS;
    }
}

Running extract_php() on this file returns two classes (TimeConstant, CacheService), one method (.ttl()), the contains and method edges. No edge connects CacheService to TimeConstant, even though the method body uses it.

This is reproducible on any project that follows the Laravel convention of extracting magic numbers into enum-like classes, but it also hits any project that uses native enum Foo { case Bar; } syntax because enum case access goes through the same grammar node.

Expected behavior

The method should be linked to the class that holds the constant, with a relation label that makes the intent clear (for example uses_const). The existing calls relation is reserved for callable invocations, so a new relation label keeps the graph semantically honest.

Proposed solution

Extend LanguageConfig with an optional static_const_types frozenset (default empty, so other languages are untouched) and populate it in _PHP_CONFIG with class_constant_access_expression. In the walk_calls dispatcher, handle the new node type by reading its class reference (via the scope field with a positional fallback, since tree-sitter-php has exposed the child under different field names across versions) and adding a uses_const edge when the enclosing class resolves in label_to_nid.

The change stays additive. Languages that do not set static_const_types see no behavioral difference.

Notes

I am happy to open a PR (one is already prepared with tests). I also have follow-up ideas for scoped_call_expression and scoped_property_access_expression that have the same root cause and can be addressed independently.

Activity

  1. safishamsi commented on Apr 14, 2026

    @safishamsi
    Member

    Implemented in v0.4.14.

    pip install --upgrade graphifyy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions