Search in sources :

Example 6 with ConstantReference

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

the class McryptRsaOraclePaddingStrategy method apply.

public static boolean apply(@NotNull ProblemsHolder holder, @NotNull FunctionReference reference) {
    boolean result = false;
    if (isTargetCall(reference)) {
        final Set<PsiElement> modeVariants = PossibleValuesDiscoveryUtil.discover(reference.getParameters()[3]);
        if (!modeVariants.isEmpty()) {
            for (final PsiElement variant : modeVariants) {
                if (variant instanceof ConstantReference) {
                    final String constantName = ((ConstantReference) variant).getName();
                    if (constantName != null && constantName.equals("MCRYPT_MODE_CBC")) {
                        holder.registerProblem(reference, message);
                        result = true;
                        break;
                    }
                }
            }
            modeVariants.clear();
        }
    }
    return result;
}
Also used : ConstantReference(com.jetbrains.php.lang.psi.elements.ConstantReference) PsiElement(com.intellij.psi.PsiElement)

Example 7 with ConstantReference

use of com.jetbrains.php.lang.psi.elements.ConstantReference in project idea-php-typo3-plugin by cedricziel.

the class ConstantMatcherInspection method getRemovedConstantsFQNs.

private Set<String> getRemovedConstantsFQNs(ConstantReference element) {
    Set<PsiElement> elements = new HashSet<>();
    PsiFile[] constantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ConstantMatcher.php", GlobalSearchScope.allScope(element.getProject()));
    for (PsiFile file : constantMatcherFiles) {
        Collections.addAll(elements, PsiTreeUtil.collectElements(file, el -> PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withAncestor(4, PlatformPatterns.psiElement(PhpElementTypes.RETURN))).accepts(el)));
    }
    return elements.stream().map(stringLiteral -> "\\" + ((StringLiteralExpression) stringLiteral).getContents()).collect(Collectors.toSet());
}
Also used : PhpElementVisitor(com.jetbrains.php.lang.psi.visitors.PhpElementVisitor) GroupNames(com.intellij.codeInsight.daemon.GroupNames) FilenameIndex(com.intellij.psi.search.FilenameIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) Collectors(java.util.stream.Collectors) PlatformPatterns(com.intellij.patterns.PlatformPatterns) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) HashSet(java.util.HashSet) ConstantReference(com.jetbrains.php.lang.psi.elements.ConstantReference) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Nls(org.jetbrains.annotations.Nls) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) PhpInspection(com.jetbrains.php.lang.inspections.PhpInspection) StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) NotNull(org.jetbrains.annotations.NotNull) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) Collections(java.util.Collections) PhpElementTypes(com.jetbrains.php.lang.parser.PhpElementTypes) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) PsiFile(com.intellij.psi.PsiFile) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) PsiElement(com.intellij.psi.PsiElement) HashSet(java.util.HashSet)

Aggregations

ConstantReference (com.jetbrains.php.lang.psi.elements.ConstantReference)7 PsiElement (com.intellij.psi.PsiElement)6 NotNull (org.jetbrains.annotations.NotNull)4 IElementType (com.intellij.psi.tree.IElementType)2 BinaryExpression (com.jetbrains.php.lang.psi.elements.BinaryExpression)2 PhpPsiElement (com.jetbrains.php.lang.psi.elements.PhpPsiElement)2 StringLiteralExpression (com.jetbrains.php.lang.psi.elements.StringLiteralExpression)2 PhpElementVisitor (com.jetbrains.php.lang.psi.visitors.PhpElementVisitor)2 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)2 GroupNames (com.intellij.codeInsight.daemon.GroupNames)1 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)1 PlatformPatterns (com.intellij.patterns.PlatformPatterns)1 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)1 PsiFile (com.intellij.psi.PsiFile)1 FilenameIndex (com.intellij.psi.search.FilenameIndex)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 PhpInspection (com.jetbrains.php.lang.inspections.PhpInspection)1 PhpElementTypes (com.jetbrains.php.lang.parser.PhpElementTypes)1 FunctionReference (com.jetbrains.php.lang.psi.elements.FunctionReference)1