From 5be85a4fc6d1f51a65bdfb6700f2657bd99f7a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 8 Apr 2024 12:11:29 +0200 Subject: [PATCH] Refactored code to use PHP8 attributes instead of annotations In this change, Doctrine and validation annotations have been replaced with PHP8 Attributes. The Rector tool has been configured with a list of annotations to convert to attributes. As a consequence, the PHPStan's rules have been updated to reflect these changes. The PHP8's nullable operator (?) has been added where required, and comments in field declaration have been replaced with #[Attribute] syntax. --- MIGRATION.md | 42 ++ ...an-baseline-deprecations-doctrine-orm.neon | 50 +++ phpstan-deprecations-sf54.neon | 422 ------------------ phpstan.neon.dist | 1 + rector.php | 19 + .../ChillActivityBundle/Entity/Activity.php | 10 +- .../Constraints/ActivityValidity.php | 4 +- .../Entity/CustomFieldsGroup.php | 3 +- .../Entity/StoredObject.php | 5 +- .../Validator/Constraints/AsyncFileExists.php | 10 +- .../ChillMainBundle/Entity/Location.php | 8 +- .../ChillMainBundle/Entity/Notification.php | 3 +- src/Bundle/ChillMainBundle/Entity/User.php | 3 +- .../Entity/Workflow/EntityWorkflow.php | 4 +- .../Tests/Export/SortExportElementTest.php | 2 +- .../Constraint/PhonenumberConstraint.php | 12 +- .../Entity/UserCircleConsistency.php | 4 +- .../Validator/EntityWorkflowCreation.php | 3 +- .../Entity/AccompanyingPeriod.php | 15 +- .../AccompanyingPeriodWork.php | 3 +- .../Entity/Household/Household.php | 4 +- .../ChillPersonBundle/Entity/Person.php | 19 +- .../Entity/Relationships/Relationship.php | 4 +- .../ByStepAggregatorTest.php | 2 +- .../AccompanyingPeriodValidity.php | 4 +- .../ConfidentialCourseMustHaveReferrer.php | 4 +- .../AccompanyingPeriod/LocationValidity.php | 4 +- .../ParticipationOverlap.php | 4 +- .../ResourceDuplicateCheck.php | 4 +- .../HouseholdMembershipSequential.php | 4 +- .../Constraints/Household/MaxHolder.php | 4 +- .../Constraints/Person/Birthdate.php | 3 +- .../Constraints/Person/PersonHasCenter.php | 4 +- .../Relationship/RelationshipNoDuplicate.php | 4 +- .../Entity/ThirdParty.php | 4 +- 35 files changed, 164 insertions(+), 531 deletions(-) create mode 100644 phpstan-baseline-deprecations-doctrine-orm.neon diff --git a/MIGRATION.md b/MIGRATION.md index deab7b449..b3e867402 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -5,3 +5,45 @@ **Note**: It is not necessary to apply this tag on service definition: the tag is automatically applyied if the service implements `\Chill\MainBundle\Security\ProvideRoleInterface`. + +- those annotation can be converted to attribute: + + - `Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\AccompanyingPeriodValidity` + - `Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequential` + - `Chill\PersonBundle\Validator\Constraints\Household\MaxHolder` + - `Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ConfidentialCourseMustHaveReferrer` + - `Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\LocationValidity` + - `Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ParticipationOverlap` + - `Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ResourceDuplicateCheck` + - `Chill\PersonBundle\Validator\Constraints\Person\Birthdate` + - `Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter` + - `Chill\PersonBundle\Validator\Constraints\Relationship\RelationshipNoDuplicate` + - `Chill\ActivityBundle\Validator\Constraints\ActivityValidity` + - `Chill\DocStoreBundle\Validator\Constraints\AsyncFileExists` + - `Chill\MainBundle\Validation\Constraint\PhonenumberConstraint` + - `Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistency` + - `Chill\MainBundle\Workflow\Validator\EntityWorkflowCreation` + + Here is the rector rule that can be used to switch attributes to annotations: + + ```php + $rectorConfig->ruleWithConfiguration(\Rector\Php80\Rector\Class_\AnnotationToAttributeRector::class, [ + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\AccompanyingPeriodValidity'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequential'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Household\MaxHolder'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ConfidentialCourseMustHaveReferrer'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\LocationValidity'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ParticipationOverlap'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ResourceDuplicateCheck'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Person\Birthdate'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Relationship\RelationshipNoDuplicate'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\ActivityBundle\Validator\Constraints\ActivityValidity'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\DocStoreBundle\Validator\Constraints\AsyncFileExists'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\MainBundle\Validation\Constraint\PhonenumberConstraint'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistency'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\MainBundle\Workflow\Validator\EntityWorkflowCreation'), + ]); + ``` + + diff --git a/phpstan-baseline-deprecations-doctrine-orm.neon b/phpstan-baseline-deprecations-doctrine-orm.neon new file mode 100644 index 000000000..aad0db175 --- /dev/null +++ b/phpstan-baseline-deprecations-doctrine-orm.neon @@ -0,0 +1,50 @@ +# See https://github.com/doctrine/orm/issues/11313 for a follow-up +parameters: + ignoreErrors: + - + message: """ + #^Fetching deprecated class constant ASC of class Doctrine\\\\Common\\\\Collections\\\\Criteria\\: + use Order\\:\\:Ascending instead$# + """ + count: 1 + path: src/Bundle/ChillCustomFieldsBundle/Entity/CustomFieldsGroup.php + + - + message: """ + #^Fetching deprecated class constant ASC of class Doctrine\\\\Common\\\\Collections\\\\Criteria\\: + use Order\\:\\:Ascending instead$# + """ + count: 1 + path: src/Bundle/ChillMainBundle/Entity/Notification.php + + - + message: """ + #^Fetching deprecated class constant DESC of class Doctrine\\\\Common\\\\Collections\\\\Criteria\\: + use Order\\:\\:Descending instead$# + """ + count: 1 + path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php + + - + message: """ + #^Fetching deprecated class constant DESC of class Doctrine\\\\Common\\\\Collections\\\\Criteria\\: + use Order\\:\\:Descending instead$# + """ + count: 1 + path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php + + - + message: """ + #^Fetching deprecated class constant DESC of class Doctrine\\\\Common\\\\Collections\\\\Criteria\\: + use Order\\:\\:Descending instead$# + """ + count: 2 + path: src/Bundle/ChillPersonBundle/Entity/Household/Household.php + + - + message: """ + #^Fetching deprecated class constant DESC of class Doctrine\\\\Common\\\\Collections\\\\Criteria\\: + use Order\\:\\:Descending instead$# + """ + count: 2 + path: src/Bundle/ChillPersonBundle/Entity/Person.php diff --git a/phpstan-deprecations-sf54.neon b/phpstan-deprecations-sf54.neon index 019df1022..e2e5e85a6 100644 --- a/phpstan-deprecations-sf54.neon +++ b/phpstan-deprecations-sf54.neon @@ -1,53 +1,5 @@ parameters: ignoreErrors: - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 5 - path: src/Bundle/ChillActivityBundle/Controller/ActivityReasonCategoryController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 5 - path: src/Bundle/ChillActivityBundle/Controller/ActivityReasonController.php - - - - message: """ - #^Call to deprecated method getUsername\\(\\) of class Chill\\\\MainBundle\\\\Entity\\\\User\\: - since Symfony 5\\.3, use getUserIdentifier\\(\\) instead$# - """ - count: 2 - path: src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 3 - path: src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 4 - path: src/Bundle/ChillCalendarBundle/Controller/CalendarController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 4 - path: src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldController.php - - message: """ #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: @@ -56,86 +8,6 @@ parameters: count: 2 path: src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldsGroupController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 9 - path: src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldsGroupController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 4 - path: src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 7 - path: src/Bundle/ChillDocStoreBundle/Controller/DocumentCategoryController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 4 - path: src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php - - - - message: """ - #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, use method or constructor injection in your controller instead$# - """ - count: 2 - path: src/Bundle/ChillEventBundle/Controller/EventController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 6 - path: src/Bundle/ChillEventBundle/Controller/EventController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 6 - path: src/Bundle/ChillEventBundle/Controller/EventTypeController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 10 - path: src/Bundle/ChillEventBundle/Controller/ParticipationController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 6 - path: src/Bundle/ChillEventBundle/Controller/RoleController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 6 - path: src/Bundle/ChillEventBundle/Controller/StatusController.php - - message: """ #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: @@ -144,14 +16,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 2 - path: src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php - - message: """ #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: @@ -160,14 +24,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 7 - path: src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php - - message: """ #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: @@ -176,14 +32,6 @@ parameters: count: 3 path: src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 7 - path: src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php - - message: """ #^Call to deprecated method getUsername\\(\\) of class Chill\\\\MainBundle\\\\Entity\\\\User\\: @@ -192,14 +40,6 @@ parameters: count: 2 path: src/Bundle/ChillMainBundle/Command/ChillImportUsersCommand.php - - - message: """ - #^Parameter \\$passwordEncoder of method Chill\\\\MainBundle\\\\Command\\\\ChillImportUsersCommand\\:\\:__construct\\(\\) has typehint with deprecated interface Symfony\\\\Component\\\\Security\\\\Core\\\\Encoder\\\\UserPasswordEncoderInterface\\: - since Symfony 5\\.3, use \\{@link UserPasswordHasherInterface\\} instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Command/ChillImportUsersCommand.php - - message: """ #^Call to deprecated method getUsername\\(\\) of class Chill\\\\MainBundle\\\\Entity\\\\User\\: @@ -216,30 +56,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Command/SetPasswordCommand.php - - - message: """ - #^Instantiation of deprecated class Symfony\\\\Component\\\\Security\\\\Core\\\\Encoder\\\\MessageDigestPasswordEncoder\\: - since Symfony 5\\.3, use \\{@link MessageDigestPasswordHasher\\} instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Command/SetPasswordCommand.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 2 - path: src/Bundle/ChillMainBundle/Controller/AbsenceController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Controller/AddressApiController.php - - message: """ #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: @@ -248,46 +64,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Controller/MenuController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Controller/NotificationController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 5 - path: src/Bundle/ChillMainBundle/Controller/PasswordController.php - - - - message: """ - #^Parameter \\$passwordEncoder of method Chill\\\\MainBundle\\\\Controller\\\\PasswordController\\:\\:__construct\\(\\) has typehint with deprecated interface Symfony\\\\Component\\\\Security\\\\Core\\\\Encoder\\\\UserPasswordEncoderInterface\\: - since Symfony 5\\.3, use \\{@link UserPasswordHasherInterface\\} instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Controller/PasswordController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Controller/PostalCodeController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 5 - path: src/Bundle/ChillMainBundle/Controller/ScopeController.php - - message: """ #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: @@ -295,13 +71,6 @@ parameters: """ count: 1 path: src/Bundle/ChillMainBundle/Controller/SearchController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 6 - path: src/Bundle/ChillMainBundle/Controller/UserController.php - message: """ @@ -311,30 +80,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Controller/UserController.php - - - message: """ - #^Parameter \\$passwordEncoder of method Chill\\\\MainBundle\\\\Controller\\\\UserController\\:\\:__construct\\(\\) has typehint with deprecated interface Symfony\\\\Component\\\\Security\\\\Core\\\\Encoder\\\\UserPasswordEncoderInterface\\: - since Symfony 5\\.3, use \\{@link UserPasswordHasherInterface\\} instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Controller/UserController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Controller/UserProfileController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Controller/WorkflowController.php - - message: """ #^Instantiation of deprecated class Symfony\\\\Component\\\\Security\\\\Core\\\\Encoder\\\\EncoderFactory\\: @@ -343,30 +88,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadUsers.php - - - message: """ - #^Instantiation of deprecated class Symfony\\\\Component\\\\Security\\\\Core\\\\Encoder\\\\MessageDigestPasswordEncoder\\: - since Symfony 5\\.3, use \\{@link MessageDigestPasswordHasher\\} instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadUsers.php - - - - message: """ - #^Parameter \\$passwordEncoder of method Chill\\\\MainBundle\\\\Form\\\\UserPasswordType\\:\\:__construct\\(\\) has typehint with deprecated interface Symfony\\\\Component\\\\Security\\\\Core\\\\Encoder\\\\UserPasswordEncoderInterface\\: - since Symfony 5\\.3, use \\{@link UserPasswordHasherInterface\\} instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Form/UserPasswordType.php - - - - message: """ - #^Call to deprecated method isMasterRequest\\(\\) of class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\: - since symfony/http\\-kernel 5\\.3, use isMainRequest\\(\\) instead$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Notification/EventListener/PersistNotificationOnTerminateEventSubscriber.php - - message: """ #^Call to deprecated method getUsername\\(\\) of class Chill\\\\MainBundle\\\\Entity\\\\User\\: @@ -375,14 +96,6 @@ parameters: count: 2 path: src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php - - - message: """ - #^Instantiation of deprecated class Symfony\\\\Component\\\\Security\\\\Core\\\\Exception\\\\UsernameNotFoundException\\: - since Symfony 5\\.3 to be removed in 6\\.0, use UserNotFoundException instead\\.$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Security/UserProvider/UserProvider.php - - message: """ #^Call to deprecated method getUsername\\(\\) of class Chill\\\\MainBundle\\\\Entity\\\\User\\: @@ -407,54 +120,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Validator/Constraints/Entity/UserCircleConsistencyValidator.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillPersonBundle/CRUD/Controller/EntityPersonCRUDController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 3 - path: src/Bundle/ChillPersonBundle/CRUD/Controller/OneToOneEntityPersonCRUDController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 5 - path: src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 3 - path: src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseCommentController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 6 - path: src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php - - message: """ #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: @@ -463,53 +128,6 @@ parameters: count: 13 path: src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 6 - path: src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillPersonBundle/Controller/ClosingMotiveController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 3 - path: src/Bundle/ChillPersonBundle/Controller/HouseholdController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 4 - path: src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 8 - path: src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php - - message: """ #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: @@ -518,30 +136,6 @@ parameters: count: 4 path: src/Bundle/ChillPersonBundle/Controller/PersonController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 8 - path: src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 4 - path: src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 1 - path: src/Bundle/ChillPersonBundle/Controller/TimelinePersonController.php - - message: """ #^Call to deprecated method get\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: @@ -550,22 +144,6 @@ parameters: count: 7 path: src/Bundle/ChillReportBundle/Controller/ReportController.php - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 9 - path: src/Bundle/ChillReportBundle/Controller/ReportController.php - - - - message: """ - #^Call to deprecated method getDoctrine\\(\\) of class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\: - since Symfony 5\\.4, inject an instance of ManagerRegistry in your controller instead$# - """ - count: 8 - path: src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php - - message: """ #^Call to deprecated method getUsername\\(\\) of class Chill\\\\MainBundle\\\\Entity\\\\User\\: diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 648e4e608..e09bb5081 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -32,3 +32,4 @@ includes: - phpstan-baseline-level-4.neon - phpstan-baseline-level-5.neon - phpstan-deprecations-sf54.neon + - phpstan-baseline-deprecations-doctrine-orm.neon diff --git a/rector.php b/rector.php index 03109c6cb..7604667ea 100644 --- a/rector.php +++ b/rector.php @@ -11,6 +11,7 @@ declare(strict_types=1); use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; +use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $rectorConfig): void { @@ -69,4 +70,22 @@ return static function (RectorConfig $rectorConfig): void { \Rector\Symfony\Symfony28\Rector\MethodCall\GetToConstructorInjectionRector::class, \Rector\Symfony\Symfony34\Rector\Closure\ContainerGetNameToTypeInTestsRector::class, ]); + + $rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [ + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\AccompanyingPeriodValidity'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequential'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Household\MaxHolder'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ConfidentialCourseMustHaveReferrer'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\LocationValidity'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ParticipationOverlap'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ResourceDuplicateCheck'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Person\Birthdate'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\PersonBundle\Validator\Constraints\Relationship\RelationshipNoDuplicate'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\ActivityBundle\Validator\Constraints\ActivityValidity'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\DocStoreBundle\Validator\Constraints\AsyncFileExists'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\MainBundle\Validation\Constraint\PhonenumberConstraint'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistency'), + new \Rector\Php80\ValueObject\AnnotationToAttribute('Chill\MainBundle\Workflow\Validator\EntityWorkflowCreation'), + ]); }; diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index f69c9c705..2e7bede57 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -25,7 +25,6 @@ use Chill\MainBundle\Entity\HasScopesInterface; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; -use Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistency; use Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodLinkedWithSocialIssuesEntityInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; @@ -42,19 +41,12 @@ use Symfony\Component\Validator\Constraints as Assert; /** * Class Activity. - * - * @ActivityValidator\ActivityValidity - * - * TODO see if necessary - * UserCircleConsistency( - * "CHILL_ACTIVITY_SEE_DETAILS", - * getUserFunction="getUser", - * path="scope") */ #[DiscriminatorMap(typeProperty: 'type', mapping: ['activity' => Activity::class])] #[ORM\Entity(repositoryClass: \Chill\ActivityBundle\Repository\ActivityRepository::class)] #[ORM\HasLifecycleCallbacks] #[ORM\Table(name: 'activity')] +#[ActivityValidator\ActivityValidity] // TODO see if necessary class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterface, HasCentersInterface, HasScopesInterface, TrackCreationInterface, TrackUpdateInterface { use TrackCreationTrait; diff --git a/src/Bundle/ChillActivityBundle/Validator/Constraints/ActivityValidity.php b/src/Bundle/ChillActivityBundle/Validator/Constraints/ActivityValidity.php index aafe5f9b5..bea38c768 100644 --- a/src/Bundle/ChillActivityBundle/Validator/Constraints/ActivityValidity.php +++ b/src/Bundle/ChillActivityBundle/Validator/Constraints/ActivityValidity.php @@ -13,9 +13,7 @@ namespace Chill\ActivityBundle\Validator\Constraints; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS)] class ActivityValidity extends Constraint { final public const IS_REQUIRED_MESSAGE = ' is required'; diff --git a/src/Bundle/ChillCustomFieldsBundle/Entity/CustomFieldsGroup.php b/src/Bundle/ChillCustomFieldsBundle/Entity/CustomFieldsGroup.php index ce5f2dc5b..25040ec5f 100644 --- a/src/Bundle/ChillCustomFieldsBundle/Entity/CustomFieldsGroup.php +++ b/src/Bundle/ChillCustomFieldsBundle/Entity/CustomFieldsGroup.php @@ -13,7 +13,6 @@ namespace Chill\CustomFieldsBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; -use Doctrine\Common\Collections\Order; use Doctrine\ORM\Mapping as ORM; /** @@ -36,7 +35,7 @@ class CustomFieldsGroup * @var Collection */ #[ORM\OneToMany(targetEntity: CustomField::class, mappedBy: 'customFieldGroup')] - #[ORM\OrderBy(['ordering' => 'ASC'])] + #[ORM\OrderBy(['ordering' => \Doctrine\Common\Collections\Criteria::ASC])] private Collection $customFields; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)] diff --git a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php index c38189869..2cb2e98f5 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php @@ -28,13 +28,10 @@ use Symfony\Component\Serializer\Annotation as Serializer; * * The property `$deleteAt` allow a deletion of the document after the given date. But this property should * be set before the document is actually written by the StoredObjectManager. - * - * @AsyncFileExists( - * message="The file is not stored properly" - * ) */ #[ORM\Entity] #[ORM\Table('chill_doc.stored_object')] +#[AsyncFileExists(message: 'The file is not stored properly')] class StoredObject implements Document, TrackCreationInterface { use TrackCreationTrait; diff --git a/src/Bundle/ChillDocStoreBundle/Validator/Constraints/AsyncFileExists.php b/src/Bundle/ChillDocStoreBundle/Validator/Constraints/AsyncFileExists.php index 4e251629b..c0b5ec79c 100644 --- a/src/Bundle/ChillDocStoreBundle/Validator/Constraints/AsyncFileExists.php +++ b/src/Bundle/ChillDocStoreBundle/Validator/Constraints/AsyncFileExists.php @@ -13,13 +13,17 @@ namespace Chill\DocStoreBundle\Validator\Constraints; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)] final class AsyncFileExists extends Constraint { public string $message = "The file '{{ filename }}' is not stored properly."; + public function __construct(?array $options = null, ?string $message = null, ?array $groups = null, $payload = null) + { + parent::__construct($options ?? [], $groups, $payload); + $this->message = $message; + } + public function validatedBy() { return AsyncFileExistsValidator::class; diff --git a/src/Bundle/ChillMainBundle/Entity/Location.php b/src/Bundle/ChillMainBundle/Entity/Location.php index 836f6c1f9..228fd089f 100644 --- a/src/Bundle/ChillMainBundle/Entity/Location.php +++ b/src/Bundle/ChillMainBundle/Entity/Location.php @@ -65,18 +65,14 @@ class Location implements TrackCreationInterface, TrackUpdateInterface #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)] private ?string $name = null; - /** - * @PhonenumberConstraint(type="any") - */ #[Serializer\Groups(['read', 'write', 'docgen:read'])] #[ORM\Column(type: 'phone_number', nullable: true)] + #[PhonenumberConstraint(type: 'any')] private ?PhoneNumber $phonenumber1 = null; - /** - * @PhonenumberConstraint(type="any") - */ #[Serializer\Groups(['read', 'write', 'docgen:read'])] #[ORM\Column(type: 'phone_number', nullable: true)] + #[PhonenumberConstraint(type: 'any')] private ?PhoneNumber $phonenumber2 = null; #[Serializer\Groups(['read'])] diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index 494de08e1..4165da3d0 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -14,7 +14,6 @@ namespace Chill\MainBundle\Entity; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; -use Doctrine\Common\Collections\Order; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; @@ -58,7 +57,7 @@ class Notification implements TrackUpdateInterface * @var Collection */ #[ORM\OneToMany(targetEntity: NotificationComment::class, mappedBy: 'notification', orphanRemoval: true)] - #[ORM\OrderBy(['createdAt' => 'ASC'])] + #[ORM\OrderBy(['createdAt' => \Doctrine\Common\Collections\Criteria::ASC])] private Collection $comments; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)] diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 90544fd50..56ed66761 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -111,10 +111,9 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter /** * The user's mobile phone number. - * - * @PhonenumberConstraint() */ #[ORM\Column(type: 'phone_number', nullable: true)] + #[PhonenumberConstraint] private ?PhoneNumber $phonenumber = null; /** diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index f1aef9693..6996eacea 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -24,12 +24,10 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Validator\Constraints as Assert; -/** - * @EntityWorkflowCreation(groups={"creation"}) - */ #[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['entity_workflow' => EntityWorkflow::class])] #[ORM\Entity] #[ORM\Table('chill_main_workflow_entity')] +#[EntityWorkflowCreation(groups: ['creation'])] class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface { use TrackCreationTrait; diff --git a/src/Bundle/ChillMainBundle/Tests/Export/SortExportElementTest.php b/src/Bundle/ChillMainBundle/Tests/Export/SortExportElementTest.php index 02cf0a90f..cd820bb1c 100644 --- a/src/Bundle/ChillMainBundle/Tests/Export/SortExportElementTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Export/SortExportElementTest.php @@ -102,7 +102,7 @@ class SortExportElementTest extends KernelTestCase private function makeTranslator(): TranslatorInterface { return new class () implements TranslatorInterface { - public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null) + public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null) { return $id; } diff --git a/src/Bundle/ChillMainBundle/Validation/Constraint/PhonenumberConstraint.php b/src/Bundle/ChillMainBundle/Validation/Constraint/PhonenumberConstraint.php index 147a02465..2c20de854 100644 --- a/src/Bundle/ChillMainBundle/Validation/Constraint/PhonenumberConstraint.php +++ b/src/Bundle/ChillMainBundle/Validation/Constraint/PhonenumberConstraint.php @@ -13,9 +13,7 @@ namespace Chill\MainBundle\Validation\Constraint; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD)] class PhonenumberConstraint extends Constraint { public $notLandlineMessage = 'This is not a landline phonenumber'; @@ -29,7 +27,13 @@ class PhonenumberConstraint extends Constraint * * @var string 'landline', 'mobile' or 'any' */ - public $type; + public string $type; + + public function __construct(?array $options = null, ?string $type = null, ?array $groups = null, $payload = null) + { + parent::__construct($options ?? [], $groups, $payload); + $this->type = $type ?? 'any'; + } public function validatedBy() { diff --git a/src/Bundle/ChillMainBundle/Validator/Constraints/Entity/UserCircleConsistency.php b/src/Bundle/ChillMainBundle/Validator/Constraints/Entity/UserCircleConsistency.php index b8edc98ad..3c283a96e 100644 --- a/src/Bundle/ChillMainBundle/Validator/Constraints/Entity/UserCircleConsistency.php +++ b/src/Bundle/ChillMainBundle/Validator/Constraints/Entity/UserCircleConsistency.php @@ -13,9 +13,7 @@ namespace Chill\MainBundle\Validator\Constraints\Entity; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS)] class UserCircleConsistency extends Constraint { public $getUserFunction = 'getUser'; diff --git a/src/Bundle/ChillMainBundle/Workflow/Validator/EntityWorkflowCreation.php b/src/Bundle/ChillMainBundle/Workflow/Validator/EntityWorkflowCreation.php index 7476d3273..34f024884 100644 --- a/src/Bundle/ChillMainBundle/Workflow/Validator/EntityWorkflowCreation.php +++ b/src/Bundle/ChillMainBundle/Workflow/Validator/EntityWorkflowCreation.php @@ -17,9 +17,8 @@ namespace Chill\MainBundle\Workflow\Validator; * * a handler exists; * * a related entity does exists; * * a workflow can be associated with this entity. - * - * @Annotation */ +#[\Attribute(\Attribute::TARGET_CLASS)] class EntityWorkflowCreation extends \Symfony\Component\Validator\Constraint { public string $messageEntityNotFound = 'Related entity is not found'; diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 73758c5cc..3f4b7c8fe 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -53,17 +53,14 @@ use UnexpectedValueException; /** * AccompanyingPeriod Class. - * - * @AccompanyingPeriodValidity(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED}) - * - * @LocationValidity(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED}) - * - * @ConfidentialCourseMustHaveReferrer(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED}) */ #[DiscriminatorMap(typeProperty: 'type', mapping: ['accompanying_period' => AccompanyingPeriod::class])] #[Assert\GroupSequenceProvider] #[ORM\Entity] #[ORM\Table(name: 'chill_person_accompanying_period')] +#[AccompanyingPeriodValidity(groups: [AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED])] +#[LocationValidity(groups: [AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED])] +#[ConfidentialCourseMustHaveReferrer(groups: [AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED])] class AccompanyingPeriod implements GroupSequenceProviderInterface, HasCentersInterface, @@ -215,12 +212,11 @@ class AccompanyingPeriod implements private ?Origin $origin = null; /** - * @ParticipationOverlap(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED}) - * * @var Collection */ #[Groups(['read', 'docgen:read'])] #[ORM\OneToMany(targetEntity: AccompanyingPeriodParticipation::class, mappedBy: 'accompanyingPeriod', orphanRemoval: true, cascade: ['persist', 'refresh', 'remove', 'merge', 'detach'])] + #[ParticipationOverlap(groups: [AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED])] private Collection $participations; #[ORM\ManyToOne(targetEntity: Person::class, inversedBy: 'periodLocatedOn')] @@ -251,11 +247,10 @@ class AccompanyingPeriod implements /** * @var Collection - * - * @ResourceDuplicateCheck(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED, "Default", "default"}) */ #[Groups(['read', 'docgen:read'])] #[ORM\OneToMany(targetEntity: AccompanyingPeriod\Resource::class, mappedBy: 'accompanyingPeriod', cascade: ['persist', 'remove'], orphanRemoval: true)] + #[ResourceDuplicateCheck(groups: [AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED, 'Default', 'default'])] private Collection $resources; /** diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index 7b0374d4e..52b246521 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -24,7 +24,6 @@ use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\ThirdPartyBundle\Entity\ThirdParty; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; -use Doctrine\Common\Collections\Order; use Doctrine\Common\Collections\ReadableCollection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; @@ -47,7 +46,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues */ #[Serializer\Groups(['read', 'docgen:read'])] #[ORM\OneToMany(targetEntity: AccompanyingPeriodWorkEvaluation::class, mappedBy: 'accompanyingPeriodWork', cascade: ['remove', 'persist'], orphanRemoval: true)] - #[ORM\OrderBy(['startDate' => 'DESC', 'id' => 'DESC'])] + #[ORM\OrderBy(['startDate' => \Doctrine\Common\Collections\Criteria::DESC, 'id' => 'DESC'])] private Collection $accompanyingPeriodWorkEvaluations; #[Serializer\Groups(['read', 'docgen:read', 'read:accompanyingPeriodWork:light'])] diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index 905bdd801..ea68f51ec 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -25,12 +25,10 @@ use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; -/** - * @MaxHolder(groups={"household_memberships"}) - */ #[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['household' => Household::class])] #[ORM\Entity] #[ORM\Table(name: 'chill_person_household')] +#[MaxHolder(groups: ['household_memberships'])] class Household { /** diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 44d6588bb..0a9bf9612 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -47,12 +47,6 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * Person Class. - * - * @PersonHasCenter - * - * @HouseholdMembershipSequential( - * groups={"household_memberships"} - * ) */ #[DiscriminatorMap(typeProperty: 'type', mapping: ['person' => Person::class])] #[ORM\Entity] @@ -60,6 +54,8 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; #[ORM\Index(name: 'person_birthdate', columns: ['birthdate'])] // @ORM\HasLifecycleCallbacks #[ORM\Table(name: 'chill_person_person')] #[ORM\HasLifecycleCallbacks] +#[PersonHasCenter] +#[HouseholdMembershipSequential(groups: ['household_memberships'])] class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateInterface, \Stringable { final public const BOTH_GENDER = 'both'; @@ -122,10 +118,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * The person's birthdate. - * - * @Birthdate */ #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATE_MUTABLE, nullable: true)] + #[Birthdate] private ?\DateTime $birthdate = null; /** @@ -316,10 +311,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * The person's mobile phone number. - * - * @PhonenumberConstraint(type="mobile") */ #[ORM\Column(type: 'phone_number', nullable: true)] + #[PhonenumberConstraint(type: 'mobile')] private ?PhoneNumber $mobilenumber = null; /** @@ -350,12 +344,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * The person's phonenumber. - * - * @PhonenumberConstraint( - * type="landline", - * ) */ #[ORM\Column(type: 'phone_number', nullable: true)] + #[PhonenumberConstraint(type: 'landline')] private ?PhoneNumber $phonenumber = null; /** diff --git a/src/Bundle/ChillPersonBundle/Entity/Relationships/Relationship.php b/src/Bundle/ChillPersonBundle/Entity/Relationships/Relationship.php index 8e38f827e..4e658575b 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Relationships/Relationship.php +++ b/src/Bundle/ChillPersonBundle/Entity/Relationships/Relationship.php @@ -23,13 +23,11 @@ use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Validator\Constraints as Assert; -/** - * @RelationshipNoDuplicate - */ #[DiscriminatorMap(typeProperty: 'type', mapping: ['relationship' => Relationship::class])] #[ORM\Entity] #[DiscriminatorColumn(name: 'relation_id', type: 'integer')] #[ORM\Table(name: 'chill_person_relationships')] +#[RelationshipNoDuplicate] class Relationship implements TrackCreationInterface, TrackUpdateInterface { #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)] diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingPeriodStepHistoryAggregators/ByStepAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingPeriodStepHistoryAggregators/ByStepAggregatorTest.php index 7184b3151..58e3e5f61 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingPeriodStepHistoryAggregators/ByStepAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingPeriodStepHistoryAggregators/ByStepAggregatorTest.php @@ -27,7 +27,7 @@ class ByStepAggregatorTest extends AbstractAggregatorTest public function getAggregator() { $translator = new class () implements TranslatorInterface { - public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null) + public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null) { return $id; } diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidity.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidity.php index 4d8fd35c5..82a2d1d40 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidity.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidity.php @@ -13,9 +13,7 @@ namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS)] class AccompanyingPeriodValidity extends Constraint { public $messageSocialIssueCannotBeDeleted = 'The social %name% issue cannot be deleted because it is associated with an activity or an action'; diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ConfidentialCourseMustHaveReferrer.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ConfidentialCourseMustHaveReferrer.php index b22117dc8..97e5be385 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ConfidentialCourseMustHaveReferrer.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ConfidentialCourseMustHaveReferrer.php @@ -13,9 +13,7 @@ namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS)] class ConfidentialCourseMustHaveReferrer extends Constraint { public string $message = 'A confidential parcours must have a referrer'; diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/LocationValidity.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/LocationValidity.php index 1940ec8c4..8e832da6e 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/LocationValidity.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/LocationValidity.php @@ -13,9 +13,7 @@ namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS)] class LocationValidity extends Constraint { public $messagePeriodMustRemainsLocated = 'The period must remain located'; diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlap.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlap.php index 80d202772..f82d8ac3f 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlap.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlap.php @@ -13,9 +13,7 @@ namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_PROPERTY)] class ParticipationOverlap extends Constraint { public $message = '{{ name }} is already associated to this accompanying course.'; diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ResourceDuplicateCheck.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ResourceDuplicateCheck.php index 5a747291b..cacb7d39c 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ResourceDuplicateCheck.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ResourceDuplicateCheck.php @@ -13,9 +13,7 @@ namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_PROPERTY)] class ResourceDuplicateCheck extends Constraint { public $message = '{{ name }} is already associated to this accompanying course.'; diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/HouseholdMembershipSequential.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/HouseholdMembershipSequential.php index 22e88d1c3..d5f3a9547 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/HouseholdMembershipSequential.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/HouseholdMembershipSequential.php @@ -13,9 +13,7 @@ namespace Chill\PersonBundle\Validator\Constraints\Household; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS)] class HouseholdMembershipSequential extends Constraint { public $message = 'household_membership.Person with membership covering'; diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/MaxHolder.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/MaxHolder.php index f21793ec4..5f45f69ac 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/MaxHolder.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/MaxHolder.php @@ -13,9 +13,7 @@ namespace Chill\PersonBundle\Validator\Constraints\Household; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS)] class MaxHolder extends Constraint { public $message = 'household.max_holder_overflowed'; diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/Birthdate.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/Birthdate.php index 30060445f..d35bf947d 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/Birthdate.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/Birthdate.php @@ -20,9 +20,8 @@ use Symfony\Component\Validator\Constraint; * interval_spec : http://php.net/manual/en/dateinterval.construct.php * (this interval_spec itself is based on ISO8601 : * https://en.wikipedia.org/wiki/ISO_8601#Durations) - * - * @Annotation */ +#[\Attribute(\Attribute::TARGET_PROPERTY)] class Birthdate extends Constraint { final public const BIRTHDATE_INVALID_CODE = '3f42fd96-0b2d-11ec-8cf3-0f3b1b1ca1c4'; diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/PersonHasCenter.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/PersonHasCenter.php index 2dc19156b..2e502f9f3 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/PersonHasCenter.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/PersonHasCenter.php @@ -11,9 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Validator\Constraints\Person; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS)] class PersonHasCenter extends \Symfony\Component\Validator\Constraint { public string $message = 'A center is required'; diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/Relationship/RelationshipNoDuplicate.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/Relationship/RelationshipNoDuplicate.php index c4db049dd..c21cca5b6 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/Relationship/RelationshipNoDuplicate.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/Relationship/RelationshipNoDuplicate.php @@ -13,9 +13,7 @@ namespace Chill\PersonBundle\Validator\Constraints\Relationship; use Symfony\Component\Validator\Constraint; -/** - * @Annotation - */ +#[\Attribute(\Attribute::TARGET_CLASS)] class RelationshipNoDuplicate extends Constraint { public $message = 'relationship.duplicate'; diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 76cc0ed19..7fa3178fe 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -206,11 +206,9 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin #[Context(normalizationContext: ['groups' => 'docgen:read'], groups: ['docgen:read:3party:parent'])] private string $profession = ''; - /** - * @PhonenumberConstraint(type="any") - */ #[Groups(['read', 'write', 'docgen:read', 'docgen:read:3party:parent'])] #[ORM\Column(name: 'telephone', type: 'phone_number', nullable: true)] + #[PhonenumberConstraint(type: 'any')] private ?PhoneNumber $telephone = null; #[ORM\Column(name: 'types', type: \Doctrine\DBAL\Types\Types::JSON, nullable: true)]