use of com.jetbrains.php.config.PhpLanguageLevel in project phpinspectionsea by kalessil.
the class MinimalPhpVersionStrategy method apply.
public static void apply(final Method method, final ProblemsHolder holder, final PhpLanguageLevel neededVersion) {
if (null != method.getNameIdentifier()) {
final PhpLanguageLevel phpVersion = PhpProjectConfigurationFacade.getInstance(holder.getProject()).getLanguageLevel();
if (phpVersion.compareTo(neededVersion) < 0) {
// at least required version
final String message = strProblemDescription.replace("%m%", method.getName()).replace("%v%", neededVersion.getVersionString());
holder.registerProblem(method.getNameIdentifier(), message, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
}
use of com.jetbrains.php.config.PhpLanguageLevel in project phpinspectionsea by kalessil.
the class ArgumentUnpackingCanBeUsedInspector method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new BasePhpElementVisitor() {
@Override
public void visitPhpFunctionCall(@NotNull FunctionReference reference) {
final PhpLanguageLevel php = PhpProjectConfigurationFacade.getInstance(holder.getProject()).getLanguageLevel();
if (php.compareTo(PhpLanguageLevel.PHP560) >= 0) {
final String functionName = reference.getName();
if (functionName != null && functionName.equals("call_user_func_array")) {
final PsiElement[] arguments = reference.getParameters();
if (arguments.length == 2) {
final boolean isContainerValid = arguments[1] instanceof Variable || arguments[1] instanceof ArrayCreationExpression || arguments[1] instanceof FunctionReference;
if (isContainerValid && arguments[0] instanceof StringLiteralExpression) {
/* do not process strings with injections */
final StringLiteralExpression targetFunction = (StringLiteralExpression) arguments[0];
if (targetFunction.getFirstPsiChild() == null) {
final String replacement = "%f%(...%a%)".replace("%a%", arguments[1].getText()).replace("%f%", targetFunction.getContents());
final String message = messagePattern.replace("%e%", replacement);
holder.registerProblem(reference, message, new UnpackFix(replacement));
}
}
}
}
}
// TODO: if (isContainerValid && params[0] instanceof ArrayCreationExpression) {
// TODO: call_user_func_array([...], ...); string method name must not contain ::
}
};
}
Aggregations