From 546107398aeafc131ca8774708d7c87aa814775a Mon Sep 17 00:00:00 2001 From: mjansen Date: Mon, 20 Apr 2026 09:51:14 +0200 Subject: [PATCH] [IMPROVEMENT] User: Improve PHP types in `User/Profile` This PR improves the type documentation in the `Profile` sub-namespace of the "User" component. --- .../src/Profile/ChangeMail/DBRepository.php | 2 +- .../src/Profile/ChangeMail/Repository.php | 3 -- .../ILIAS/User/src/Profile/DataRepository.php | 15 ++++----- .../src/Profile/DatabaseDataRepository.php | 10 ++---- .../Fields/CachedConfigurationRepository.php | 19 ++++++++--- .../Fields/ConfigurationRepository.php | 4 +-- components/ILIAS/User/src/Profile/Profile.php | 19 +++++++---- .../src/Profile/ProfileImplementation.php | 33 ++++++++----------- 8 files changed, 53 insertions(+), 52 deletions(-) diff --git a/components/ILIAS/User/src/Profile/ChangeMail/DBRepository.php b/components/ILIAS/User/src/Profile/ChangeMail/DBRepository.php index 84a26f0967b6..721def77c17e 100755 --- a/components/ILIAS/User/src/Profile/ChangeMail/DBRepository.php +++ b/components/ILIAS/User/src/Profile/ChangeMail/DBRepository.php @@ -139,7 +139,7 @@ private function storeToken(Token $token): void $this->db->replace( self::TABLE_NAME, [ - 'token' => ['text', $token->getToken()] + 'token' => [\ilDBConstants::T_TEXT, $token->getToken()] ], [ 'usr_id' => [\ilDBConstants::T_TEXT, $token->getUserId()], diff --git a/components/ILIAS/User/src/Profile/ChangeMail/Repository.php b/components/ILIAS/User/src/Profile/ChangeMail/Repository.php index 120d6db215b6..2905c7947fd7 100755 --- a/components/ILIAS/User/src/Profile/ChangeMail/Repository.php +++ b/components/ILIAS/User/src/Profile/ChangeMail/Repository.php @@ -26,9 +26,6 @@ public function hasUserValidEmailConfirmationToken(\ilObjUser $user): bool; /** * This Function will check if the token is actually valid for the given user * before returning the new email. - * - * @return string The new email a user wishes to be used or an empty string - * if validation failed or there is no usable entry. */ public function getTokenForTokenString(string $token_string, \ilObjUser $user): ?Token; public function moveToNextStep(Token $token, int $now): Token; diff --git a/components/ILIAS/User/src/Profile/DataRepository.php b/components/ILIAS/User/src/Profile/DataRepository.php index 7987b5f60dee..b41b02a6ba95 100644 --- a/components/ILIAS/User/src/Profile/DataRepository.php +++ b/components/ILIAS/User/src/Profile/DataRepository.php @@ -28,11 +28,9 @@ interface DataRepository { public function getDefault(): Data; public function getSingle(int $id): Data; - /** - * - * @param array $user_ids - * @return Generator + * @param list $user_ids + * @return \Generator */ public function getMultiple(array $user_ids): \Generator; public function store(Data $user_data): void; @@ -51,17 +49,18 @@ public function storeLoginFor( public function storeLastVisitedFor( int $usr_id, array $last_visited - ); + ): void; + /** + * @return list<\ILIAS\User\Search\AutocompleteItem> + */ public function searchUsers( SettingsDataRepository $settings_data_repository, ProfileFieldsConfigurationRepository $profile_fields_config_repo, AutocompleteQuery $search_term ): array; - public function getProfileDataQuery(array $select_fields): DataQuery; - /** - * @return array{cnt: int, set: array{string, mixed}} + * @return array{cnt: int, set: list>} */ public function getCountAndRecordsForQuery( DataQuery $query, diff --git a/components/ILIAS/User/src/Profile/DatabaseDataRepository.php b/components/ILIAS/User/src/Profile/DatabaseDataRepository.php index 1a36f3d79079..847d24d87583 100644 --- a/components/ILIAS/User/src/Profile/DatabaseDataRepository.php +++ b/components/ILIAS/User/src/Profile/DatabaseDataRepository.php @@ -69,7 +69,7 @@ public function getSingle(int $id): Data $base_data = $this->db->fetchObject($base_query); if ($base_data === null) { - throw \InvalidArgumentException( + throw new \InvalidArgumentException( 'This user does not exist.' ); } @@ -188,7 +188,7 @@ public function store(Data $user_data): void public function deleteForFieldIdentifier(string $identifier): void { - $this->db->manipulateF( + $this->db->manipulate( 'DELETE FROM ' . self::USER_VALUES_TABLE . " WHERE field_id='{$this->db->quote($identifier, \ilDBConstants::T_TEXT)}'" ); @@ -245,9 +245,6 @@ public function storeLastVisitedFor( ); } - /** - * @return list<\ILIAS\User\Search\AutocompleteItem> - */ public function searchUsers( SettingsDataRepository $settings_data_repository, ProfileFieldsConfigurationRepository $profile_fields_config_repo, @@ -293,9 +290,6 @@ public function getProfileDataQuery( ); } - /** - * @return array{cnt: int, set: array{string, mixed}} - */ public function getCountAndRecordsForQuery( DataQuery $query, int $offset, diff --git a/components/ILIAS/User/src/Profile/Fields/CachedConfigurationRepository.php b/components/ILIAS/User/src/Profile/Fields/CachedConfigurationRepository.php index e0c7950a6564..1a3ad26ef003 100644 --- a/components/ILIAS/User/src/Profile/Fields/CachedConfigurationRepository.php +++ b/components/ILIAS/User/src/Profile/Fields/CachedConfigurationRepository.php @@ -26,14 +26,20 @@ class CachedConfigurationRepository implements ConfigurationRepository { private const string USER_FIELD_CONFIGURATION_TABLE = 'usr_field_config'; private const string UDF_DEFINITIONS_TABLE = 'udf_definition'; + /** + * @var list + */ private array $available_profile_fields; /** - * - * @var array + * @var array */ private array $fields_data = []; + /** + * @param list> $available_custom_field_types + * @param list $available_standard_profile_fields + */ public function __construct( private readonly \ilDBInterface $db, private readonly UUIDFactory $uuid_factory, @@ -159,7 +165,7 @@ public function storeConfiguration(Field $field): void public function getCustomFieldTypes(): array { return array_map( - fn(string $v): Custom\Type => new $v(), + static fn(string $v): Custom\Type => new $v(), $this->available_custom_field_types ); } @@ -189,6 +195,10 @@ public function deleteCustomField(Field $field): void $this->available_profile_fields = $this->generateAvailableProfielFields(); } + /** + * @param list> $available_custom_field_types + * @return list + */ private function buildCustomFieldDefinitions( array $available_custom_field_types ): array { @@ -199,9 +209,10 @@ private function buildCustomFieldDefinitions( $custom_field_definitions = []; while (($field = $this->db->fetchObject($query_result)) !== null) { $field_type = array_search($field->field_type, $available_custom_field_types); - if ($field_type === null) { + if ($field_type === false) { continue; } + $custom_field_definitions[] = new Custom\Custom( $this->uuid_factory->fromString($field->field_id), new $available_custom_field_types[$field_type](), diff --git a/components/ILIAS/User/src/Profile/Fields/ConfigurationRepository.php b/components/ILIAS/User/src/Profile/Fields/ConfigurationRepository.php index 87e2eb132356..00b50de2cb9c 100644 --- a/components/ILIAS/User/src/Profile/Fields/ConfigurationRepository.php +++ b/components/ILIAS/User/src/Profile/Fields/ConfigurationRepository.php @@ -25,7 +25,7 @@ interface ConfigurationRepository public function hasMigrationBeenRun(): bool; /** - * @return array<\ILIAS\User\Profile\Fields\Field> + * @return list */ public function get(): array; public function getByIdentifier(string $identifier): ?Field; @@ -33,7 +33,7 @@ public function getByClass(string $class): ?Field; public function storeConfiguration(Field $field): void; /** - * @return array<\ILIAS\User\Profile\Fields\FieldDefinition> + * @return list */ public function getCustomFieldTypes(): array; public function getUnspecifiedCustomField(): Field; diff --git a/components/ILIAS/User/src/Profile/Profile.php b/components/ILIAS/User/src/Profile/Profile.php index 32c3593e1c1b..b91acb8def26 100755 --- a/components/ILIAS/User/src/Profile/Profile.php +++ b/components/ILIAS/User/src/Profile/Profile.php @@ -24,7 +24,9 @@ interface Profile { /** - * @return array<\ILIAS\User\Profile\Fields\Field> + * @param list<\ILIAS\User\Profile\Fields\AvailableSections> $fields_to_skip + * @param list> $fields_to_skip + * @return array */ public function getFields( array $sections_to_skip = [], @@ -32,7 +34,9 @@ public function getFields( ): array; /** - * @return array<\ILIAS\User\Profile\Fields\Field> + * @param list<\ILIAS\User\Profile\Fields\AvailableSections> $fields_to_skip + * @param list> $fields_to_skip + * @return array */ public function getVisibleFields( Context $context, @@ -43,6 +47,9 @@ public function getVisibleFields( public function getFieldByIdentifier(string $identifier): ?ProfileField; + /** + * @param list> $fields_to_skip + */ public function addFieldsToForm( \ilPropertyFormGUI $form, Context $context, @@ -64,7 +71,7 @@ public function getDataFor( /** * * @param array $usr_ids - * @return \Generator + * @return \Generator */ public function getDataForMultiple( array $usr_ids @@ -79,18 +86,18 @@ public function userFieldVisibleToUser( public function userFieldEditableByUser(string $definition_class): bool; /** - * @return array<\ILIAS\User\Profile\Fields\Field> + * @return list */ public function getIgnorableRequiredFields(): array; /** * @deprecated since version 11 will be removed with 13 - * @return array + * @return array */ public function getAllUserDefinedFields(): array; /** * @deprecated since version 11 will be removed with 13 - * @return array + * @return array */ public function getVisibleUserDefinedFields( Context $context diff --git a/components/ILIAS/User/src/Profile/ProfileImplementation.php b/components/ILIAS/User/src/Profile/ProfileImplementation.php index 936efc44b0d8..ea740bdb5dc0 100644 --- a/components/ILIAS/User/src/Profile/ProfileImplementation.php +++ b/components/ILIAS/User/src/Profile/ProfileImplementation.php @@ -25,9 +25,13 @@ use ILIAS\User\Profile\Fields\AvailableSections as AvailableProfileSections; use ILIAS\User\Profile\Fields\ConfigurationRepository as FieldsConfigurationRepository; use ILIAS\Language\Language; +use ILIAS\User\Profile\Fields\AvailableSections; class ProfileImplementation implements Profile { + /** + * @var list + */ private array $user_fields; public function __construct( @@ -38,16 +42,13 @@ public function __construct( $this->user_fields = $this->profile_fields_repository->get(); } - /** - * @return array<\ILIAS\User\Profile\Fields\Field> - */ public function getFields( array $sections_to_skip = [], array $fields_to_skip = [] ): array { return array_reduce( $this->user_fields, - function (array $c, ProfileField $v) use ($sections_to_skip, $fields_to_skip): array { + static function (array $c, ProfileField $v) use ($sections_to_skip, $fields_to_skip): array { if (!in_array($v->getSection(), $sections_to_skip) && !in_array(get_class($v->getDefinition()), $fields_to_skip)) { $c[$v->getIdentifier()] = $v; @@ -58,9 +59,6 @@ function (array $c, ProfileField $v) use ($sections_to_skip, $fields_to_skip): a ); } - /** - * @return array<\ILIAS\User\Profile\Fields\Field> - */ public function getVisibleFields( Context $context, ?\ilObjUser $user = null, @@ -69,7 +67,7 @@ public function getVisibleFields( ): array { return array_filter( $this->user_fields, - fn(ProfileField $v) => !in_array($v->getSection(), $sections_to_skip) + static fn(ProfileField $v) => !in_array($v->getSection(), $sections_to_skip) && !in_array($v->getDefinition()::class, $fields_to_skip) && $context->isFieldVisible($v, $user) ? true : false @@ -174,7 +172,7 @@ public function userFieldEditableByUser(string $setting): bool return $field->isVisibleToUser() && $field->isChangeableByUser(); } - public function getIgnorableRequiredFields(): array // Missing array type. + public function getIgnorableRequiredFields(): array { return array_reduce( $this->user_fields, @@ -192,15 +190,11 @@ static function (array $c, ProfileField $v): array { ); } - /** - * @deprecated since version 11 will be removed with 13 - * @return array - */ public function getAllUserDefinedFields(): array { return array_reduce( $this->user_fields, - function (array $c, ProfileField $v): array { + static function (array $c, ProfileField $v): array { if ($v->isCustom()) { $c[$v->getIdentifier()] = $v; } @@ -210,16 +204,12 @@ function (array $c, ProfileField $v): array { ); } - /** - * @deprecated since version 11 will be removed with 13 - * @return array - */ public function getVisibleUserDefinedFields( Context $context ): array { return array_reduce( $this->getVisibleFields($context), - function (array $c, ProfileField $v): array { + static function (array $c, ProfileField $v): array { if ($v->isCustom()) { $c[$v->getIdentifier()] = $v; } @@ -239,6 +229,9 @@ public function tempStorePicture( ->getDefinition()->tempStorePicture($form); } + /** + * @return array, array> + */ private function getVisibleFieldsBySection( Context $context, ?\ilObjUser $user, @@ -247,7 +240,7 @@ private function getVisibleFieldsBySection( return array_filter( array_reduce( $this->getVisibleFields($context, $user, [], $fields_to_skip), - function (array $c, ProfileField $v): array { + static function (array $c, ProfileField $v): array { $c[$v->getSection()->value][] = $v; return $c; },