Skip to content

Commit 6e8e005

Browse files
committed
feat: generate only typed properties and public properties for entity
1 parent 6c20721 commit 6e8e005

File tree

2 files changed

+10
-43
lines changed

2 files changed

+10
-43
lines changed

src/Component/Generator/Definition/CollectionGenerator.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,9 @@ public function generate(Definition $loaderResult): void
2323
}
2424

2525
$phpDoc = '/**
26-
* @method void add(%className% $entity)
27-
* @method void set(string $key, %className% $entity)
28-
* @method %className%[] getIterator()
29-
* @method %className%[] getElements()
30-
* @method %className%|null get(string $key)
31-
* @method %className%|null first()
32-
* @method %className%|null last()
26+
* @extends EntityCollection<%className%>
3327
*/';
3428

35-
36-
3729
$node = $builder
3830
->namespace($loaderResult->namespace)
3931
->addStmt($builder->use(EntityCollection::class))

src/Component/Generator/Definition/EntityGenerator.php

+9-34
Original file line numberDiff line numberDiff line change
@@ -66,47 +66,22 @@ public function generate(Definition $definition): void
6666
continue;
6767
}
6868

69-
$type = TypeMapping::mapToPhpType($field, true, $definition);
70-
71-
$class->stmts[] = $builder->property($field->getPropertyName())->makeProtected()->setDocComment('/** @var ' . $type . ' */')->getNode();
72-
}
73-
74-
/** @var Field $field */
75-
foreach ($definition->fields as $field) {
76-
if ($field->name === IdField::class) {
77-
continue;
78-
}
79-
80-
$setterMethodName = 'set' . ucfirst($field->getPropertyName());
81-
$getterMethodName = 'get' . ucfirst($field->getPropertyName());
82-
83-
if ($this->hasMethod($classMethods, $setterMethodName) || $this->hasMethod($classMethods, $getterMethodName)) {
84-
continue;
85-
}
86-
8769
$type = TypeMapping::mapToPhpType($field, false, $definition);
88-
8970
if ($field->isNullable()) {
9071
$type = '?' . $type;
9172
}
9273

93-
$method = new ClassMethod(new Identifier($setterMethodName));
94-
$method->flags = Class_::MODIFIER_PUBLIC;
95-
$method->returnType = new Identifier('void');
96-
$method->params = [new Param(new Name('$value'), null, new Name($type))];
97-
98-
$var = new PropertyFetch(new Variable('this'), new Name($field->getPropertyName()));
99-
$method->stmts[] = new Expression(new Assign($var, new Variable('value')));
74+
$node = $builder
75+
->property($field->getPropertyName())
76+
->setType($type)
77+
->makePublic();
10078

101-
$class->stmts[] = $method;
102-
103-
$method = new ClassMethod(new Identifier($getterMethodName));
104-
$method->flags = Class_::MODIFIER_PUBLIC;
105-
$method->returnType = new Identifier($type);
106-
107-
$method->stmts[] = new Return_($var);
79+
if ($field->isNullable()) {
80+
$node = $node->setDefault(null);
81+
}
10882

109-
$class->stmts[] = $method;
83+
$class->stmts[] = $node
84+
->getNode();
11085
}
11186

11287
$printer = new Standard();

0 commit comments

Comments
 (0)