Skip to content

Commit d3e01e0

Browse files
authored
Merge pull request #1894 from Haehnchen/feature/1893-attributes-workaround
#1893 workaround in wrongly implemented attributes handling; catch er…
2 parents 0093da7 + bc3856d commit d3e01e0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpPsiAttributesUtil.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,22 @@ public static String getAttributeValueByNameAsStringWithDefaultParameterFallback
6363
for (PhpAttribute.PhpAttributeArgument argument : attribute.getArguments()) {
6464
PhpExpectedFunctionArgument argument1 = argument.getArgument();
6565
if (argument1.getArgumentIndex() == 0) {
66+
// what a mess here :)
67+
// createReference is stopping with exception on array values
68+
String value = argument1.getValue();
69+
String s = org.apache.commons.lang3.StringUtils.normalizeSpace(value).replaceAll("[\\n\\t ]", "");
70+
if (s.startsWith("['") || s.startsWith("[\"")) {
71+
continue;
72+
}
6673

6774
// hint: reference is a complete fake object lazily created; it is not reflect the real element :(
6875
// PhpPsiElementFactory.createPhpPsiFromText => com.jetbrains.php.lang.psi.stubs.indexes.expectedArguments.PhpExpectedFunctionClassConstantArgument.createReference
69-
@NotNull PsiElement namedElement = argument1.createReference(attribute.getProject());
76+
@NotNull PsiElement namedElement;
77+
try {
78+
namedElement = argument1.createReference(attribute.getProject());
79+
} catch (AssertionError e) {
80+
continue;
81+
}
7082

7183
if (namedElement instanceof StringLiteralExpression) {
7284
// we can trust the string representation here, looks to be right implemented

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/stubs/indexes/fixtures/RoutesStubIndex.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ public function attributesPathFoo1()
204204
public function attributesPathFoo2()
205205
{
206206
}
207+
208+
#[Route([
209+
'cs' => '/foobar/baz/{id}',
210+
'sk' => '/foobarbaz/bat/{id}',
211+
], name: 'dashboard', methods: ['GET'])]
212+
public function nameAsArray()
213+
{
214+
}
207215
}
208216
}
209217

0 commit comments

Comments
 (0)