gossi/php-code-generator
A lightweight PHP library for generating PHP code programmatically. Build classes, methods, properties, namespaces, and docblocks through a fluent API, then render valid source files for scaffolding, code generation, and automation workflows.
This package generates PHP classes (models, controllers, etc.) from configuration, and v0.6-beta.1 adds a profile option and experimental code formatting via gossi/php-code-formatter. Start by publishing the config (php artisan vendor:publish) and reviewing config/code-generator.php for CodeGeneratorConfig options. The first use case is scaffolding a CRUD resource: define your table or schema, run the generator command, and inspect the generated files. Look first at the profile option—it lets you switch between formatting presets—and set enableFormatting to true only if you’re comfortable with experimental output. For existing projects, verify that generated interfaces now carry proper FQCNs (fixed in this release) and that traits are no longer forced into first position.
profile option to maintain separate formatting styles per project or per generator run. Combine it with enableFormatting for automatic PSR-12-ish cleanup, but treat it as a post-processing step—review diffs before committing.--output=tmp/generated), run your test suite or static analysis, then move files into place. This catches the “traits in first position” and FQCN issues early.profile option to match your team’s code style (e.g., “laravel” vs “psr12”).use statements.enableFormatting flag is a quick win, but for production pipelines prefer your own pint/php-cs-fixer step to avoid depending on an experimental feature.PhpFunction is deprecated: If your custom templates or config reference PhpFunction, migrate to the recommended replacement (check issue #35). Deprecation warnings may appear in logs; silence them only after migrating.enableFormatting uses gossi/php-code-formatter and is marked “very experimental.” Test on a branch—formatting may alter generated code in unexpected ways (e.g., line breaks in long signatures). Keep a backup or use version control.profile option is new; ensure your config file is republished or merged. If you use config caching (php artisan config:cache), clear it after upgrading.use statements, remove those workarounds to avoid duplicates.--verbose (if available) or inspect the intermediate representation before formatting. The formatter runs after generation, so syntax errors in your definitions will still surface before formatting.composer.json and avoid using it in critical production generators until the formatting feature stabilises.How can I help you explore Laravel packages today?