Search in sources :

Example 16 with PhpLanguageLevel

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);
        }
    }
}
Also used : PhpLanguageLevel(com.jetbrains.php.config.PhpLanguageLevel)

Example 17 with PhpLanguageLevel

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 ::
        }
    };
}
Also used : BasePhpElementVisitor(com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor) Variable(com.jetbrains.php.lang.psi.elements.Variable) ArrayCreationExpression(com.jetbrains.php.lang.psi.elements.ArrayCreationExpression) StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) FunctionReference(com.jetbrains.php.lang.psi.elements.FunctionReference) NotNull(org.jetbrains.annotations.NotNull) PhpLanguageLevel(com.jetbrains.php.config.PhpLanguageLevel) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PhpLanguageLevel (com.jetbrains.php.config.PhpLanguageLevel)17 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)8 NotNull (org.jetbrains.annotations.NotNull)8 PsiElement (com.intellij.psi.PsiElement)7 FunctionReference (com.jetbrains.php.lang.psi.elements.FunctionReference)4 StringLiteralExpression (com.jetbrains.php.lang.psi.elements.StringLiteralExpression)2 Variable (com.jetbrains.php.lang.psi.elements.Variable)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 ProblemHighlightType (com.intellij.codeInspection.ProblemHighlightType)1 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)1 Project (com.intellij.openapi.project.Project)1 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 SmartPointerManager (com.intellij.psi.SmartPointerManager)1 SmartPsiElementPointer (com.intellij.psi.SmartPsiElementPointer)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 PhpAccessVariableInstruction (com.jetbrains.php.codeInsight.controlFlow.instructions.PhpAccessVariableInstruction)1 PhpEntryPointInstruction (com.jetbrains.php.codeInsight.controlFlow.instructions.PhpEntryPointInstruction)1 PhpLanguageFeature (com.jetbrains.php.config.PhpLanguageFeature)1