From 5bd86dd6be0ca3ce0f4067362566ff399c2f5db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org> Date: Thu, 3 Jun 2021 12:14:02 +0200 Subject: [PATCH] :ambulance: fix(core) Improve type documentation of array_* functions issue #6165 --- include/functions.inc | 71 ++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/include/functions.inc b/include/functions.inc index 65d1903d3..c681e4f71 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -220,52 +220,55 @@ function get_template_path ($filename = '', $plugin = FALSE, $path = '') } -/*! - * \brief Remove multiple entries from an array +/** + * Remove multiple entries from an array * * Removes every element that is in $needles from the * array given as $haystack * - * \param array $needles array of the entries to remove + * @param array $needles array of the entries to remove + * + * @param array $haystack original array to remove the entries from * - * \param array $haystack original array to remove the entries from + * @return array<int,mixed> */ -function array_remove_entries (array $needles, array $haystack) +function array_remove_entries (array $needles, array $haystack): array { return array_values(array_udiff($haystack, $needles, 'array_cmp_recursive')); } -/*! - * \brief Remove multiple entries from an array (case-insensitive) +/** + * Remove multiple entries from an array (case-insensitive) * * Removes every element that is in $needles from the * array given as $haystack but case insensitive - * Only works on array of stringable * - * \param array $needles array of the entries to remove + * @param array<int|string|bool|null|float|double|Stringable> $needles array of the entries to remove + * + * @param array<int|string|bool|null|float|double|Stringable> $haystack original array to remove the entries from * - * \param array $haystack original array to remove the entries from + * @return array<int,int|string|bool|null|float|double|Stringable> */ -function array_remove_entries_ics (array $needles, array $haystack) +function array_remove_entries_ics (array $needles, array $haystack): array { // strcasecmp will work, because we only compare ASCII values here return array_values(array_udiff($haystack, $needles, 'strcasecmp')); } -/*! - * \brief Merge to array but remove duplicate entries (case-insensitive) +/** + * Merge to array but remove duplicate entries (case-insensitive) * * Merges two arrays and removes duplicate entries. Triggers * an error if first or second parametre is not an array. * - * \param array $ar1 first array + * @param array<int|string|bool|null|float|double|Stringable> $ar1 first array * - * \param array $ar2 second array + * @param array<int|string|bool|null|float|double|Stringable> $ar2 second array * - * \return array + * @return array<int,int|string|bool|null|float|double|Stringable> */ -function array_merge_unique (array $ar1, array $ar2) +function array_merge_unique (array $ar1, array $ar2): array { return array_values(array_unique(array_merge($ar1, $ar2))); } @@ -1047,16 +1050,16 @@ function array_key_ics ($ikey, array $items) } -/*! - * \brief Determine if two arrays are different +/** + * Determine if two arrays are different * - * \param array $src The source + * @param array<int|string|bool|null|float|double|Stringable> $src The source * - * \param array $dst The destination + * @param array<int|string|bool|null|float|double|Stringable> $dst The destination * - * \return boolean TRUE or FALSE + * @return bool TRUE or FALSE */ -function array_differs (array $src, array $dst) +function array_differs (array $src, array $dst): bool { /* If the count is differing, the arrays differ */ if (count($src) != count($dst)) { @@ -1066,28 +1069,28 @@ function array_differs (array $src, array $dst) return (count(array_diff($src, $dst)) != 0); } -/*! - * \brief Determine if two arrays are different using recursion for sublevels +/** + * Determine if two arrays are different using recursion for sublevels * - * \param array $src The source + * @param mixed $src The source * - * \param array $dst The destination + * @param mixed $dst The destination * - * \return boolean TRUE or FALSE + * @return bool TRUE or FALSE */ -function array_differs_recursive ($src, $dst) +function array_differs_recursive ($src, $dst): bool { return (array_cmp_recursive($src, $dst) !== 0); } -/*! - * \brief Determine if two arrays are different using recursion for sublevels +/** + * Determine if two arrays are different using recursion for sublevels * - * \param array $src The source + * @param mixed $src The source * - * \param array $dst The destination + * @param mixed $dst The destination * - * \return <0, 0 or >0 if $src is <, = or > $dst + * @return int negative, 0 or positive if $src is <, = or > $dst */ function array_cmp_recursive ($src, $dst): int { -- GitLab