Skip to content

Add config generator for discovering autowire-eligible classes - #78

Draft
Firehed wants to merge 6 commits into
mainfrom
77/config-generator
Draft

Add config generator for discovering autowire-eligible classes#78
Firehed wants to merge 6 commits into
mainfrom
77/config-generator

Conversation

@Firehed

Copy link
Copy Markdown
Owner

Summary

  • Adds ConfigGenerator service that scans directories for classes with autowire-compatible constructors
  • Includes CLI tool (bin/generate-config) for easy command-line usage
  • Uses composer/class-map-generator for class discovery (added as dev dependency and in suggest)

Usage

CLI:

vendor/bin/generate-config src/Services src/Repositories
vendor/bin/generate-config -o config/autowired.php src/
vendor/bin/generate-config -e config/manual.php -o config/autowired.php src/

Programmatic:

$generator = newConfigGenerator();
$generator->addDirectory('src/Services');
$generator->excludeFromFile('config/manual.php');
file_put_contents('config/autowired.php', $generator->generate());

Eligibility criteria

A class is considered autowire-eligible if:

  • Concrete class (not abstract/interface/trait/enum)
  • Public constructor (or no constructor)
  • All required params typed with non-builtin types
  • No Closure or Generator typed params

Closes#77

Test plan

  • Unit tests for ConfigGenerator
  • Manual testing of CLI tool
  • Test on a real project

🤖 Generated with Claude Code

@codecov

codecovBot commented Mar 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.60870% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.05%. Comparing base (029055c) to head (94576b5).
⚠️ Report is 1 commits behind head on main.

Files with missing linesPatch %Lines
src/ConfigGenerator.php82.60%8 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #78 +/- ##
============================================
+ Coverage 82.00% 82.05% +0.04% - Complexity 207 225 +18 
============================================
Files 27 28 +1 Lines 617 663 +46 ============================================
+ Hits 506 544 +38 - Misses 111 119 +8 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Firehedand others added 3 commits March 14, 2026 10:14
Introduces a ConfigGenerator service that scans directories for classes
with autowire-compatible constructors and generates container config files.
Includes a CLI tool (bin/generate-config) for easy use. Requires
composer/class-map-generator which is added as a dev dependency and
listed in suggest for production use.
Closes#77
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
These internal PHP types cannot meaningfully be registered in a
container, so classes requiring them as constructor parameters
should not be considered autowire-eligible.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Simplify ConfigGenerator by delegating to Autowire::isEligible()
instead of duplicating the eligibility logic.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Firehed
Firehedforce-pushed the 77/config-generator branch from 41581c2 to 85389d6CompareMarch 14, 2026 17:16
Firehedand others added 3 commits March 14, 2026 10:25
When checking autowire eligibility, some classes may fail to load due to
side effects or broken dependencies at include-time. Instead of crashing,
we now catch these errors and collect them for reporting.
The CLI displays warnings for any classes that couldn't be checked,
showing the class name and error message.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Suppress PHP warnings/deprecations during class scanning
- Include file path in error output for easier debugging
- Move error output to end so it's more visible after the generated config
Sign up for freeto 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.

Add a config generator

1 participant

@Firehed