Skip to content

Conversation

@terabytesoftw
Copy link
Contributor

Pull Request

Q A
Is bugfix? ✔️
New feature?
Breaks BC?

@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Simplified attribute case handling and enhanced normalization logic for improved consistency.
  • Tests

    • Updated test cases and descriptions to reflect simplified attribute handling.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This PR simplifies the attributeCases() method in EnumDataProvider by removing the asHtml parameter. The method now unconditionally returns normalized attribute values with an expanded return structure containing separate attribute fragment and message fields. Tests and documentation are updated accordingly.

Changes

Cohort / File(s) Summary
Core Implementation
src/EnumDataProvider.php
Removed asHtml parameter from attributeCases() method; return array structure expanded from 4-tuple to 5-tuple {UnitEnum, mixed[], UnitEnum, string, string}. Updated normalizeValue() helper to accept `string
Test Updates
tests/EnumDataProviderTest.php, tests/Support/Provider/EnumDataProviderProvider.php
Adjusted test assertions to reflect new return array indices: expected value now at index [3] (was [2]) and message at [4] (was [3]). Updated test data provider description string to reflect attribute-focused behavior.
Documentation
CHANGELOG.md
Added changelog entry documenting Bug #16 simplification of attributeCases() method and normalization logic updates.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

bug

Poem

🐰 With asHtml gone, the path is clear,
Attributes now unified without fear,
Five values strong in structured array,
Simpler logic brightens the day! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: simplifying the attributeCases() method and updating normalization logic in the EnumDataProvider class, which aligns with all file changes in the PR.
Description check ✅ Passed The description confirms this is a bugfix that simplifies the attributeCases() method and updates normalization logic, directly relating to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
src/EnumDataProvider.php (1)

40-59: LGTM on the simplification!

The removal of the asHtml parameter and consistent normalization logic simplifies the method nicely. The return structure is now consistent.

One observation: $case appears at both index 0 and index 2 in the returned array. If this is intentional for testing flexibility, consider adding a brief inline comment clarifying the purpose of each array element.

tests/Support/Provider/EnumDataProviderProvider.php (1)

20-50: Unused asHtml parameter in test data.

The asHtml boolean (index 2) is still present in the test data, but EnumDataProvider::attributeCases() no longer accepts this parameter. While the test still uses it for conditional assertions, this creates confusion as it no longer reflects the actual API behavior.

Consider removing the asHtml field from the data provider and simplifying the test to always assert the attribute fragment and message, since the method now consistently returns the same structure.

♻️ Suggested simplification
     /**
-     * `@return` array<string, array{string, string|\UnitEnum, bool, string, string, string}>
+     * `@return` array<string, array{string, string|\UnitEnum, string, string, string}>
      */
     public static function casesParameters(): array
     {
         return [
             'as enum instance' => [
                 TestEnum::class,
                 'data-test',
-                false,
                 'enum: FOO',
                 ' data-test="FOO"',
                 "Should return the 'data-test' attribute value for enum case: FOO.",
             ],
-            'as html' => [
+            'second case' => [
                 TestEnum::class,
                 'data-test',
-                true,
                 'enum: BAR',
                 ' data-test="BAR"',
                 "Should return the 'data-test' attribute value for enum case: BAR.",
             ],
             'attribute as enum instance' => [
                 TestEnum::class,
                 TestEnum::FOO,
-                true,
                 'enum: FOO',
                 ' FOO="FOO"',
                 "Should return the 'FOO' attribute value for enum case: FOO.",
             ],
         ];
     }
tests/EnumDataProviderTest.php (2)

37-45: Consider removing unused $asHtml parameter.

The $asHtml parameter is still part of the test method signature (line 40) but EnumDataProvider::attributeCases() no longer accepts it. The parameter only controls conditional assertion logic (line 62) which may no longer be meaningful since the method always returns the same structure.


62-74: Index access is correct; conditional assertion is now vestigial.

The updated indices [3] and [4] correctly align with the new return structure from attributeCases().

However, since attributeCases() now always returns the attribute fragment (no more asHtml branching), the if ($asHtml) conditional (line 62) is now misleading. Consider removing it and always asserting the attribute value.

♻️ Suggested simplification
-        if ($asHtml) {
-            self::assertSame(
-                $expectedAttributeCase,
-                $data[$expectedKeyCase][3],
-                'Should return expected attribute value for enum case.',
-            );
-        }
+        self::assertSame(
+            $expectedAttributeCase,
+            $data[$expectedKeyCase][3],
+            'Should return expected attribute value for enum case.',
+        );
📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7bc7b3 and 55c73d9.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/EnumDataProvider.php
  • tests/EnumDataProviderTest.php
  • tests/Support/Provider/EnumDataProviderProvider.php
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: terabytesoftw
Repo: php-forge/support PR: 12
File: src/TestSupport.php:0-0
Timestamp: 2025-08-18T20:13:33.518Z
Learning: User terabytesoftw prefers clean trait-based designs over maintaining backward compatibility wrappers when refactoring utility classes in the php-forge/support project.
Learnt from: terabytesoftw
Repo: php-forge/actions PR: 65
File: .github/workflows/composer-require-checker.yml:80-83
Timestamp: 2025-09-28T15:12:48.345Z
Learning: The user terabytesoftw prefers using floating tags like v1 for third-party actions in GitHub workflows instead of pinning to specific commit SHAs, even when it's a security best practice to pin to immutable commits.
🧬 Code graph analysis (1)
tests/EnumDataProviderTest.php (1)
src/EnumDataProvider.php (2)
  • EnumDataProvider (25-104)
  • attributeCases (40-59)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: linter / Super Linter
  • GitHub Check: easy-coding-standard / PHP 8.4-ubuntu-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.1-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.1-windows-2022
  • GitHub Check: phpunit / PHP 8.4-ubuntu-latest
  • GitHub Check: linter / Super Linter
🔇 Additional comments (4)
CHANGELOG.md (1)

7-7: LGTM!

The changelog entry accurately documents the simplification and normalization changes, following the established format.

src/EnumDataProvider.php (2)

10-11: LGTM!

The is_string function import is correctly added for use in the normalizeValue helper.


86-103: LGTM!

The normalizeValue helper is well-designed:

  • Cleanly handles both string and UnitEnum inputs
  • Correctly differentiates between BackedEnum (uses value) and plain UnitEnum (uses name)
  • The match expression is idiomatic PHP 8+
tests/EnumDataProviderTest.php (1)

77-99: LGTM!

The testTagCasesGenerateExpectedStructure test remains correctly aligned with the unmodified tagCases() method.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added the bug Something isn't working label Jan 20, 2026
@terabytesoftw terabytesoftw merged commit 6bfcc77 into main Jan 20, 2026
42 checks passed
@terabytesoftw terabytesoftw deleted the fix_mini_3 branch January 20, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants