Skip to content

Commit 42698d1

Browse files
committed
Don't call parent::__construct when not needed
1 parent 44cc80a commit 42698d1

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/SchemaOrgModel/TypesGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function generate($config)
110110
'fields' => [],
111111
'uses' => [],
112112
'hasConstructor' => false,
113+
'parentHasConstructor' => false,
113114
'hasChild' => false,
114115
'abstract' => false,
115116
];
@@ -280,6 +281,7 @@ public function generate($config)
280281
foreach ($classes as &$class) {
281282
if ($class['parent'] && isset($classes[$class['parent']])) {
282283
$classes[$class['parent']]['hasChild'] = true;
284+
$class['parentHasConstructor'] = $classes[$class['parent']]['hasConstructor'];
283285
}
284286

285287
foreach ($class['fields'] as &$field) {

templates/class.php.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ use {{ use }};
4343
{% if config.doctrine.useCollection and class.hasConstructor %}
4444
public function __construct()
4545
{
46+
{% if class.parentHasConstructor %}
4647
parent::__construct();
4748
49+
{% endif %}
4850
{% for field in class.fields %}
4951
{% if config.doctrine.useCollection and field.isArray and field.typeHint and not field.isEnum %}
5052
$this->{{ field.name }} = new ArrayCollection();

0 commit comments

Comments
 (0)