You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enforces that all public properties in Twig Components follow camelCase naming convention.
352
-
This ensures consistency and better integration with Twig templates where properties are passed and accessed using camelCase.
351
+
Enforces that methods with the `#[PostMount]` attribute have the correct signature: they must be public with an optional parameter of type `array`, and a return type of `array`, `void`, or `array|void`.
352
+
This ensures proper integration with the Symfony UX TwigComponent lifecycle hooks.
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
364
+
use Symfony\UX\TwigComponent\Attribute\PostMount;
364
365
365
366
#[AsTwigComponent]
366
367
final class Alert
367
368
{
368
-
public string $user_name;
369
-
public bool $is_active;
369
+
#[PostMount]
370
+
protected function postMount(): void
371
+
{
372
+
}
370
373
}
371
374
```
372
375
@@ -375,11 +378,33 @@ final class Alert
375
378
namespace App\Twig\Components;
376
379
377
380
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
381
+
use Symfony\UX\TwigComponent\Attribute\PostMount;
378
382
379
383
#[AsTwigComponent]
380
384
final class Alert
381
385
{
382
-
public string $UserName;
386
+
#[PostMount]
387
+
public function postMount(array $data): string
388
+
{
389
+
return 'invalid';
390
+
}
391
+
}
392
+
```
393
+
394
+
```php
395
+
// src/Twig/Components/Alert.php
396
+
namespace App\Twig\Components;
397
+
398
+
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
399
+
use Symfony\UX\TwigComponent\Attribute\PostMount;
400
+
401
+
#[AsTwigComponent]
402
+
final class Alert
403
+
{
404
+
#[PostMount]
405
+
public function postMount(string $data): void
406
+
{
407
+
}
383
408
}
384
409
```
385
410
@@ -392,12 +417,33 @@ final class Alert
392
417
namespace App\Twig\Components;
393
418
394
419
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
420
+
use Symfony\UX\TwigComponent\Attribute\PostMount;
395
421
396
422
#[AsTwigComponent]
397
423
final class Alert
398
424
{
399
-
public string $userName;
400
-
public bool $isActive;
425
+
#[PostMount]
426
+
public function postMount(): void
427
+
{
428
+
}
429
+
}
430
+
```
431
+
432
+
```php
433
+
// src/Twig/Components/Alert.php
434
+
namespace App\Twig\Components;
435
+
436
+
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
437
+
use Symfony\UX\TwigComponent\Attribute\PostMount;
438
+
439
+
#[AsTwigComponent]
440
+
final class Alert
441
+
{
442
+
#[PostMount]
443
+
public function postMount(array $data): array
444
+
{
445
+
return $data;
446
+
}
401
447
}
402
448
```
403
449
@@ -407,7 +453,7 @@ final class Alert
407
453
408
454
### PreMountMethodSignatureRule
409
455
410
-
Enforces that methods with the `#[PreMount]` attribute have the correct signature: they must be public and have exactly one parameter of type `array`, with a return type of `array`.
456
+
Enforces that methods with the `#[PreMount]` attribute have the correct signature: they must be public and have exactly one parameter of type `array`, with a return type of `array`, `void`, or `array|void`.
411
457
This ensures proper integration with the Symfony UX TwigComponent lifecycle hooks.
412
458
413
459
```yaml
@@ -444,12 +490,17 @@ use Symfony\UX\TwigComponent\Attribute\PreMount;
444
490
final class Alert
445
491
{
446
492
#[PreMount]
447
-
public function preMount(array $data): void
493
+
public function preMount(string $data): array
448
494
{
495
+
return [];
449
496
}
450
497
}
451
498
```
452
499
500
+
:x:
501
+
502
+
<br>
503
+
453
504
```php
454
505
// src/Twig/Components/Alert.php
455
506
namespace App\Twig\Components;
@@ -461,34 +512,71 @@ use Symfony\UX\TwigComponent\Attribute\PreMount;
461
512
final class Alert
462
513
{
463
514
#[PreMount]
464
-
public function preMount(string $data): array
515
+
public function preMount(array $data): array
465
516
{
466
-
return [];
517
+
$data['timestamp'] = time();
518
+
519
+
return $data;
467
520
}
468
521
}
469
522
```
470
523
471
-
:x:
524
+
:+1:
472
525
473
526
<br>
474
527
528
+
### PublicPropertiesShouldBeCamelCaseRule
529
+
530
+
Enforces that all public properties in Twig Components follow camelCase naming convention.
531
+
This ensures consistency and better integration with Twig templates where properties are passed and accessed using camelCase.
// Check parameter count and type (0 or 1 parameter allowed)
81
+
if (count($methodParams) > 1) {
82
+
$errors[] = RuleErrorBuilder::message(sprintf('Method "%s" with #[PostMount] attribute must have at most one parameter of type "array".', $methodName))
$errors[] = RuleErrorBuilder::message(sprintf('Method "%s" with #[PostMount] attribute must have a return type of "array", "void", or "array|void".', $methodName))
0 commit comments