use of com.kalessil.phpStorm.phpInspectionsEA.fixers.PhpUnitAssertFixer in project phpinspectionsea by kalessil.
the class AssertResourceExistsStrategy 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 && OpenapiTypesUtil.isFunctionReference(assertionArguments[0])) {
final FunctionReference candidate = (FunctionReference) assertionArguments[0];
final String functionName = candidate.getName();
if (functionName != null && targetFunctions.containsKey(functionName)) {
final PsiElement[] functionArguments = candidate.getParameters();
if (functionArguments.length == 1) {
final String suggestedAssertion = String.format(targetMapping.get(methodName), targetFunctions.get(functionName));
final String[] suggestedArguments = new String[assertionArguments.length];
suggestedArguments[0] = functionArguments[0].getText();
if (assertionArguments.length > 1) {
suggestedArguments[1] = assertionArguments[1].getText();
}
holder.registerProblem(reference, String.format(messagePattern, suggestedAssertion), new PhpUnitAssertFixer(suggestedAssertion, suggestedArguments));
result = true;
}
}
}
}
return result;
}
use of com.kalessil.phpStorm.phpInspectionsEA.fixers.PhpUnitAssertFixer in project phpinspectionsea by kalessil.
the class AssertInternalTypeStrategy method apply.
public static boolean apply(@NotNull String methodName, @NotNull MethodReference reference, @NotNull ProblemsHolder holder, @NotNull PhpUnitVersion version) {
boolean result = false;
if (targetMapping.containsKey(methodName)) {
final PsiElement[] assertionArguments = reference.getParameters();
if (assertionArguments.length > 0 && OpenapiTypesUtil.isFunctionReference(assertionArguments[0])) {
final FunctionReference functionReference = (FunctionReference) assertionArguments[0];
final String functionName = functionReference.getName();
if (functionName != null && targetFunctionMapping.containsKey(functionName)) {
final PsiElement[] functionArguments = functionReference.getParameters();
if (functionArguments.length > 0) {
/* generate QF arguments */
final String suggestedAssertion;
final String suggestedType;
final String[] suggestedArguments;
final String message;
if (version.below(PhpUnitVersion.PHPUNIT80)) {
suggestedAssertion = targetMapping.get(methodName);
suggestedType = targetFunctionMapping.get(functionName);
suggestedArguments = new String[assertionArguments.length + 1];
suggestedArguments[0] = String.format("'%s'", suggestedType);
suggestedArguments[1] = functionArguments[0].getText();
if (assertionArguments.length > 1) {
suggestedArguments[2] = assertionArguments[1].getText();
}
message = String.format(messagePatternInternalType, suggestedAssertion, suggestedType);
} else {
/* internal type assertions were deprecated */
suggestedAssertion = String.format(targetMapping.get(methodName).replace("InternalType", "Is%s").replace("NotIs", "IsNot"), StringUtils.capitalize(targetFunctionMapping.get(functionName)));
suggestedType = null;
suggestedArguments = new String[assertionArguments.length];
suggestedArguments[0] = functionArguments[0].getText();
if (assertionArguments.length > 1) {
suggestedArguments[1] = assertionArguments[1].getText();
}
message = String.format(messagePattern, suggestedAssertion);
}
/* register an issue */
holder.registerProblem(reference, MessagesPresentationUtil.prefixWithEa(message), new PhpUnitAssertFixer(suggestedAssertion, suggestedArguments));
result = true;
}
}
}
}
return result;
}
use of com.kalessil.phpStorm.phpInspectionsEA.fixers.PhpUnitAssertFixer in project phpinspectionsea by kalessil.
the class AssertResourceExistsStrategy method apply.
public static boolean apply(@NotNull String methodName, @NotNull MethodReference reference, @NotNull ProblemsHolder holder, @NotNull PhpUnitVersion version) {
boolean result = false;
if (targetMapping.containsKey(methodName)) {
final PsiElement[] assertionArguments = reference.getParameters();
if (assertionArguments.length > 0 && OpenapiTypesUtil.isFunctionReference(assertionArguments[0])) {
final FunctionReference candidate = (FunctionReference) assertionArguments[0];
final String functionName = candidate.getName();
if (functionName != null && targetFunctions.containsKey(functionName)) {
final PsiElement[] functionArguments = candidate.getParameters();
if (functionArguments.length == 1) {
final String suggestedAssertion = String.format(targetMapping.get(methodName), targetFunctions.get(functionName));
final String[] suggestedArguments = new String[assertionArguments.length];
suggestedArguments[0] = functionArguments[0].getText();
if (assertionArguments.length > 1) {
suggestedArguments[1] = assertionArguments[1].getText();
}
holder.registerProblem(reference, String.format(MessagesPresentationUtil.prefixWithEa(messagePattern), suggestNotDeprecated(suggestedAssertion, version)), new PhpUnitAssertFixer(suggestedAssertion, suggestedArguments));
result = true;
}
}
}
}
return result;
}
use of com.kalessil.phpStorm.phpInspectionsEA.fixers.PhpUnitAssertFixer in project phpinspectionsea by kalessil.
the class AssertContainsStrategy method apply.
public static boolean apply(@NotNull String methodName, @NotNull MethodReference reference, @NotNull ProblemsHolder holder, @NotNull PhpUnitVersion version) {
boolean result = false;
if (version.below(PhpUnitVersion.PHPUNIT90) && targetMapping.containsKey(methodName)) {
final PsiElement[] assertionArguments = reference.getParameters();
if (assertionArguments.length > 0 && OpenapiTypesUtil.isFunctionReference(assertionArguments[0])) {
final FunctionReference candidate = (FunctionReference) assertionArguments[0];
final String functionName = candidate.getName();
if (functionName != null && functionName.equals("in_array")) {
final PsiElement[] functionArguments = candidate.getParameters();
if (functionArguments.length >= 2) {
final String suggestedAssertion = targetMapping.get(methodName);
final String[] suggestedArguments = new String[assertionArguments.length + 1];
suggestedArguments[0] = functionArguments[0].getText();
suggestedArguments[1] = functionArguments[1].getText();
if (assertionArguments.length > 1) {
suggestedArguments[2] = assertionArguments[1].getText();
}
holder.registerProblem(reference, String.format(MessagesPresentationUtil.prefixWithEa(messagePattern), suggestedAssertion), new PhpUnitAssertFixer(suggestedAssertion, suggestedArguments));
result = true;
}
}
}
}
return result;
}
use of com.kalessil.phpStorm.phpInspectionsEA.fixers.PhpUnitAssertFixer 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;
}
Aggregations