Idea-php-symfony2-plugin: Doctrine2 magic repository methods

Created on 4 Sep 2013  路  18Comments  路  Source: Haehnchen/idea-php-symfony2-plugin

In 0.8.0 release there was a note:

  • Detect EntityRepository::find/findOneBy/findAll/findBy result type

At the moment doctrine2 support behaves like this:

$repo = $this->getDoctrine()->getRepository('Namespace:Entity');
$entity = $repo->findOneByProperty('value'); // $entity does not resolve as an Entity
$entity = $repo->findOneBy(array('property' => 'value')) // $entity does resolve as an Entity and autocomplete works

Could you please implement resolving of magic methods like findOneBy* and findBy*?

enhancement todo

Most helpful comment

Same here, would love to have the "magic" Doctrine methods to be resolved in PHPStorm like findOneBy*

All 18 comments

phpstorm api need a fully class name which is not possible. iam looking into a hack for thats but limited to api...

by ide design its not possible, need to close but marked as "api"

now possible with a workaround :)

That's a good news! :+1: :)

any more detail available on this workaround? inquiring minds want to know!

just let phpstorm build a dummy interface and add this in phptypeprovider to the already known class return type :)

Hi guys, any news on this issue?

WI-22743 "Fix versions 8.0" and http://youtrack.jetbrains.com/issue/WI-22881.
so waiting for what we will get in phpstorm8, else going for the hack.

Did you go for the hack? I'm facing the exact same issue. My current approach is to dump the generated files into a sub-folder under cache and add the directory as a library.

@Haehnchen Can you provide an example for Alexey on WI-22881?

Bumping this as I am interested in this as well.

Same here, would love to have the "magic" Doctrine methods to be resolved in PHPStorm like findOneBy*

Hi @Haehnchen, methods findBy* are still marked as not found. Have you any plans to add support of them?

return type is resolved; did a quick test on the method completion, but there is now new API available to attach it

@Haehnchen I've just updated plugin to 0.20.194 which includes this issue resolution, but I still see the same warning as in the previous version:

image

Also I've got 5 exceptions for the file that is on screenshot above:

In file: file://***/src/Service/CurrencyService.php

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    at fr.adrienbrault.idea.symfony2plugin.doctrine.ObjectManagerFindContextTypeProvider.complete(ObjectManagerFindContextTypeProvider.java:81)
    at com.jetbrains.php.PhpIndexImpl.lambda$completeType$1(PhpIndexImpl.java:129)
    at com.intellij.openapi.util.RecursionManager$1.doPreventingRecursion(RecursionManager.java:117)
    at com.jetbrains.php.PhpIndexImpl.completeType(PhpIndexImpl.java:129)
    at com.jetbrains.php.PhpIndexImpl.completeType(PhpIndexImpl.java:100)
    at com.jetbrains.php.lang.psi.resolve.types.PhpType.global(PhpType.java:460)
    at com.jetbrains.php.lang.psi.resolve.types.PhpArrayAccessTP.complete(PhpArrayAccessTP.java:137)
    at com.jetbrains.php.PhpIndexImpl.lambda$completeType$1(PhpIndexImpl.java:129)
    at com.intellij.openapi.util.RecursionManager$1.doPreventingRecursion(RecursionManager.java:117)
    at com.jetbrains.php.PhpIndexImpl.completeType(PhpIndexImpl.java:129)
    at com.jetbrains.php.PhpIndexImpl.getClasses(PhpIndexImpl.java:708)
    at com.jetbrains.php.PhpIndexImpl.getBySignatureInternal(PhpIndexImpl.java:617)
    at com.jetbrains.php.PhpIndexImpl.getBySignature(PhpIndexImpl.java:508)
    at com.jetbrains.php.PhpIndexImpl.completeType(PhpIndexImpl.java:142)
    at com.jetbrains.php.PhpIndexImpl.completeType(PhpIndexImpl.java:100)
    at com.jetbrains.php.lang.psi.resolve.types.PhpType.global(PhpType.java:460)
    at com.jetbrains.php.lang.psi.resolve.types.PhpType.globalLocationAware(PhpType.java:455)
    at com.jetbrains.php.lang.annotator.PhpAnnotatorVisitor.getType(PhpAnnotatorVisitor.java:404)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
    at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
    at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.anyMatch(ReferencePipeline.java:528)
    at one.util.streamex.AbstractStreamEx.anyMatch(AbstractStreamEx.java:443)
    at com.jetbrains.php.lang.annotator.PhpAnnotatorVisitor.checkOperatorsArraySupport(PhpAnnotatorVisitor.java:397)
    at com.jetbrains.php.lang.annotator.PhpAnnotatorVisitor.visitPhpBinaryExpression(PhpAnnotatorVisitor.java:389)
    at com.jetbrains.php.lang.psi.elements.impl.BinaryExpressionImpl.accept(BinaryExpressionImpl.java:59)
    at com.jetbrains.php.lang.annotator.PhpAnnotator.annotate(PhpAnnotator.java:17)
    at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.runAnnotators(DefaultHighlightVisitor.java:129)
    at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.visit(DefaultHighlightVisitor.java:110)
    at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.runVisitors(GeneralHighlightingPass.java:346)
    at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.lambda$collectHighlights$5(GeneralHighlightingPass.java:286)
    at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:306)
    at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.lambda$analyzeByVisitors$6(GeneralHighlightingPass.java:309)
    at com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.analyze(XmlHighlightVisitor.java:599)
    at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:309)
    at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.lambda$analyzeByVisitors$6(GeneralHighlightingPass.java:309)
    at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.analyze(DefaultHighlightVisitor.java:93)
    at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:309)
    at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectHighlights(GeneralHighlightingPass.java:277)
    at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectInformationWithProgress(GeneralHighlightingPass.java:222)
    at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:84)
    at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:52)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$null$1(PassExecutorService.java:442)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1106)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:435)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:627)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:572)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:434)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:410)
    at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:168)
    at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:168)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:408)
    at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:171)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)

But I can't send these reports because Report exception button is disabled for unknown reason.

@yura3d your issue is fixed, but your method not found is not catched here only the return type of the find*. simply there is no way in the PhpStorm that magic method can be attached.

image

@Haehnchen What could be the reason that the variable in the example above is not resolved as entity and autocompletion for it doesn't work?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dewos picture dewos  路  5Comments

ostrolucky picture ostrolucky  路  4Comments

Anubarak picture Anubarak  路  5Comments

alexsakhnov picture alexsakhnov  路  7Comments

Haehnchen picture Haehnchen  路  7Comments