Skip to content

Commit

Permalink
Don't call parent::__construct when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Mar 6, 2015
1 parent 44cc80a commit 42698d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/SchemaOrgModel/TypesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function generate($config)
'fields' => [],
'uses' => [],
'hasConstructor' => false,
'parentHasConstructor' => false,
'hasChild' => false,
'abstract' => false,
];
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions templates/class.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 42698d1

Please sign in to comment.