Skip to content

Commit

Permalink
[IDE Classes] Add return types for entity repositories (concretecms#7251
Browse files Browse the repository at this point in the history
)

What about telling the IDE the return types of the `find()`/`findOneBy()`/`findAll()`/`findBy()`/`matching()` of custom entity repositories?

I don't know if phpstorms support a syntax like the one provided by the following code- if not, phpstorm users should give a thumb up at https://youtrack.jetbrains.com/issue/WI-27832.

```php
override(\Concrete\Core\Entity\Express\EntityRepository::find(0), map([
  '' => 'Concrete\Core\Entity\Express\Entity|null',
]));
```

BTW I just updated my Eclipse+PDT plugin to support it.

Sample application:

![immagine](https://user-images.githubusercontent.com/928116/47566542-615be180-d92c-11e8-988f-0cad4125ea6e.png)
  • Loading branch information
mlocati authored and KorvinSzanto committed Oct 29, 2018
1 parent 81aa4aa commit 62a6e16
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions concrete/src/Support/Symbol/MetadataGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ public function render()
$getRepositoryMethod[$entityClass] = "\\{$repositoryClass}::class";
}
$output = array_merge($output, $this->getOverride('\Doctrine\ORM\EntityManagerInterface::getRepository(0)', $getRepositoryMethod, '$em->getRepository(EntityClass::class)'));
foreach ($customEntityRepositories as $entityClass => $repositoryClass) {
$output = array_merge($output, $this->getOverride("\\{$repositoryClass}::find(0)", ['' => "'{$entityClass}|null'"], '$em->getRepository(EntityClass::class)->find()'));
$output = array_merge($output, $this->getOverride("\\{$repositoryClass}::findOneBy(0)", ['' => "'{$entityClass}|null'"], '$em->getRepository(EntityClass::class)->findOneBy()'));
$output = array_merge($output, $this->getOverride("\\{$repositoryClass}::findAll(0)", ['' => "'{$entityClass}[]'"], '$em->getRepository(EntityClass::class)->find()'));
$output = array_merge($output, $this->getOverride("\\{$repositoryClass}::findBy(0)", ['' => "'{$entityClass}[]'"], '$em->getRepository(EntityClass::class)->find()'));
$output = array_merge($output, $this->getOverride("\\{$repositoryClass}::matching(0)", ['' => "'Doctrine\Common\Collections\Collection|{$entityClass}[]'"], '$em->getRepository(EntityClass::class)->find()'));
}
}
$output = array_merge($output, $this->getOverride('\Doctrine\ORM\EntityManagerInterface::find(0)', ['' => "'@'"], '$em->find(EntityClass::class, $id)'));

Expand Down

0 comments on commit 62a6e16

Please sign in to comment.