Search in sources :

Example 1 with PhpExpression

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

the class CanNotReturnTypeStrategy method apply.

public static void apply(final Method method, final ProblemsHolder holder) {
    final Collection<PhpReturn> returnStatements = PsiTreeUtil.findChildrenOfType(method, PhpReturn.class);
    if (!returnStatements.isEmpty() && NamedElementUtil.getNameIdentifier(method) != null) {
        final String message = strProblemDescription.replace("%m%", method.getName());
        for (final PhpReturn returnExpression : returnStatements) {
            final PhpExpression returnValue = ExpressionSemanticUtil.getReturnValue(returnExpression);
            if (null != returnValue && method == ExpressionSemanticUtil.getScope(returnExpression)) {
                holder.registerProblem(returnExpression, MessagesPresentationUtil.prefixWithEa(message));
            }
        }
    }
    returnStatements.clear();
}
Also used : PhpReturn(com.jetbrains.php.lang.psi.elements.PhpReturn) PhpExpression(com.jetbrains.php.lang.psi.elements.PhpExpression)

Example 2 with PhpExpression

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

the class MethodArgumentDroppedMatcherInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    return new PhpElementVisitor() {

        @Override
        public void visitPhpElement(PhpPsiElement element) {
            if (!PlatformPatterns.psiElement(PhpElementTypes.METHOD_REFERENCE).accepts(element)) {
                return;
            }
            MethodReference methodReference = (MethodReference) element;
            ParameterList parameterList = methodReference.getParameterList();
            PhpExpression classReference = methodReference.getClassReference();
            if (classReference != null) {
                PhpType inferredType = classReference.getInferredType();
                String compiledClassMethodKey = inferredType.toString() + "->" + methodReference.getName();
                if (ExtensionScannerUtil.classMethodHasDroppedArguments(element.getProject(), compiledClassMethodKey)) {
                    Integer maximumNumberOfArguments = ExtensionScannerUtil.getMaximumNumberOfArguments(element.getProject(), compiledClassMethodKey);
                    if (parameterList != null && maximumNumberOfArguments != -1 && parameterList.getParameters().length != maximumNumberOfArguments) {
                        problemsHolder.registerProblem(element, "Number of arguments changed with TYPO3 9, consider refactoring");
                    }
                }
            }
        }
    };
}
Also used : PhpElementVisitor(com.jetbrains.php.lang.psi.visitors.PhpElementVisitor) PhpExpression(com.jetbrains.php.lang.psi.elements.PhpExpression) ParameterList(com.jetbrains.php.lang.psi.elements.ParameterList) MethodReference(com.jetbrains.php.lang.psi.elements.MethodReference) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) PhpType(com.jetbrains.php.lang.psi.resolve.types.PhpType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PhpExpression (com.jetbrains.php.lang.psi.elements.PhpExpression)2 MethodReference (com.jetbrains.php.lang.psi.elements.MethodReference)1 ParameterList (com.jetbrains.php.lang.psi.elements.ParameterList)1 PhpPsiElement (com.jetbrains.php.lang.psi.elements.PhpPsiElement)1 PhpReturn (com.jetbrains.php.lang.psi.elements.PhpReturn)1 PhpType (com.jetbrains.php.lang.psi.resolve.types.PhpType)1 PhpElementVisitor (com.jetbrains.php.lang.psi.visitors.PhpElementVisitor)1 NotNull (org.jetbrains.annotations.NotNull)1