From 42698d1dccef53af77b60372c872862537346359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 6 Mar 2015 15:23:55 +0100 Subject: [PATCH] Don't call parent::__construct when not needed --- src/SchemaOrgModel/TypesGenerator.php | 2 ++ templates/class.php.twig | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/SchemaOrgModel/TypesGenerator.php b/src/SchemaOrgModel/TypesGenerator.php index 6f295250..c4c5285e 100644 --- a/src/SchemaOrgModel/TypesGenerator.php +++ b/src/SchemaOrgModel/TypesGenerator.php @@ -110,6 +110,7 @@ public function generate($config) 'fields' => [], 'uses' => [], 'hasConstructor' => false, + 'parentHasConstructor' => false, 'hasChild' => false, 'abstract' => false, ]; @@ -280,6 +281,7 @@ public function generate($config) foreach ($classes as &$class) { if ($class['parent'] && isset($classes[$class['parent']])) { $classes[$class['parent']]['hasChild'] = true; + $class['parentHasConstructor'] = $classes[$class['parent']]['hasConstructor']; } foreach ($class['fields'] as &$field) { diff --git a/templates/class.php.twig b/templates/class.php.twig index f969bf7b..a091479f 100644 --- a/templates/class.php.twig +++ b/templates/class.php.twig @@ -43,8 +43,10 @@ use {{ use }}; {% if config.doctrine.useCollection and class.hasConstructor %} public function __construct() { +{% if class.parentHasConstructor %} parent::__construct(); +{% endif %} {% for field in class.fields %} {% if config.doctrine.useCollection and field.isArray and field.typeHint and not field.isEnum %} $this->{{ field.name }} = new ArrayCollection();