Skip to content

chore(phpstan): correct CustomAttribute parameter types - #1895

Merged
JohnVillalovos merged 1 commit into
developfrom
jlvillal/phpstan
Nov 10, 2026
Merged

JohnVillalovos merged 1 commit into
developfrom
jlvillal/phpstan

Conversation

@JohnVillalovos

@JohnVillalovos JohnVillalovos commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

The CustomAttribute PHPDoc did not match how the class is used, which produced about 100 level-5 argument.type errors:

  • regex and possible_values are nullable columns, Create() passes a null id, and WithSecondaryEntities(null, null) clears the secondary scope. Document those as nullable.
  • FromRow() and WithSecondaryEntities() kept entity IDs split from database strings as strings. Convert them to int, as documented. The API's appliesToIds and secondaryEntityIds now return integers, matching CustomAttributeDefinitionResponse's int[] types and examples.
    Document the response's regex and secondaryCategoryId as nullable.
  • AttributeSaveController passed (int) for the bool $required.

Fix tests that passed null labels, sort orders and required flags, or a bare int where an array of entity IDs is expected.

Assisted-by: Claude:claude-opus-5-5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

An active moderate issue remains because WithSecondaryEntities() returns secondary entity IDs as strings despite the documented int[] API.

1 open issue
What changed in this PR

This PR corrects the PHPDoc types for CustomAttribute so they match how the class is really used. That clears about 100 PHPStan level-5 argument.type errors. The main changes are nullable regex and possibleValues, integer entity IDs from FromRow(), a boolean required flag in the API save controller, and test fixtures updated to pass the right types.

Changes:

  • Marks regex, possibleValues, and id as nullable in CustomAttribute docblocks, and documents that WithSecondaryEntities() accepts null to clear the secondary scope.
  • Converts primary entity IDs from FromRow() to integers, and casts required to a boolean in AttributeSaveController.
  • Updates test fixtures to pass valid types, such as false for required, integer sort orders, and arrays of entity IDs.

Open issue: FromRow() still returns secondary entity IDs as strings. Converting them is needed to match the documented int[] type.

File Description
WebServices/​Controllers/​AttributeSaveController.php Casts required to bool instead of int, matching the bool parameter.
tests/​Presenters/​Reservation/​ReservationAttributesPresenterTest.php Passes secondary entity IDs as arrays.
tests/​Presenters/​Admin/​ManageAttributesPresenterTest.php Replaces null sort order and entity IDs with valid values.
tests/​Domain/​Attribute/​CustomAttributeTest.php Replaces null labels and sort orders with valid values.
tests/​Domain/​Attribute/​AttributeRepositoryTest.php Uses integer sort orders and wraps entity IDs in arrays.
tests/​Application/​Schedule/​ScheduleResourceFilterTest.php Wraps entity IDs in arrays to match the new constructor type.
tests/​Application/​Reservation/​CustomAttributeValidationRuleTest.php Passes secondary entity IDs as arrays.
tests/​Application/​Attributes/​AttributeServiceTest.php Replaces null required flags and sort orders, and wraps IDs in arrays.
Domain/​CustomAttribute.php Updates docblocks to nullable types and converts FromRow() primary IDs to integers.

Review effort: Lite

Comment thread Domain/CustomAttribute.php Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active moderate issues leave the API response contracts inconsistent with nullable domain values, and a test does not verify entity ID conversion.

3 open issues
1 resolved since last review

Review effort: Lite

Comment thread Domain/CustomAttribute.php Resolved
Comment thread Domain/CustomAttribute.php Resolved
The CustomAttribute PHPDoc did not match how the class is used, which
produced about 100 level-5 argument.type errors:

- regex and possible_values are nullable columns, Create() passes a
  null id, and WithSecondaryEntities(null, null) clears the secondary
  scope. Document those as nullable.
- FromRow() and WithSecondaryEntities() kept entity IDs split from
  database strings as strings. Convert them to int, as documented. The
  API's appliesToIds and secondaryEntityIds now return integers,
  matching CustomAttributeDefinitionResponse's int[] types and examples.
- AttributeSaveController passed (int) for the bool $required.

Fix tests that passed null labels, sort orders and required flags, or
a bare int where an array of entity IDs is expected.

Assisted-by: Claude:claude-opus-5-5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The changes align nullable and scalar PHPDoc types and normalize entity IDs to integers, with corresponding test updates covering the corrected contracts.

No open issues 🎉

3 resolved since last review

Review effort: Lite

@JohnVillalovos
JohnVillalovos merged commit 499d2e0 into develop Nov 10, 2026
18 checks passed
@JohnVillalovos
JohnVillalovos deleted the jlvillal/phpstan branch November 10, 2026 05:36
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