Repository navigation
Description
Version: graphify 0.9.28 · Python 3.10 · macOS · --code-only
A class whose name is a strict prefix of other class names in the same project loses all of its inbound imports edges. affected then reports No affected nodes found for a class that is imported by several files.
This looks related to the namespace/use-aware PHP resolution pass added in 0.9.17 for #1923.
Minimal reproduction
Five files, graphify extract . --code-only --force.
Case A — works. Pivot plus two importers:
// src/Pivot.php
<?php
namespace App\Entities;
class Pivot { public $id; }// src/ModelWithRelation.php
<?php
namespace App\Models;
use App\Entities\Pivot;
class ModelWithRelation
{
public function rows() { return $this->hasMany(Pivot::class, 'model_id'); }
}// src/ServiceWithTypeHint.php
<?php
namespace App\Services;
use App\Entities\Pivot;
class ServiceWithTypeHint
{
public function __construct(Pivot $pivot) { $this->pivot = $pivot; }
}$ graphify affected "Pivot" --depth 2
- ModelWithRelation.php [imports] src/ModelWithRelation.php:L4
- ServiceWithTypeHint.php [imports] src/ServiceWithTypeHint.php:L4
- .__construct() [references] src/ServiceWithTypeHint.php:L9
$ graphify explain "Pivot"
Degree: 4Case B — broken. Same Pivot, same importer, but add three siblings whose names begin with Pivot:
// src/PivotRepository.php
<?php
namespace App\Repositories;
interface PivotRepository {}// src/PivotRepositoryEloquent.php
<?php
namespace App\Repositories;
use App\Entities\Pivot;
class PivotRepositoryEloquent implements PivotRepository
{
public function model() { return Pivot::class; }
}// src/PivotValidator.php
<?php
namespace App\Validators;
class PivotValidator {}// src/ModelWithRelation.php (unchanged)
<?php
namespace App\Models;
use App\Entities\Pivot;
class ModelWithRelation
{
public function rows() { return $this->hasMany(Pivot::class, 'model_id'); }
}$ graphify affected "Pivot" --depth 2
No affected nodes found.
$ graphify explain "Pivot"
Degree: 1
<-- Pivot.php [contains] src/Pivot.php:L3Both use App\Entities\Pivot; statements are gone from the graph. The only surviving edge is the file's own contains. Adding the prefix-siblings is the single change between A and B.
Real-world impact
Hit this on a Laravel 8 codebase (~4.4k nodes). App\Entities\ConciliacionesBanorteFacturas is imported by four files, and coexists with ConciliacionesBanorteFacturasRepository, ConciliacionesBanorteFacturasRepositoryEloquent and ConciliacionesBanorteFacturasValidator — the exact shape above, which prettus/l5-repository generates for every entity, so any Laravel project using that package is affected across its whole data layer.
The importing file still emits its other imports, so the loss is silent and per-target:
app_models_conciliacionbanorte --imports--> app_entities_cliente ✅
app_models_conciliacionbanorte --imports--> app_entities_complementospagos ✅
app_models_conciliacionbanorte --imports--> app_models_bkcomplementopago ✅
(no edge) app_entities_conciliacionesbanortefacturas ❌
The practical danger is that affected returns an empty result rather than an error, which reads as "nothing depends on this" when the honest answer is "unknown" — the failure mode most likely to green-light a bad refactor. It also under-ranks these classes in god-nodes.
Secondary observation
Independently of the above, in Case A the method .rows() never appears: a class referenced as X::class inside a method body produces no method-level references edge, while the same class in a constructor signature does. Only the file-level import survives.
That pattern is how every Eloquent relationship is declared — hasMany, belongsTo, morphMany, morphTo — so in ORM-heavy code the densest part of the real dependency graph is the least represented. Happy to split this into its own issue if you prefer.
Expected
- A
useimport always produces an edge, regardless of whether other classes share its name as a prefix. - If resolution genuinely cannot determine a target, that is reported rather than dropped silently.
Glad to test a patch — the project above is a decent stress case at ~4.4k nodes with heavy Eloquent and prettus/l5-repository usage.
Activity
safishamsi commentedon Aug 12, 2026
Fixed in v0.9.41 (
graphifyy==0.9.41on PyPI). A PHPuseimport written with a leading backslash / fully-qualified prefix now resolves to its target definition (and does not mis-bind to a same-prefixed sibling class). Thanks @ousamabenyounes (PR #2661).alejandro-vargas-m commentedon Aug 12, 2026
Thanks for the quick turnaround — confirmed the prefix-sibling fix works. Verified 0.9.41 against the real project (~4.4k nodes):
affected "ConciliacionesBanorteFacturas"went fromNo affected nodes foundto correctly listing the files that import it. It also works for plainuse App\Entities\Pivot;without a leading backslash, which is a bit broader than the closing note suggested.The secondary observation from the original report is still open, and having now measured it I think it's worth its own tracking — happy to file separately if you'd rather, just say the word.
A class referenced as
X::classinside a method body produces no edge when the file has nousefor it.Two files,
graphify extract . --code-only --forceon 0.9.41:SinUse.phpnever appears, though both files referencePivotidentically. The edge tracks theusestatement, not the actual reference.Why this is load-bearing for PHP. Two very common shapes have no
useto key off:useis redundant (linters flag it as unnecessary);\App\Entities\Pivot::class.Measured on the real project with 0.9.41 — of 240 Eloquent relationships declared in
app/(hasMany,belongsTo,morphMany,morphTo, …), 158 (65%) still produce no edge. Only the 82 that happen to carry auseare linked:Since
Model::classinside a method body is how Eloquent declares every relationship, the ORM layer — the densest part of the real dependency graph — stays largely invisible.affectedon an Entity still returns an empty result that reads as "nothing depends on this" rather than "unknown".Adding redundant
usestatements does make the edges appear, but that means editing production code to satisfy the extractor, and any IDE "optimize imports" pass silently reverts it — so it trades a consistent gap for an intermittent one.Expected:
X::classinside a method body resolves against the current namespace (and anyusealiases) and produces areferencesedge from the enclosing method, the same way a constructor type hint already does.Glad to test a patch on the real project — heavy Eloquent plus
prettus/l5-repository, so it exercises both shapes.