Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
danigargar committed Aug 29, 2024
1 parent 809f96c commit 52d6fde
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
11 changes: 4 additions & 7 deletions EntityGeneratorBundle/Doctrine/EntityTrait/Adder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Adder implements CodeGeneratorUnitInterface
protected $classMetadata;
protected $visibility;

protected $returnHintCallable;
protected $getReturnHint;

public function __construct(
string $propertyName,
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions EntityGeneratorBundle/Doctrine/EntityTrait/GetReturnHint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace IvozDevTools\EntityGeneratorBundle\Doctrine\EntityTrait;

class GetReturnHint
{
public function __invoke(string $returnHint): string {
$similarInterfaces = false;

foreach (array_keys($this->useStatements) as $fqdn){

Check failure on line 10 in EntityGeneratorBundle/Doctrine/EntityTrait/GetReturnHint.php

View workflow job for this annotation

GitHub Actions / build

Access to an undefined property IvozDevTools\EntityGeneratorBundle\Doctrine\EntityTrait\GetReturnHint::$useStatements.
$parts = explode('\\', $fqdn);
$lastValue = end($parts);

if($lastValue === $returnHint){
$similarInterfaces = true;
break;
}
}

if($similarInterfaces){
$returnHint = 'static';
}

return $returnHint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ public function addSetter(
$classMetadata,
$commentLines,
$columnOptions,
$visibility,
[$this, 'getReturnHint']
$visibility
);
$this->methods[] = new Remover(
Expand Down

0 comments on commit 52d6fde

Please sign in to comment.