Skip to content

Commit 0746480

Browse files
authored
Merge pull request #21 from Kocal/rename-rules
2 parents 949b94c + 06f379d commit 0746480

File tree

64 files changed

+166
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+166
-111
lines changed

README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ Each rule can be enabled individually by adding it to your `phpstan.neon` or `ph
2929

3030
## LiveComponent Rules
3131

32-
### LiveActionMethodsShouldBePublicRule
32+
### LiveActionMethodsVisibilityRule
3333

3434
Enforces that all methods annotated with `#[LiveAction]` in LiveComponents must be declared as public.
3535
LiveAction methods need to be publicly accessible to be invoked as component actions from the frontend.
3636

3737
```yaml
3838
rules:
39-
- Kocal\PHPStanSymfonyUX\Rules\LiveComponent\LiveActionMethodsShouldBePublicRule
39+
- Kocal\PHPStanSymfonyUX\Rules\LiveComponent\LiveActionMethodsVisibilityRule
4040
```
4141

42+
> **Note:** The rule `LiveActionMethodsShouldBePublicRule` is deprecated and will be removed in version 2.0. Use `LiveActionMethodsVisibilityRule` instead.
43+
4244
```php
4345
// src/Twig/Components/TodoList.php
4446
namespace App\Twig\Components;
@@ -103,16 +105,18 @@ final class TodoList
103105

104106
<br>
105107

106-
### LiveListenerMethodsShouldBePublicRule
108+
### LiveListenerMethodsVisibilityRule
107109

108110
Enforces that all methods annotated with `#[LiveListener]` in LiveComponents must be declared as public.
109111
LiveListener methods need to be publicly accessible to be invoked when listening to events from the frontend.
110112

111113
```yaml
112114
rules:
113-
- Kocal\PHPStanSymfonyUX\Rules\LiveComponent\LiveListenerMethodsShouldBePublicRule
115+
- Kocal\PHPStanSymfonyUX\Rules\LiveComponent\LiveListenerMethodsVisibilityRule
114116
```
115117

118+
> **Note:** The rule `LiveListenerMethodsShouldBePublicRule` is deprecated and will be removed in version 2.0. Use `LiveListenerMethodsVisibilityRule` instead.
119+
116120
```php
117121
// src/Twig/Components/Notification.php
118122
namespace App\Twig\Components;
@@ -448,15 +452,17 @@ final class Alert
448452

449453
<br>
450454

451-
### ClassNameShouldNotEndWithComponentRule
455+
### ClassNameMustNotEndWithComponentRule
452456

453457
Forbid Twig Component class names from ending with "Component" suffix, as it creates redundancy since the class is already identified as a component through the `#[AsTwigComponent]` attribute.
454458

455459
```yaml
456460
rules:
457-
- Kocal\PHPStanSymfonyUX\Rules\TwigComponent\ClassNameShouldNotEndWithComponentRule
461+
- Kocal\PHPStanSymfonyUX\Rules\TwigComponent\ClassNameMustNotEndWithComponentRule
458462
```
459463

464+
> **Note:** The rule `ClassNameShouldNotEndWithComponentRule` is deprecated and will be removed in version 2.0. Use `ClassNameMustNotEndWithComponentRule` instead.
465+
460466
```php
461467
// src/Twig/Components/AlertComponent.php
462468
namespace App\Twig\Components;
@@ -489,16 +495,18 @@ final class Alert
489495

490496
<br>
491497

492-
### ExposePublicPropsShouldBeFalseRule
498+
### ExposePublicPropsMustBeFalseRule
493499

494500
Enforces that the `#[AsTwigComponent]` attribute has its `exposePublicProps` parameter explicitly set to `false`.
495501
This prevents public properties from being automatically exposed to templates, promoting explicit control over what data is accessible in your Twig components.
496502

497503
```yaml
498504
rules:
499-
- Kocal\PHPStanSymfonyUX\Rules\TwigComponent\ExposePublicPropsShouldBeFalseRule
505+
- Kocal\PHPStanSymfonyUX\Rules\TwigComponent\ExposePublicPropsMustBeFalseRule
500506
```
501507

508+
> **Note:** The rule `ExposePublicPropsShouldBeFalseRule` is deprecated and will be removed in version 2.0. Use `ExposePublicPropsMustBeFalseRule` instead.
509+
502510
```php
503511
// src/Twig/Components/Alert.php
504512
namespace App\Twig\Components;
@@ -657,7 +665,7 @@ final class Alert
657665

658666
<br>
659667

660-
### MethodsShouldBePublicOrPrivateRule
668+
### MethodsVisibilityRule
661669

662670
Enforces that all methods in Twig Components are either public or private, but not protected.
663671
Since Twig Components must be final classes and inheritance is forbidden (see `ForbiddenInheritanceRule`), protected methods serve no purpose and should be avoided.
@@ -666,9 +674,11 @@ Since Twig Components must be final classes and inheritance is forbidden (see `F
666674

667675
```yaml
668676
rules:
669-
- Kocal\PHPStanSymfonyUX\Rules\TwigComponent\MethodsShouldBePublicOrPrivateRule
677+
- Kocal\PHPStanSymfonyUX\Rules\TwigComponent\MethodsVisibilityRule
670678
```
671679

680+
> **Note:** The rule `MethodsShouldBePublicOrPrivateRule` is deprecated and will be removed in version 2.0. Use `MethodsVisibilityRule` instead.
681+
672682
```php
673683
// src/Twig/Components/Alert.php
674684
namespace App\Twig\Components;
@@ -924,16 +934,18 @@ final class Alert
924934

925935
<br>
926936

927-
### PublicPropertiesShouldBeCamelCaseRule
937+
### PublicPropertiesMustBeCamelCaseRule
928938

929939
Enforces that all public properties in Twig Components follow camelCase naming convention.
930940
This ensures consistency and better integration with Twig templates where properties are passed and accessed using camelCase.
931941

932942
```yaml
933943
rules:
934-
- Kocal\PHPStanSymfonyUX\Rules\TwigComponent\PublicPropertiesShouldBeCamelCaseRule
944+
- Kocal\PHPStanSymfonyUX\Rules\TwigComponent\PublicPropertiesMustBeCamelCaseRule
935945
```
936946

947+
> **Note:** The rule `PublicPropertiesShouldBeCamelCaseRule` is deprecated and will be removed in version 2.0. Use `PublicPropertiesMustBeCamelCaseRule` instead.
948+
937949
```php
938950
// src/Twig/Components/Alert.php
939951
namespace App\Twig\Components;

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
"autoload": {
2424
"psr-4": {
2525
"Kocal\\PHPStanSymfonyUX\\": "src/"
26-
}
26+
},
27+
"files": [
28+
"src/deprecated-aliases.php"
29+
]
2730
},
2831
"autoload-dev": {
2932
"psr-4": {

src/Rules/LiveComponent/LiveActionMethodsShouldBePublicRule.php renamed to src/Rules/LiveComponent/LiveActionMethodsVisibilityRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @implements Rule<Class_>
1818
*/
19-
final class LiveActionMethodsShouldBePublicRule implements Rule
19+
class LiveActionMethodsVisibilityRule implements Rule
2020
{
2121
public function getNodeType(): string
2222
{
@@ -42,7 +42,7 @@ public function processNode(Node $node, Scope $scope): array
4242
$errors[] = RuleErrorBuilder::message(
4343
sprintf('LiveAction method "%s()" must be public.', $methodName)
4444
)
45-
->identifier('symfonyUX.liveComponent.liveActionMethodsShouldBePublic')
45+
->identifier('symfonyUX.liveComponent.liveActionMethodsVisibility')
4646
->line($method->getLine())
4747
->tip('Methods annotated with #[LiveAction] must be public to be accessible as component actions.')
4848
->build();

src/Rules/LiveComponent/LiveListenerMethodsShouldBePublicRule.php renamed to src/Rules/LiveComponent/LiveListenerMethodsVisibilityRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @implements Rule<Class_>
1818
*/
19-
final class LiveListenerMethodsShouldBePublicRule implements Rule
19+
class LiveListenerMethodsVisibilityRule implements Rule
2020
{
2121
public function getNodeType(): string
2222
{
@@ -41,7 +41,7 @@ public function processNode(Node $node, Scope $scope): array
4141
'LiveListener method "%s()" must be public.',
4242
$method->name->toString()
4343
))
44-
->identifier('symfonyUX.liveComponent.liveListenerMethodShouldBePublic')
44+
->identifier('symfonyUX.liveComponent.liveListenerMethodsVisibility')
4545
->line($method->getLine())
4646
->tip('Change the method visibility to public.')
4747
->build();

src/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule.php renamed to src/Rules/TwigComponent/ClassNameMustNotEndWithComponentRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @implements Rule<Class_>
1818
*/
19-
final class ClassNameShouldNotEndWithComponentRule implements Rule
19+
class ClassNameMustNotEndWithComponentRule implements Rule
2020
{
2121
public function getNodeType(): string
2222
{
@@ -38,7 +38,7 @@ public function processNode(Node $node, Scope $scope): array
3838
if (str_ends_with($classNameString, 'Component')) {
3939
return [
4040
RuleErrorBuilder::message(sprintf('Twig component class "%s" must not end with "Component".', $classNameString))
41-
->identifier('symfonyUX.twigComponent.classNameShouldNotEndWithComponent')
41+
->identifier('symfonyUX.twigComponent.classNameMustNotEndWithComponent')
4242
->line($className->getLine())
4343
->tip('Remove the "Component" suffix from the class name.')
4444
->build(),

src/Rules/TwigComponent/ExposePublicPropsShouldBeFalseRule.php renamed to src/Rules/TwigComponent/ExposePublicPropsMustBeFalseRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @implements Rule<Class_>
1818
*/
19-
final class ExposePublicPropsShouldBeFalseRule implements Rule
19+
class ExposePublicPropsMustBeFalseRule implements Rule
2020
{
2121
public function getNodeType(): string
2222
{
@@ -37,7 +37,7 @@ public function processNode(Node $node, Scope $scope): array
3737
'The #[%s] attribute must have its "exposePublicProps" parameter set to false.',
3838
$attribute->name->getLast(),
3939
))
40-
->identifier('symfonyUX.twigComponent.exposePublicPropsShouldBeFalse')
40+
->identifier('symfonyUX.twigComponent.exposePublicPropsMustBeFalse')
4141
->line($attribute->getLine())
4242
->tip(sprintf(
4343
'Set "exposePublicProps" to false in the #[%s] attribute.',

src/Rules/TwigComponent/MethodsShouldBePublicOrPrivateRule.php renamed to src/Rules/TwigComponent/MethodsVisibilityRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* @implements Rule<Class_>
2020
*/
21-
final class MethodsShouldBePublicOrPrivateRule implements Rule
21+
class MethodsVisibilityRule implements Rule
2222
{
2323
public function __construct(
2424
private ReflectionProvider $reflectionProvider,
@@ -64,7 +64,7 @@ public function processNode(Node $node, Scope $scope): array
6464
$errors[] = RuleErrorBuilder::message(
6565
sprintf('Method "%s()" in a Twig component must not be protected.', $methodName)
6666
)
67-
->identifier('symfonyUX.twigComponent.methodsShouldBePublicOrPrivate')
67+
->identifier('symfonyUX.twigComponent.methodsVisibility')
6868
->line($method->getLine())
6969
->tip('Twig component methods should be either public or private, not protected.')
7070
->build();
@@ -113,7 +113,7 @@ public function processNode(Node $node, Scope $scope): array
113113
$errors[] = RuleErrorBuilder::message(
114114
sprintf('Method "%s()" in a Twig component must not be protected.', $methodName)
115115
)
116-
->identifier('symfonyUX.twigComponent.methodsShouldBePublicOrPrivate')
116+
->identifier('symfonyUX.twigComponent.methodsVisibility')
117117
->line($lineNumber)
118118
->tip('Twig component methods should be either public or private, not protected.')
119119
->build();

src/Rules/TwigComponent/PublicPropertiesShouldBeCamelCaseRule.php renamed to src/Rules/TwigComponent/PublicPropertiesMustBeCamelCaseRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @implements Rule<Class_>
1818
*/
19-
final class PublicPropertiesShouldBeCamelCaseRule implements Rule
19+
class PublicPropertiesMustBeCamelCaseRule implements Rule
2020
{
2121
public function getNodeType(): string
2222
{
@@ -43,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array
4343
$errors[] = RuleErrorBuilder::message(
4444
sprintf('Public property "%s" in a Twig component must be in camelCase.', $propertyName)
4545
)
46-
->identifier('symfonyUX.twigComponent.publicPropertiesShouldBeCamelCase')
46+
->identifier('symfonyUX.twigComponent.publicPropertiesMustBeCamelCase')
4747
->line($property->getLine())
4848
->tip(sprintf('Consider renaming "%s" to "%s".', $propertyName, $this->toCamelCase($propertyName)))
4949
->build();

src/deprecated-aliases.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Deprecated class aliases for backward compatibility.
7+
* These aliases will be removed in version 2.0.
8+
*/
9+
10+
// LiveComponent rules
11+
class_alias(
12+
\Kocal\PHPStanSymfonyUX\Rules\LiveComponent\LiveActionMethodsVisibilityRule::class,
13+
\Kocal\PHPStanSymfonyUX\Rules\LiveComponent\LiveActionMethodsShouldBePublicRule::class
14+
);
15+
16+
class_alias(
17+
\Kocal\PHPStanSymfonyUX\Rules\LiveComponent\LiveListenerMethodsVisibilityRule::class,
18+
\Kocal\PHPStanSymfonyUX\Rules\LiveComponent\LiveListenerMethodsShouldBePublicRule::class
19+
);
20+
21+
// TwigComponent rules
22+
class_alias(
23+
\Kocal\PHPStanSymfonyUX\Rules\TwigComponent\MethodsVisibilityRule::class,
24+
\Kocal\PHPStanSymfonyUX\Rules\TwigComponent\MethodsShouldBePublicOrPrivateRule::class
25+
);
26+
27+
class_alias(
28+
\Kocal\PHPStanSymfonyUX\Rules\TwigComponent\PublicPropertiesMustBeCamelCaseRule::class,
29+
\Kocal\PHPStanSymfonyUX\Rules\TwigComponent\PublicPropertiesShouldBeCamelCaseRule::class
30+
);
31+
32+
class_alias(
33+
\Kocal\PHPStanSymfonyUX\Rules\TwigComponent\ClassNameMustNotEndWithComponentRule::class,
34+
\Kocal\PHPStanSymfonyUX\Rules\TwigComponent\ClassNameShouldNotEndWithComponentRule::class
35+
);
36+
37+
class_alias(
38+
\Kocal\PHPStanSymfonyUX\Rules\TwigComponent\ExposePublicPropsMustBeFalseRule::class,
39+
\Kocal\PHPStanSymfonyUX\Rules\TwigComponent\ExposePublicPropsShouldBeFalseRule::class
40+
);

tests/Rules/LiveComponent/LiveActionMethodsShouldBePublicRule/Fixture/LiveComponentWithPrivateLiveAction.php renamed to tests/Rules/LiveComponent/LiveActionMethodsVisibilityRule/Fixture/LiveComponentWithPrivateLiveAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Kocal\PHPStanSymfonyUX\Tests\Rules\LiveComponent\LiveActionMethodsShouldBePublicRule\Fixture;
5+
namespace Kocal\PHPStanSymfonyUX\Tests\Rules\LiveComponent\LiveActionMethodsVisibilityRule\Fixture;
66

77
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
88
use Symfony\UX\LiveComponent\Attribute\LiveAction;

0 commit comments

Comments
 (0)