Welcome to PHP Builder Generator development! This guide will help you set up your development environment and understand the codebase.
- PHP 8.2 or higher
- Composer 2.0 or higher
- Git
-
Fork and clone the repository:
git clone https://github.com/your-username/php-builder-generator.git cd php-builder-generator -
Install dependencies:
composer install
-
Run tests to verify setup:
composer test
The project includes these development tools:
- PHPUnit: Testing framework
- Twig: Template engine for code generation
php-builder-generator/
├── bin/ # Executable scripts
├── docs/ # Documentation
├── examples/ # Example usage
├── src/ # Main source code
│ ├── Analyzer/ # PHP object analysis
│ ├── Attributes/ # PHP attributes
│ ├── Command/ # CLI commands
│ ├── Configuration/ # Configuration handling
│ ├── Generator/ # Code generation logic
│ ├── Plugin/ # Composer plugin
│ └── Service/ # Builder services
├── templates/ # Twig templates for generation
└── tests/ # Test files
├── Unit/ # Unit tests
├── Integration/ # Integration tests
└── Fixtures/ # Test fixtures
Defines the #[Builder] attribute and its options:
#[Attribute(Attribute::TARGET_CLASS)]
class Builder
{
public function __construct(
public ?string $className = null,
public ?string $namespace = null,
public bool $fluent = true,
// ... other options
) {}
}Parses PHP classes to extract information needed for generation:
ClassParser: Parses class definitionsPropertyParser: Extracts property informationConstructorParser: Handles constructor analysis
Generates builder code:
BuilderGenerator: Main generation orchestratorTemplateRenderer: Handles Twig template renderingFileGenerator: Manages file output
Composer plugin integration:
BuilderGeneratorPlugin: Main plugin classComposerEventSubscriber: Handles composer events
-
Create a feature branch:
git checkout -b feature/your-feature-name
-
Make your changes following the coding standards
-
Add tests for new functionality
-
Run the test suite:
composer test -
Fix code style:
composer cs:fix
-
Run static analysis:
composer analyse
Create unit tests in tests/Unit/ for individual components:
<?php
namespace MaxBeckers\PhpBuilderGenerator\Tests\Unit\Generator;
use MaxBeckers\PhpBuilderGenerator\Generator\BuilderGenerator;
use MaxBeckers\PhpBuilderGenerator\Tests\TestCase;
class BuilderGeneratorTest extends TestCase
{
public function testGeneratesCorrectBuilder(): void
{
// Test implementation
}
}Create integration tests in tests/Integration/ for end-to-end scenarios:
public function testFullGenerationWorkflow(): void
{
$this->generateBuilderFromFixture('UserClass.php');
$this->assertBuilderGenerated('UserBuilder.php');
$this->assertBuilderWorks('UserBuilder');
}-
Update the
Builderattribute:// src/Attributes/Builder.php public function __construct( // ... existing options public bool $newOption = false, ) {}
-
Update the template (
templates/builder.twig):{% if config.newOption %} // New feature code {% endif %} -
Add tests:
public function testNewOptionEnabled(): void { $builder = new Builder(newOption: true); // Test the new functionality }
-
Update documentation in relevant docs files
-
Create template file in
templates/:{# templates/new-feature.twig #} <?php // Generated template content
-
Update the generator to use the new template:
public function generateNewFeature(ClassInfo $class): string { return $this->templateRenderer->render('new-feature.twig', [ 'class' => $class, ]); }
-
Update the command class:
// src/Command/GenerateCommand.php protected function configure(): void { $this->addOption( 'new-option', null, InputOption::VALUE_REQUIRED, 'Description of new option' ); }
-
Handle the option:
protected function execute(InputInterface $input, OutputInterface $output): int { $newOption = $input->getOption('new-option'); // Use the option }
- Familiar syntax for PHP developers
- Good separation of logic and presentation
- Extensible with custom functions/filters
- Good performance with caching
- Automatic integration with existing workflows
- No additional build steps required
- Leverages Composer's autoloading
- Easy installation and configuration
- Native PHP 8+ support
- Better IDE support
- Type safety
- No additional parsing required
- Create descriptive PR title and description
- Reference related issues if applicable
- Include tests for new functionality
- Update documentation as needed
- Ensure CI passes before requesting review
- Tests added for new functionality
- Documentation updated
- Code follows project standards
- No breaking changes (or properly documented)
- Performance considerations addressed
Releases follow semantic versioning:
- Major: Breaking changes
- Minor: New features, backwards compatible
- Patch: Bug fixes, backwards compatible
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Ready to contribute? Check out our open issues!