From: Alexander Ebert Date: Mon, 9 Oct 2023 16:05:53 +0000 (+0200) Subject: Improve the code logic X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=21514e37b3c99fa69a15051e3108efeacf17283d;p=GitHub%2FWoltLab%2FWCF.git Improve the code logic --- diff --git a/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php b/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php index 40a4ead226..0a6361b84a 100644 --- a/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php +++ b/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php @@ -214,7 +214,7 @@ class ArticleCategory extends AbstractDecoratedCategory implements IAccessibleOb } } - return LabelPickerGroup::fromGroupIDs(\array_unique($groupIDs), false); + return LabelPickerGroup::fromGroupIDs($groupIDs, false); } /** diff --git a/wcfsetup/install/files/lib/system/label/LabelHandler.class.php b/wcfsetup/install/files/lib/system/label/LabelHandler.class.php index af48316eb1..a7219a9367 100644 --- a/wcfsetup/install/files/lib/system/label/LabelHandler.class.php +++ b/wcfsetup/install/files/lib/system/label/LabelHandler.class.php @@ -428,7 +428,6 @@ class LabelHandler extends SingletonFactory /** * @param int[] $groupIDs - * @param bool $invertible * @return LabelPicker[] * @since 6.0 */ diff --git a/wcfsetup/install/files/lib/system/label/LabelPicker.class.php b/wcfsetup/install/files/lib/system/label/LabelPicker.class.php index 52b19aada0..fb37ea03d9 100644 --- a/wcfsetup/install/files/lib/system/label/LabelPicker.class.php +++ b/wcfsetup/install/files/lib/system/label/LabelPicker.class.php @@ -8,7 +8,7 @@ use wcf\util\JSON; use wcf\util\StringUtil; /** - * Provides helper methods to interact with the label group. + * Manages the state of a label picker and renders the component. * * @author Alexander Ebert * @copyright 2001-2023 WoltLab GmbH @@ -117,7 +117,7 @@ final class LabelPicker if (!isset($this->elementID)) { $this->elementID = \sprintf( '%s_labelGroup%d', - \substr(\md5($this->name), 0, 8), + \bin2hex(\random_bytes(16)), $this->labelGroup->groupID, ); } diff --git a/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php b/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php index 273a6daf11..15984d6447 100644 --- a/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php +++ b/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php @@ -97,26 +97,21 @@ final class LabelPickerGroup implements \Countable, \Iterator /** * Returns an unencoded query string for `labelIDs` for use in the LinkHandler. - * - * @return string */ public function toUrlQueryString(): string { return \implode( '&', - \array_filter( - \array_map(static function (LabelPicker $labelPicker) { - if (!$labelPicker->hasSelection()) { - return ''; - } - - return \sprintf( - 'labelIDs[%d]=%d', - $labelPicker->labelGroup->groupID, - $labelPicker->getSelectedValue(), - ); - }, $this->labelPickers) - ) + \array_map(static function (LabelPicker $labelPicker) { + return \sprintf( + 'labelIDs[%d]=%d', + $labelPicker->labelGroup->groupID, + $labelPicker->getSelectedValue(), + ); + }, \array_filter( + $this->labelPickers, + static fn (LabelPicker $labelPicker) => $labelPicker->hasSelection() + )) ); } @@ -127,11 +122,12 @@ final class LabelPickerGroup implements \Countable, \Iterator */ public function toLabelIDs(): array { - return \array_filter( - \array_map( - fn (LabelPicker $labelPicker) => $labelPicker->getSelectedValue(), - $this->labelPickers - ), + return \array_map( + static fn (LabelPicker $labelPicker) => $labelPicker->getSelectedValue(), + \array_filter( + $this->labelPickers, + static fn (LabelPicker $labelPicker) => $labelPicker->hasSelection() + ) ); } @@ -250,7 +246,7 @@ final class LabelPickerGroup implements \Countable, \Iterator public static function fromViewableLabelGroups(array $viewableLabelGroups, bool $invertible): self { $labelPickers = \array_map( - fn (ViewableLabelGroup $viewableLabelGroup) => new LabelPicker($viewableLabelGroup, $invertible), + static fn (ViewableLabelGroup $viewableLabelGroup) => new LabelPicker($viewableLabelGroup, $invertible), $viewableLabelGroups );