feat(skills): add Yii2 alias resolver for PHP import resolution#495
Open
Maxximus007 wants to merge 1 commit into
Open
feat(skills): add Yii2 alias resolver for PHP import resolution#495Maxximus007 wants to merge 1 commit into
Maxximus007 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Yii2 Advanced projects configure PSR-4 autoloading via
Yii::setAlias()calls in<app>/config/bootstrap.php, not viacomposer.json'sautoload.psr-4section. The standardextract-import-map.mjstherefore produced an empty import map for these projects, leaving every PHP node as an orphan in the knowledge graph.Changes
loadYii2Aliases()loader — parsesconfig/bootstrap.phpfiles forYii::setAlias('@name', dirname(__DIR__)...)calls and derives a namespace-prefix → directory map (e.g.common\→common/). Resolvesdirname()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— addedloadYii2Aliasesas a 4th concurrent loader alongsideloadTsConfigs,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):
Sample edges (correct):
backend/controllers/ActivityLogController.php→common/models/ActivityLog.phpbackend/controllers/admin/WhatsAppController.php→common/models/Booking.phpAll 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