Skip to content

feat(skills): add Yii2 alias resolver for PHP import resolution#495

Open
Maxximus007 wants to merge 1 commit into
Egonex-AI:mainfrom
Maxximus007:feat/yii2-import-resolver
Open

feat(skills): add Yii2 alias resolver for PHP import resolution#495
Maxximus007 wants to merge 1 commit into
Egonex-AI:mainfrom
Maxximus007:feat/yii2-import-resolver

Conversation

@Maxximus007

Copy link
Copy Markdown

Summary

Yii2 Advanced projects configure PSR-4 autoloading via Yii::setAlias() calls in <app>/config/bootstrap.php, not via composer.json's autoload.psr-4 section. The standard extract-import-map.mjs therefore produced an empty import map for these projects, leaving every PHP node as an orphan in the knowledge graph.

Changes

  • New loadYii2Aliases() loader — parses config/bootstrap.php files for Yii::setAlias('@name', dirname(__DIR__)...) calls and derives a namespace-prefix → directory map (e.g. common\common/). Resolves dirname() nesting heuristically (depth 1 → parent, depth 2 → project root). Adds defensive conventional prefixes for standard Yii2 dirs (common, backend, frontend, console, api) when they contain PHP files but aren't explicitly aliased.
  • buildResolutionContext — added loadYii2Aliases as a 4th concurrent loader alongside loadTsConfigs, loadGoModules, loadPhpAutoloads. Warnings drained in canonical order (ts → go → php → yii2).
  • resolvePhpImport — restructured from "return [] on missing composer autoload" to "try composer PSR-4 first, then fall back to Yii2 alias map". The Yii2 fallback uses the same longest-prefix-match logic as the composer resolver.

Verification

Tested on the CostaCabana Yii2 project (948 PHP files):

Metric Before After
Import edges 0 1259
Files with imports 0 517
Orphan nodes 509 321

Sample edges (correct):

  • backend/controllers/ActivityLogController.phpcommon/models/ActivityLog.php
  • backend/controllers/admin/WhatsAppController.phpcommon/models/Booking.php

All 753 existing core tests pass. The composer PSR-4 path still takes priority, so non-Yii2 PHP projects are unaffected.

Limitations

The dirname() resolver is heuristic — it handles the standard Yii2 advanced template pattern (dirname(__DIR__), dirname(dirname(__DIR__)) . '/subdir') but would need extension for exotic path expressions (function calls, variables, complex concatenations). These are rare in standard Yii2 templates.

Generated with Devin

Yii2 Advanced projects configure PSR-4 autoloading via
`Yii::setAlias()` calls in `<app>/config/bootstrap.php`, not via
composer.json's autoload.psr-4 section. The standard extract-import-map
script therefore produced an empty import map for these projects,
leaving every PHP node as an orphan in the knowledge graph.

Add a `loadYii2Aliases()` loader that parses bootstrap.php files for
`Yii::setAlias('@name', dirname(__DIR__)...)` calls and derives a
namespace-prefix → directory map (e.g. `common\` → `common/`). The
resolver runs concurrently with the existing ts/go/php config loaders
and is tried as a fallback in `resolvePhpImport` when the composer
PSR-4 map doesn't match.

On the CostaCabana Yii2 project (948 PHP files), this adds 1259 import
edges that were previously missing, reducing orphan nodes from 509 to
321 (the remaining orphans are non-PHP files).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

1 participant