Search in sources :

Example 6 with PhpLanguageLevel

use of com.jetbrains.php.config.PhpLanguageLevel in project phpinspectionsea by kalessil.

the class CascadeStringReplacementInspectorTest method testIfFindsPhp74Patterns.

public void testIfFindsPhp74Patterns() {
    final PhpLanguageLevel level = PhpLanguageLevel.parse("7.4");
    if (level != null && level.getVersionString().equals("7.4")) {
        PhpProjectConfigurationFacade.getInstance(myFixture.getProject()).setLanguageLevel(level);
        final CascadeStringReplacementInspector inspector = new CascadeStringReplacementInspector();
        inspector.USE_SHORT_ARRAYS_SYNTAX = true;
        myFixture.enableInspections(inspector);
        myFixture.configureByFile("testData/fixtures/api/strings/cascade-str-replace.74.php");
        myFixture.testHighlighting(true, false, true);
        myFixture.getAllQuickFixes().forEach(fix -> myFixture.launchAction(fix));
        myFixture.setTestDataPath(".");
        myFixture.checkResultByFile("testData/fixtures/api/strings/cascade-str-replace.74.fixed.php");
    }
}
Also used : CascadeStringReplacementInspector(com.kalessil.phpStorm.phpInspectionsEA.inspectors.apiUsage.strings.CascadeStringReplacementInspector) PhpLanguageLevel(com.jetbrains.php.config.PhpLanguageLevel)

Example 7 with PhpLanguageLevel

use of com.jetbrains.php.config.PhpLanguageLevel in project phpinspectionsea by kalessil.

the class UnnecessaryCastingInspectorTest method testIfFindsAllPatternsPhp8.

public void testIfFindsAllPatternsPhp8() {
    final PhpLanguageLevel level = PhpLanguageLevel.parse("8.0");
    if (level != null && level.getVersionString().equals("8.0")) {
        // PS 2020.2 introduced very limited PHP 8 support, hence we are checking the feature availability as well
        final boolean run = Arrays.stream(PhpLanguageFeature.class.getEnumConstants()).anyMatch(v -> v.toString().equals("NULLSAFE_DEREFERENCING"));
        if (run) {
            PhpProjectConfigurationFacade.getInstance(myFixture.getProject()).setLanguageLevel(level);
            myFixture.enableInspections(new UnnecessaryCastingInspector());
            myFixture.configureByFile("testData/fixtures/types/unnecessary-casting.php8.php");
            myFixture.testHighlighting(true, false, true);
        }
    }
}
Also used : UnnecessaryCastingInspector(com.kalessil.phpStorm.phpInspectionsEA.inspectors.codeStyle.UnnecessaryCastingInspector) PhpLanguageLevel(com.jetbrains.php.config.PhpLanguageLevel)

Example 8 with PhpLanguageLevel

use of com.jetbrains.php.config.PhpLanguageLevel in project phpinspectionsea by kalessil.

the class StaticClosureCanBeUsedInspectorTest method testIfFindsArrowFunctionPatterns.

public void testIfFindsArrowFunctionPatterns() {
    final PhpLanguageLevel level = PhpLanguageLevel.parse("7.4");
    if (level != null && level.getVersionString().equals("7.4")) {
        /* looks like 7.4 feature were introduced in multiple batches */
        final boolean hasArrowFunctions = Arrays.stream(PhpLanguageFeature.class.getEnumConstants()).anyMatch(f -> f.toString().contains("Arrow function"));
        if (hasArrowFunctions) {
            PhpProjectConfigurationFacade.getInstance(myFixture.getProject()).setLanguageLevel(level);
            final StaticClosureCanBeUsedInspector inspection = new StaticClosureCanBeUsedInspector();
            inspection.SUGGEST_FOR_SHORT_FUNCTIONS = true;
            myFixture.enableInspections(inspection);
            myFixture.configureByFile("testData/fixtures/codeStyle/static-closure-use.php74.php");
            myFixture.testHighlighting(true, false, true);
        }
    }
}
Also used : StaticClosureCanBeUsedInspector(com.kalessil.phpStorm.phpInspectionsEA.inspectors.codeStyle.StaticClosureCanBeUsedInspector) PhpLanguageLevel(com.jetbrains.php.config.PhpLanguageLevel)

Example 9 with PhpLanguageLevel

use of com.jetbrains.php.config.PhpLanguageLevel in project phpinspectionsea by kalessil.

the class IsCountableCanBeUsedInspectorTest method testIfFindsAllPatterns.

public void testIfFindsAllPatterns() {
    final PhpLanguageLevel level = PhpLanguageLevel.parse("7.4");
    if (level != null && level.getVersionString().equals("7.4")) {
        PhpProjectConfigurationFacade.getInstance(myFixture.getProject()).setLanguageLevel(level);
        myFixture.enableInspections(new IsCountableCanBeUsedInspector());
        myFixture.configureByFile("testData/fixtures/api/is-countable.php");
        myFixture.testHighlighting(true, false, true);
    }
}
Also used : IsCountableCanBeUsedInspector(com.kalessil.phpStorm.phpInspectionsEA.inspectors.apiUsage.IsCountableCanBeUsedInspector) PhpLanguageLevel(com.jetbrains.php.config.PhpLanguageLevel)

Example 10 with PhpLanguageLevel

use of com.jetbrains.php.config.PhpLanguageLevel in project phpinspectionsea by kalessil.

the class ArrayUniqueCanBeUsedInspectorTest method testIfFindsAllPatterns.

public void testIfFindsAllPatterns() {
    final PhpLanguageLevel level = PhpLanguageLevel.parse("7.2");
    if (level != null && level.getVersionString().equals("7.2")) {
        PhpProjectConfigurationFacade.getInstance(myFixture.getProject()).setLanguageLevel(level);
        myFixture.enableInspections(new ArrayUniqueCanBeUsedInspector());
        myFixture.configureByFile("testData/fixtures/api/array-unique.php");
        myFixture.testHighlighting(true, false, true);
        myFixture.getAllQuickFixes().forEach(fix -> myFixture.launchAction(fix));
        myFixture.setTestDataPath(".");
        myFixture.checkResultByFile("testData/fixtures/api/array-unique.fixed.php");
    }
}
Also used : ArrayUniqueCanBeUsedInspector(com.kalessil.phpStorm.phpInspectionsEA.inspectors.apiUsage.arrays.ArrayUniqueCanBeUsedInspector) PhpLanguageLevel(com.jetbrains.php.config.PhpLanguageLevel)

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