Search in sources :

Example 1 with PhpEmpty

use of com.jetbrains.php.lang.psi.elements.PhpEmpty in project phpinspectionsea by kalessil.

the class AssertEmptyStrategy method apply.

public static boolean apply(@NotNull String methodName, @NotNull MethodReference reference, @NotNull ProblemsHolder holder) {
    boolean result = false;
    if (targetMapping.containsKey(methodName)) {
        final PsiElement[] assertionArguments = reference.getParameters();
        if (assertionArguments.length > 0 && assertionArguments[0] instanceof PhpEmpty) {
            final PsiElement[] emptyArguments = ((PhpEmpty) assertionArguments[0]).getVariables();
            if (emptyArguments.length == 1) {
                /* generate QF arguments */
                final String suggestedAssertion = targetMapping.get(methodName);
                final String[] suggestedArguments = new String[assertionArguments.length];
                suggestedArguments[0] = emptyArguments[0].getText();
                if (assertionArguments.length > 1) {
                    suggestedArguments[1] = assertionArguments[1].getText();
                }
                /* register an issue */
                holder.registerProblem(reference, String.format(MessagesPresentationUtil.prefixWithEa(messagePattern), suggestedAssertion), new PhpUnitAssertFixer(suggestedAssertion, suggestedArguments));
                result = true;
            }
        }
    }
    return result;
}
Also used : PhpEmpty(com.jetbrains.php.lang.psi.elements.PhpEmpty) PhpUnitAssertFixer(com.kalessil.phpStorm.phpInspectionsEA.fixers.PhpUnitAssertFixer) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 PhpEmpty (com.jetbrains.php.lang.psi.elements.PhpEmpty)1 PhpUnitAssertFixer (com.kalessil.phpStorm.phpInspectionsEA.fixers.PhpUnitAssertFixer)1