Skip to content
This repository was archived by the owner on Jul 2, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<!-- Add your extensions here -->
</extensions>

<extensions defaultExtensionNs="com.jetbrains.php">
<typeProvider3 implementation="org.atoum.intellij.plugin.atoum.MockTypeProvider" />
</extensions>

<application-components>
<!-- Add your application components here -->
</application-components>
Expand Down Expand Up @@ -79,4 +83,4 @@
<depends>com.jetbrains.php</depends>
<depends>com.intellij.modules.platform</depends>

</idea-plugin>
</idea-plugin>
41 changes: 41 additions & 0 deletions src/org/atoum/intellij/plugin/atoum/MockTypeProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.atoum.intellij.plugin.atoum;

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.lang.psi.elements.ClassReference;
import com.jetbrains.php.lang.psi.elements.NewExpression;
import com.jetbrains.php.lang.psi.elements.PhpNamedElement;
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider3;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Set;

public class MockTypeProvider implements PhpTypeProvider3 {

@Override
public char getKey() {
return '\u0102';

@vdechenaux vdechenaux Oct 1, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your custom signature key, i.e. "Я"

https://confluence.jetbrains.com/display/PhpStorm/PHP+Open+API

I checked other projects, like here https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/a3fa7ef7c3d5a57be2a7130cf831d44d7760ea1e/src/fr/adrienbrault/idea/symfony2plugin/doctrine/ObjectManagerFindTypeProvider.java and they seems to use random unicode character.
I used Ă ( 'A' for atoum and it looks like the atoum logo with the horns 😛 )

}

@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
if (psiElement instanceof NewExpression) {
NewExpression expr = (NewExpression) psiElement;
ClassReference ref = expr.getClassReference();

if (ref != null && ref.getFQN() != null && ref.getFQN().startsWith("\\mock\\")) {
return new PhpType().add(ref.getFQN().substring("\\mock".length()));
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the element which need type resolution is a class with FQN like \mock\xxxxxx we return the class \xxxxxx

}

return null;
}

@Override
public Collection<? extends PhpNamedElement> getBySignature(String s, Set<String> set, int i, Project project) {
return null;
}
}