-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add ExposePublicPropsShouldBeFalseRule
#3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Kocal
commented
Nov 23, 2025
| Q | A |
|---|---|
| Bug fix? | no |
| New feature? | yes |
| Tests pass? | yes |
| Fixed tickets | Close #... |
05bb612 to
25f0c74
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds a new PHPStan rule ExposePublicPropsShouldBeFalseRule to enforce that Twig components explicitly set exposePublicProps: false in the #[AsTwigComponent] attribute. This promotes explicit control over which properties are exposed to Twig templates, improving security and maintainability of Symfony UX Twig components.
Key Changes:
- Adds new PHPStan rule that validates the
exposePublicPropsparameter in#[AsTwigComponent]attributes - Includes comprehensive test coverage with fixtures for various scenarios
- Adds documentation to README following the established pattern for rule documentation
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Rules/TwigComponent/ExposePublicPropsShouldBeFalseRule.php |
New rule implementation that checks if exposePublicProps is explicitly set to false in #[AsTwigComponent] attributes |
tests/Rules/TwigComponent/ExposePublicPropsShouldBeFalseRule/ExposePublicPropsShouldBeFalseRuleTest.php |
Test class with separate methods for violations and no-violations scenarios |
tests/Rules/TwigComponent/ExposePublicPropsShouldBeFalseRule/config/configured_rule.neon |
Configuration file for test setup |
tests/Rules/TwigComponent/ExposePublicPropsShouldBeFalseRule/Fixture/NotAComponent.php |
Fixture for testing that non-component classes are ignored |
tests/Rules/TwigComponent/ExposePublicPropsShouldBeFalseRule/Fixture/ComponentWithoutExposePublicProps.php |
Fixture for testing violation when exposePublicProps is not set |
tests/Rules/TwigComponent/ExposePublicPropsShouldBeFalseRule/Fixture/ComponentWithExposePublicPropsTrue.php |
Fixture for testing violation when exposePublicProps is set to true |
tests/Rules/TwigComponent/ExposePublicPropsShouldBeFalseRule/Fixture/ComponentWithExposePublicPropsFalse.php |
Fixture for testing valid case where exposePublicProps is set to false |
README.md |
Documentation for the new rule with examples showing violations and correct usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| RuleErrorBuilder::message('The #[AsTwigComponent] attribute must have its "exposePublicProps" parameter set to false.') | ||
| ->identifier('symfonyUX.twigComponent.exposePublicPropsShouldBeFalse') | ||
| ->line($asTwigComponent->getLine()) | ||
| ->tip('Add "exposePublicProps: false" to the #[AsTwigComponent] attribute.') |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tip message "Add" is misleading when exposePublicProps is already set to true. Consider using "Set" instead of "Add" to cover both cases (when the parameter is missing and when it's set to true).
Suggested change:
->tip('Set "exposePublicProps" to false in the #[AsTwigComponent] attribute.')| ->tip('Add "exposePublicProps: false" to the #[AsTwigComponent] attribute.') | |
| ->tip('Set "exposePublicProps" to false in the #[AsTwigComponent] attribute.') |
25f0c74 to
8dad96c
Compare