Skip to content

Commit 55132e4

Browse files
committed
optimize builder attribute
1 parent a7fba04 commit 55132e4

5 files changed

Lines changed: 0 additions & 52 deletions

File tree

docs/features/configuration.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ The `#[Builder]` attribute provides fine-grained control over individual builder
105105
className: 'CustomUserBuilder',
106106
namespace: 'App\\Builders',
107107
fluent: true,
108-
generateFactory: false,
109108
exclude: ['password'],
110109
include: ['name', 'email'],
111-
immutable: false,
112110
builderMethod: 'create'
113111
)]
114112
class User { ... }
@@ -121,10 +119,8 @@ class User { ... }
121119
| `className` | `?string` | `null` | Custom name for the generated builder class |
122120
| `namespace` | `?string` | `null` | Custom namespace for the generated builder |
123121
| `fluent` | `bool` | `true` | Whether setter methods should return `self` for chaining |
124-
| `generateFactory` | `bool` | `false` | Generate an additional factory class |
125122
| `exclude` | `array` | `[]` | Property names to exclude from the builder |
126123
| `include` | `array` | `[]` | Only include these properties (if set, overrides exclude) |
127-
| `immutable` | `bool` | `false` | Whether to treat the target class as immutable |
128124
| `builderMethod` | `string` | `'builder'` | Name of the static factory method |
129125

130126
## Advanced Configuration Examples
@@ -203,19 +199,6 @@ $user = UserBuilder::create() // Instead of ::builder()
203199
->build();
204200
```
205201

206-
### Immutable Objects
207-
208-
```php
209-
#[Builder(immutable: true)]
210-
class Money
211-
{
212-
public function __construct(
213-
public readonly int $amount,
214-
public readonly string $currency
215-
) {}
216-
}
217-
```
218-
219202
## Generator-Specific Configuration
220203

221204
The `generator-config` section allows for future extensibility:

docs/getting-started/quick-start.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,4 @@ class Email
126126
}
127127
```
128128

129-
### Immutable Object
130-
```php
131-
#[Builder(immutable: true)]
132-
class Money
133-
{
134-
public function __construct(
135-
public readonly int $amount,
136-
public readonly string $currency
137-
) {}
138-
}
139-
```
140-
141129
Ready to dive deeper? Check out our [configuration guide](../features/configuration.md)!

src/Attribute/Builder.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ public function __construct(
1313
public ?string $className = null,
1414
public ?string $namespace = null,
1515
public bool $fluent = true,
16-
public bool $generateFactory = false,
1716
public array $exclude = [],
1817
public array $include = [],
19-
public bool $immutable = false,
2018
public string $builderMethod = 'builder'
2119
) {
2220
}

src/Generator/BuilderGenerator.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function generate(GenerationContext $context): array
6262

6363
$results = [];
6464

65-
// Generate main builder
6665
$builderCode = $this->templateEngine->render('builder.php.twig', $templateContext);
6766
$results[] = [
6867
'type' => 'builder',
@@ -71,20 +70,6 @@ public function generate(GenerationContext $context): array
7170
'path' => $this->getOutputPath($context, $builderClassName, $builderNamespace)
7271
];
7372

74-
// Generate factory if requested
75-
if ($builderAttribute->generateFactory) {
76-
$factoryClassName = $builderClassName . 'Factory';
77-
$templateContext['factory_class_name'] = $factoryClassName;
78-
79-
$factoryCode = $this->templateEngine->render('factory.php.twig', $templateContext);
80-
$results[] = [
81-
'type' => 'factory',
82-
'class_name' => $factoryClassName,
83-
'content' => $factoryCode,
84-
'path' => $this->getOutputPath($context, $factoryClassName, $builderNamespace)
85-
];
86-
}
87-
8873
return $results;
8974
}
9075

tests/Unit/Attribute/BuilderTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ public function testBuilderAttributeWithDefaults(): void
1616
$this->assertNull($builder->className);
1717
$this->assertNull($builder->namespace);
1818
$this->assertTrue($builder->fluent);
19-
$this->assertFalse($builder->generateFactory);
2019
$this->assertEquals([], $builder->exclude);
2120
$this->assertEquals([], $builder->include);
22-
$this->assertFalse($builder->immutable);
2321
$this->assertEquals('builder', $builder->builderMethod);
2422
}
2523

@@ -29,20 +27,16 @@ public function testBuilderAttributeWithCustomValues(): void
2927
className: 'CustomBuilder',
3028
namespace: 'Custom\\Namespace',
3129
fluent: false,
32-
generateFactory: true,
3330
exclude: ['password'],
3431
include: ['name', 'email'],
35-
immutable: true,
3632
builderMethod: 'builder'
3733
);
3834

3935
$this->assertEquals('CustomBuilder', $builder->className);
4036
$this->assertEquals('Custom\\Namespace', $builder->namespace);
4137
$this->assertFalse($builder->fluent);
42-
$this->assertTrue($builder->generateFactory);
4338
$this->assertEquals(['password'], $builder->exclude);
4439
$this->assertEquals(['name', 'email'], $builder->include);
45-
$this->assertTrue($builder->immutable);
4640
$this->assertEquals('builder', $builder->builderMethod);
4741
}
4842
}

0 commit comments

Comments
 (0)