- Issue created by @Jonasanne
- 🇧🇪Belgium Jonasanne
In this code modification, I enhanced the UserMailUniqueValidator class in the UserMailUniqueValidator.php file. The changes involve refactoring the constructor to leverage property promotion, which is a feature introduced in PHP 8.0. This helps simplify the code by declaring and initializing class properties directly within the constructor parameters.
Here's a breakdown of the changes:
Property Promotion in Constructor:I replaced the individual property declarations and assignments in the constructor with property promotion.
Introduced property promotion for the AuthmapInterface, OpenidConnectRealmManagerInterface, EntityFieldManagerInterface, and EntityTypeManagerInterface properties.Constructor Parameter Removal:
Removed the unnecessary parameters from the constructor, as property promotion takes care of both declaration and initialization.Dependency Injection Enhancement:
Updated the create method to include the new dependencies (EntityFieldManagerInterface and EntityTypeManagerInterface) when instantiating the class. - Status changed to Needs work
11 months ago 11:07am 5 January 2024 - 🇧🇪Belgium jelle_s Antwerp, Belgium
-
+++ b/src/Plugin/Validation/Constraint/UserMailUniqueValidator.php @@ -36,9 +24,7 @@ class UserMailUniqueValidator extends UniqueFieldValueValidator implements Conta + public function __construct(protected AuthmapInterface $authmap, protected OpenidConnectRealmManagerInterface $realm_manager,protected EntityFieldManagerInterface $entityFieldManager, protected EntityTypeManagerInterface $entityTypeManager) {
Code style: space after
$realm_manager,
Code style: rename$realm_manager
to$realmManager
Drupal uses snake_case for method arguments, but camelCase for properties; I believe the fact you're defining a property here has precedence over the fact that it's a constructor argument. -
+++ b/src/Plugin/Validation/Constraint/UserMailUniqueValidator.php @@ -68,7 +57,7 @@ class UserMailUniqueValidator extends UniqueFieldValueValidator implements Conta + if ($this->realm_manager->hasDefinition($plugin_id)) {
Revert this change based on previous remark.
-
- 🇧🇪Belgium matthijs
Thanks for your merge request!
I'm not a big fan constructor property promotion since it causes mixed casing for class properties, so please change that as well.
- First commit to issue fork.
- Status changed to Needs review
11 months ago 8:33am 8 January 2024 - 🇮🇳India viren18febS
I have fixed the reported issues and added a patch file please review
Thanks -
Matthijs →
committed 63fc4bba on 2.x
Issue #3412523 by Jonasanne, viren18febS, Jelle_S, Matthijs: Fix Drupal...
-
Matthijs →
committed 63fc4bba on 2.x
- Status changed to Fixed
11 months ago 8:24pm 9 January 2024 Automatically closed - issue fixed for 2 weeks with no activity.