Skip to content

Conversation

@Kocal
Copy link
Owner

@Kocal Kocal commented Nov 23, 2025

Q A
Bug fix? no
New feature? yes
Tests pass? yes
Fixed tickets Close #...

Proudly vibe-coded

@Kocal Kocal self-assigned this Nov 23, 2025
@Kocal Kocal force-pushed the ComponentClassNameShouldNotEndWithComponentRule branch 2 times, most recently from 98c95e9 to 59baf89 Compare November 23, 2025 10:31
@Kocal Kocal changed the title Add ComponentClassNameShouldNotEndWithComponentRule Add ClassNameShouldNotEndWithComponentRule Nov 23, 2025
@Kocal Kocal requested a review from Copilot November 23, 2025 10:32
Copilot finished reviewing on behalf of Kocal November 23, 2025 10:34
Copy link

Copilot AI left a 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 PR adds a new PHPStan rule ClassNameShouldNotEndWithComponentRule that enforces a naming convention for Symfony UX Twig Components. The rule prevents developers from using redundant "Component" suffixes in class names since the #[AsTwigComponent] attribute already identifies the class as a component.

Key Changes

  • Implements ClassNameShouldNotEndWithComponentRule to detect and report classes ending with "Component" suffix
  • Adds comprehensive test coverage with valid, invalid, and non-component test cases
  • Updates README with documentation and examples following existing patterns
  • Adds AGENTS.md file with detailed instructions for creating new PHPStan rules in this project

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule.php Main rule implementation that checks for "Component" suffix in Twig component class names
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/ClassNameShouldNotEndWithComponentRuleTest.php Test suite with violation and no-violation test cases
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/Fixture/InvalidComponentName.php Test fixture demonstrating invalid class name (AlertComponent)
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/Fixture/ValidComponentName.php Test fixture demonstrating valid class name (Alert)
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/Fixture/NotAComponent.php Test fixture for non-component class to ensure rule doesn't trigger
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/config/configured_rule.neon PHPStan configuration for the test environment
README.md Documentation for the new rule with examples showing both invalid and valid usage
AGENTS.md Comprehensive guide for AI agents and developers on creating new PHPStan rules in this project

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (str_ends_with($classNameString, 'Component')) {
return [
RuleErrorBuilder::message(sprintf('Twig component class "%s" should not end with "Component".', $classNameString))
->identifier('symfonyUX.twigComponent.classNameShouldNotEndWithComponent')
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The identifier casing is inconsistent with other rules in this codebase. ForbiddenClassPropertyRule uses symfonyUX.twigComponent.forbiddenClassProperty (lowercase 'symfonyUX'), while ForbiddenAttributesPropertyRule uses SymfonyUX.TwigComponent.forbiddenAttributesProperty (uppercase 'SymfonyUX').

This rule follows the lowercase convention, but there should be consistency across all rules. Consider standardizing on one casing pattern (e.g., symfonyUX.twigComponent.classNameShouldNotEndWithComponent).

Suggested change
->identifier('symfonyUX.twigComponent.classNameShouldNotEndWithComponent')
->identifier('SymfonyUX.TwigComponent.classNameShouldNotEndWithComponent')

Copilot uses AI. Check for mistakes.
@Kocal Kocal force-pushed the ComponentClassNameShouldNotEndWithComponentRule branch from 59baf89 to a9344a3 Compare November 23, 2025 10:37
@Kocal Kocal merged commit 1553924 into main Nov 23, 2025
8 checks passed
@Kocal Kocal deleted the ComponentClassNameShouldNotEndWithComponentRule branch November 23, 2025 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants