Skip to content

Commit

Permalink
Merge pull request #11 from yannickl88/master
Browse files Browse the repository at this point in the history
Fixed issue with duplicate use statements and added return after NS line
  • Loading branch information
stefanlenselink committed Jul 24, 2014
2 parents 37d61bd + 599cbfd commit 3638095
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/CompoundGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function findUseStatementsForOptionalTraits(
);
}
}
return $result;
return array_unique($result, SORT_REGULAR); // remove any duplicate use statements
}
/**
* Gives all the entities to be required in the compound interface
Expand Down Expand Up @@ -144,7 +144,12 @@ private function generateTrait(PackageClass $package_class, array $traits)
array(
'class_name' => $short_name,
'namespace' => $generated_namespace,
'use_statements' => $traits
'use_statements' => array_filter(
$traits,
function (PackageClass $stmt) {
return $stmt->isTrait();
}
)
)
);

Expand Down
7 changes: 4 additions & 3 deletions src/Resources/templates/traits.php.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace {{ namespace }};
{%if use_statements | length %}
{% for use_statement in use_statements if use_statement.isTrait() %}
{% if use_statements | length %}
{% for use_statement in use_statements %}
use {{ use_statement.name}} as {{ use_statement.alias }};
{% endfor %}
{% endif %}
Expand All @@ -13,7 +14,7 @@ use {{ use_statement.name}} as {{ use_statement.alias }};
*/
trait {{ class_name }}Traits
{
{% for use_statement in use_statements if use_statement.isTrait() %}
{% for use_statement in use_statements %}
use {{ use_statement.alias }};
{% endfor %}
}
1 change: 1 addition & 0 deletions test/CompoundEdgeCases/ContractTraits.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Hostnet\Contract\Entity\Generated;

use Hostnet\Contract\Entity\ContractWhenClientTrait as HostnetContractEntityBecauseClient;

/**
Expand Down

0 comments on commit 3638095

Please sign in to comment.