Welcome to PHP Builder Generator development! This guide will help you set up your development environment and understand the codebase.
git clone https://github.com/your-username/php-builder-generator.git
cd php-builder-generator
composer install
composer test
The project includes these development tools:
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
src/Attributes/
)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
) {}
}
src/Parser/
)Parses PHP classes to extract information needed for generation:
ClassParser
: Parses class definitionsPropertyParser
: Extracts property informationConstructorParser
: Handles constructor analysissrc/Generator/
)Generates builder code:
BuilderGenerator
: Main generation orchestratorTemplateRenderer
: Handles Twig template renderingFileGenerator
: Manages file outputsrc/Plugin/
)Composer plugin integration:
BuilderGeneratorPlugin
: Main plugin classComposerEventSubscriber
: Handles composer eventsgit checkout -b feature/your-feature-name
Make your changes following the coding standards
Add tests for new functionality
composer test
composer cs:fix
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');
}
Builder
attribute:
// src/Attributes/Builder.php
public function __construct(
// ... existing options
public bool $newOption = false,
) {}
templates/builder.twig
):
public function testNewOptionEnabled(): void
{
$builder = new Builder(newOption: true);
// Test the new functionality
}
templates/
:
{# templates/new-feature.twig #}
<?php
// Generated template content
public function generateNewFeature(ClassInfo $class): string
{
return $this->templateRenderer->render('new-feature.twig', [
'class' => $class,
]);
}
// src/Command/GenerateCommand.php
protected function configure(): void
{
$this->addOption(
'new-option',
null,
InputOption::VALUE_REQUIRED,
'Description of new option'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$newOption = $input->getOption('new-option');
// Use the option
}
Releases follow semantic versioning:
Ready to contribute? Check out our open issues!