File tree Expand file tree Collapse file tree
tests/Rule/data/providers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3636use ShipMonk \PHPStan \DeadCode \Graph \UsageOrigin ;
3737use SimpleXMLElement ;
3838use SplFileInfo ;
39+ use Symfony \UX \TwigComponent \Attribute \FromMethod ;
3940use UnexpectedValueException ;
4041use function array_filter ;
4142use function array_key_first ;
@@ -417,6 +418,21 @@ private function getMethodUsagesFromReflection(InClassNode $node): array
417418 }
418419 }
419420
421+ foreach (['Symfony\UX\TwigComponent\Attribute\AsTwigComponent ' , 'Symfony\UX\LiveComponent\Attribute\AsLiveComponent ' ] as $ twigComponentAttributeClass ) {
422+ foreach ($ nativeReflection ->getAttributes ($ twigComponentAttributeClass ) as $ twigComponentAttribute ) {
423+ $ twigComponentArguments = $ twigComponentAttribute ->getArguments ();
424+ $ template = $ twigComponentArguments ['template ' ] ?? $ twigComponentArguments [1 ] ?? null ;
425+
426+ if ($ template instanceof FromMethod) {
427+ $ templateMethodName = $ template ->method ;
428+
429+ if ($ classReflection ->hasNativeMethod ($ templateMethodName )) {
430+ $ usages [] = $ this ->createUsage ($ classReflection ->getNativeMethod ($ templateMethodName ), 'Twig component template method via FromMethod ' );
431+ }
432+ }
433+ }
434+ }
435+
420436 return $ usages ;
421437 }
422438
Original file line number Diff line number Diff line change @@ -107,3 +107,18 @@ public function getFieldName(): string { return 'field'; }
107107
108108 public function deadMethod (): void {} // error: Unused SymfonyUx\CustomActionComponent::deadMethod
109109}
110+
111+ #[AsTwigComponent(template: new \Symfony \UX \TwigComponent \Attribute \FromMethod ('getTemplatePath ' ))]
112+ class DynamicTemplateComponent
113+ {
114+ public function __construct () {}
115+
116+ public function mount (): void {}
117+
118+ public function getTemplatePath (): string
119+ {
120+ return 'components/dynamic.html.twig ' ;
121+ }
122+
123+ public function deadMethod (): void {} // error: Unused SymfonyUx\DynamicTemplateComponent::deadMethod
124+ }
You can’t perform that action at this time.
0 commit comments