diff --git a/EntityGeneratorBundle/Doctrine/EntityTrait/Adder.php b/EntityGeneratorBundle/Doctrine/EntityTrait/Adder.php index 00adef2..5e4e6d7 100644 --- a/EntityGeneratorBundle/Doctrine/EntityTrait/Adder.php +++ b/EntityGeneratorBundle/Doctrine/EntityTrait/Adder.php @@ -15,7 +15,7 @@ class Adder implements CodeGeneratorUnitInterface protected $classMetadata; protected $visibility; - protected $returnHintCallable; + protected $getReturnHint; public function __construct( string $propertyName, @@ -24,8 +24,7 @@ public function __construct( $classMetadata, array $commentLines = [], array $columnOptions = [], - string $visibility = 'protected', - ?callable $returnHintCallable = null + string $visibility = 'protected' ) { $this->propertyName = $propertyName; $this->type = $type; @@ -34,7 +33,7 @@ public function __construct( $this->columnOptions = $columnOptions; $this->classMetadata = $classMetadata; $this->visibility = $visibility; - $this->returnHintCallable = $returnHintCallable; + $this->getReturnHint = new GetReturnHint(); } public function toString(string $nlLeftPad = ''): string @@ -47,9 +46,7 @@ public function toString(string $nlLeftPad = ''): string $fqdnSegments = explode('\\', $this->classMetadata->name); $returnHint = $fqdnSegments[count($fqdnSegments) -2] . 'Interface'; - if(!is_null($this->returnHintCallable)){ - $returnHint = ($this->returnHintCallable)($returnHint); - } + $returnHint = $this->getReturnHint->__invoke($returnHint); $response = []; $response[] = sprintf( diff --git a/EntityGeneratorBundle/Doctrine/EntityTrait/GetReturnHint.php b/EntityGeneratorBundle/Doctrine/EntityTrait/GetReturnHint.php new file mode 100644 index 0000000..62bc8d2 --- /dev/null +++ b/EntityGeneratorBundle/Doctrine/EntityTrait/GetReturnHint.php @@ -0,0 +1,26 @@ +useStatements) as $fqdn){ + $parts = explode('\\', $fqdn); + $lastValue = end($parts); + + if($lastValue === $returnHint){ + $similarInterfaces = true; + break; + } + } + + if($similarInterfaces){ + $returnHint = 'static'; + } + + return $returnHint; + } +} \ No newline at end of file diff --git a/EntityGeneratorBundle/Doctrine/EntityTrait/TraitManipulator.php b/EntityGeneratorBundle/Doctrine/EntityTrait/TraitManipulator.php index 4253617..6d6f907 100644 --- a/EntityGeneratorBundle/Doctrine/EntityTrait/TraitManipulator.php +++ b/EntityGeneratorBundle/Doctrine/EntityTrait/TraitManipulator.php @@ -275,8 +275,7 @@ public function addSetter( $classMetadata, $commentLines, $columnOptions, - $visibility, - [$this, 'getReturnHint'] + $visibility ); $this->methods[] = new Remover(