Skip to content

Commit

Permalink
whitelist htmlTemplate / textTemplate to be valid Twig entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Haehnchen committed Aug 31, 2023
1 parent d43006a commit 06480f2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public class SymfonyPhpReferenceContributor extends PsiReferenceContributor {
new MethodMatcher.CallToSignature("\\Twig\\Environment", "display"),
new MethodMatcher.CallToSignature("\\Twig\\Environment", "isTemplateFresh"),
new MethodMatcher.CallToSignature("\\Twig\\Environment", "resolveTemplate"), // @TODO: also "is_array($names)"

new MethodMatcher.CallToSignature("\\Symfony\\Bridge\\Twig\\Mime\\TemplatedEmail", "htmlTemplate"),
new MethodMatcher.CallToSignature("\\Symfony\\Bridge\\Twig\\Mime\\TemplatedEmail", "textTemplate"),
};

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public static class UrlAction extends AnAction {
@NotNull
private final ProfilerRequestInterface profilerRequest;

@Nullable
private String panel;

public UrlAction(@NotNull ProfilerIndexInterface profilerIndex, @NotNull ProfilerRequestInterface profilerRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static fr.adrienbrault.idea.symfony2plugin.util.StringUtils.underscore;

Expand Down Expand Up @@ -310,7 +311,7 @@ public static void processMethodReference(@NotNull MethodReference methodReferen
return;
}

if(!methods.get().contains(methodName) && !methodName.toLowerCase().contains("render")) {
if (!methods.get().contains(methodName) && Stream.of("render", "htmltemplate", "texttemplate").noneMatch(s -> methodName.toLowerCase().contains(s))) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public void testThatTwigRenderMethodsAreInIndex() {
" $foo->render($this->foo);\n" +
" $foo->render(\\DateTime::foo);\n" +
" $foo->renderView($defaultParameter);\n" +
" $foo1->htmlTemplate('emails/signup.html.twig');\n" +
" $foo1->textTemplate('emails/signup.txt.twig');\n" +
" }\n" +
"}" +
"" +
"\n" +
"function foobarFunc()" +
"{\n" +
" $foo->render('foo-render.html.twig')\n" +
Expand All @@ -50,7 +52,7 @@ public void testThatTwigRenderMethodsAreInIndex() {
"foo-render.html.twig", "foo-renderView.html.twig", "foo-renderResponse.html.twig",
"@Foo/overwrite.html.twig", "const.html.twig", "var.html.twig", "private.html.twig", "foobar-render.twig",
"foo-render-ternary.html.twig", "const-ternary.html.twig", "foo-render-coalesce.html.twig", "const-coalesce.html.twig",
"foo-var-assignment-expression.html.twig", "default-function-parameter.html.twig"
"foo-var-assignment-expression.html.twig", "default-function-parameter.html.twig", "emails/signup.html.twig", "emails/signup.txt.twig"
);

assertIndexContainsKeyWithValue(PhpTwigTemplateUsageStubIndex.KEY, "foo-render.html.twig", value ->
Expand Down

0 comments on commit 06480f2

Please sign in to comment.