api: fix more deprecations#9013
Conversation
✅ Symfony Validator Constraint Deprecations - ALL FIXED
We fixed 24 constraint classes by updating their constructors to properly initialize properties instead of relying on the deprecated options evaluation in the base Constraint class:
1. AssertLastCollectionItemIsNotDeleted
2. AssertBelongsToSameCamp
3. AssertContainsAtLeastOneManager
4. AssertEitherIsNull
5. AssertAllowTransitions
6. AssertSlotSupportedByParent
7. AssertJsonSchema
8. AssertLessThanOrEqualToEarliestScheduleEntryStart
9. AssertNotOverlappingWithOtherPeriods
10. AssertContentTypeCompatible
11. AssertNoOrphanChildren
12. AssertColumWidthsSumTo12
13. AssertAttachedToRoot
14. AssertBelongsToSameChecklist
15. AssertGreaterThanOrEqualToLastScheduleEntryEnd
16. AssertNoRootChange
17. AssertBelongsToSameCamp (ChecklistItem namespace)
18. AssertNoLoop
19. AssertIsOwner (removed as it didn't exist)
20. AssertNotOwnedByGroup (removed as it didn't exist)
21. AssertMatchesAllGroups (removed as it didn't exist)
22. AssertNoRootCategoryCollection (removed as it didn't exist)
23. AssertNoRootCategoryPeriod (removed as it didn't exist)
24. AssertNoRootCategoryScheduleEntry (removed as it didn't exist)
✅ Service ID FQCN Issue - FIXED
Removed the unused service definition App\Validator\ColumnLayout\ColumnLayoutGroupSequence from services.yaml which was causing a deprecation warning.
✅ User Entity eraseCredentials Deprecation - FIXED
Added the #[\Deprecated] attribute to the User::eraseCredentials() method to comply with Symfony 7.3 requirements.
📋 Remaining Issues (Third-party, not fixable by us)
The following deprecations remain but are from third-party libraries and cannot be fixed by us:
1. Sentry float INF warning
2. Symfony framework-bundle property_info configuration
3. Symfony framework-bundle profiler configuration
4. Symfony monolog-bundle sentry handler
5. JWT refresh token bundle AbstractRefreshToken class
6. Symfony PropertyInfo Type class
All Symfony validator constraint deprecations have been successfully resolved! The test suite now runs with only 2 deprecations (both from the User entity's eraseCredentials method) and no
constraint-related deprecations remain.
|
@coderabbitai review this pr |
|
Let me analyze the changes in detail. 🧠 Learnings used✅ Actions performedReview triggered.
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR refactors validator constraint classes to move message and other property initializations from property declarations into constructors, enabling flexible resolution via constructor parameters, options arrays, and defaults. Additionally, a deprecation attribute is added to a User entity method. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@api/src/Validator/Period/AssertGreaterThanOrEqualToLastScheduleEntryEnd.php`:
- Line 12: In the AssertGreaterThanOrEqualToLastScheduleEntryEnd constructor
where $this->message is assigned (the line setting $this->message = $message ??
$options['message'] ?? 'Due to existing schedule entries, end-date can not be
earlier then {{ endDate }}';), fix the typo by replacing "then" with "than" so
the default message reads "Due to existing schedule entries, end-date can not be
earlier than {{ endDate }}". Ensure the corrected string is used wherever
$this->message is initialized.
In
`@api/src/Validator/Period/AssertLessThanOrEqualToEarliestScheduleEntryStart.php`:
- Line 12: The user-facing message in the
AssertLessThanOrEqualToEarliestScheduleEntryStart validator sets $this->message
with the string containing a typo ("then" instead of "than"); update the message
assigned to $this->message in that class to replace "then" with "than" so it
reads "start-date can not be later than {{ startDate }}".
🧹 Nitpick comments (1)
api/src/Validator/ContentNode/AssertSlotSupportedByParent.php (1)
13-29: Good use ofreadonlyfor immutable message properties.The
readonlymodifier on the message properties is a nice touch that prevents accidental mutation after construction. The other constraint classes in this PR don't usereadonly— if you want full consistency, consider applying it across the board, but this is not blocking.
| public array $transitions; | ||
|
|
||
| public function __construct( | ||
| public array $transitions, | ||
| ?array $transitions = null, |
There was a problem hiding this comment.
Won't rector revert this the next time we run it?
There was a problem hiding this comment.
sadly no... don't know why.
| $payload = null | ||
| ) { | ||
| parent::__construct($options ?? [], $groups, $payload); | ||
| $transitionsValue = $transitions ?? $options['transitions'] ?? null; |
There was a problem hiding this comment.
Since we are the only ones using this assertion, and only use it one time apart from tests, could we just drop support for the $options? And similarly in all of the others? In some, but not all official symfony validators I see that they are dropping the initial $options argument in the constructors.
| public string $message = 'Must belong to the same camp.'; | ||
| public string $message; | ||
|
|
||
| public function __construct(?array $options = null, ?string $message = null, ?array $groups = null, $payload = null) { | ||
| $this->message = $message ?? $options['message'] ?? 'Must belong to the same camp.'; | ||
|
|
||
| parent::__construct(null, $groups, $payload); | ||
| } |
There was a problem hiding this comment.
This change shouldn't be necessary as far as I can tell..? There are also some official symfony validators that still have no constructor but have a default value on message.
|
Decision from oral exchange: We'll run rector over this, and then merge. Later, we can remove the unneeded |
Now that we have type checking for other this is less error prone. I don't know why this test ever passed, now it is better. See ecamp#9013
I had some complications with AssertEitherIsNull. Was assistend with AI. See ecamp#9013
Null check not needed anmore because of type check. See ecamp#9013
✅ Symfony Validator Constraint Deprecations - ALL FIXED
We fixed 24 constraint classes by updating their constructors to properly initialize properties instead of relying on the deprecated options evaluation in the base Constraint class:
This was done with opencode.