From 7198dc3fcf8092f0fec7347a0b10f0375a23a7d2 Mon Sep 17 00:00:00 2001 From: EA Inspections Team Date: Fri, 20 Sep 2024 08:13:41 +0200 Subject: [PATCH] [#1949] UseSuggestedReplacementFixer: harden against exceptions in blade files. --- .../fixers/UseSuggestedReplacementFixer.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/fixers/UseSuggestedReplacementFixer.java b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/fixers/UseSuggestedReplacementFixer.java index 456c71ad31..659efe7eca 100644 --- a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/fixers/UseSuggestedReplacementFixer.java +++ b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/fixers/UseSuggestedReplacementFixer.java @@ -48,7 +48,18 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri .createPhpPsiFromText(project, ParenthesizedExpression.class, '(' + this.expression + ')') .getArgument(); if (replacement != null && !project.isDisposed()) { - expression.replace(replacement); + try { + expression.replace(replacement); + } catch (final Throwable failure) { + /* + * It were multiple reports pointing to exceptions which might be related to blade support implementation. + * The best we can do is to make it less disruptive for blade files and keep exception for other files. + */ + final boolean isBladeFile = descriptor.getPsiElement().getContainingFile().getVirtualFile().getName().endsWith(".blade.php"); + if (! isBladeFile) { + throw failure; + } + } } } }