From e3007a053c6b696995aade69cfb98f420d1d2f4c Mon Sep 17 00:00:00 2001 From: mjansen Date: Thu, 11 Apr 2024 15:44:40 +0200 Subject: [PATCH] Badge: Fix code style --- Services/Badge/classes/Sorting.php | 2 +- Services/Badge/classes/Tile.php | 4 ++-- Services/Badge/classes/class.ilBadgeHandler.php | 6 ++++-- Services/Badge/classes/class.ilBadgeManagementGUI.php | 2 +- Services/Badge/classes/class.ilBadgePersonalTableGUI.php | 2 +- Services/Badge/classes/class.ilBadgeTableGUI.php | 2 +- Services/Badge/classes/class.ilBadgeWAC.php | 6 +++--- Services/Badge/classes/class.ilObjectBadgeTableGUI.php | 2 +- Services/Badge/test/BadgeParentTest.php | 8 ++++---- Services/Badge/test/ModalTest.php | 2 +- Services/Badge/test/PresentationHeaderTest.php | 2 +- Services/Badge/test/TileTest.php | 8 ++++---- Services/Badge/test/TileViewTest.php | 4 ++-- 13 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Services/Badge/classes/Sorting.php b/Services/Badge/classes/Sorting.php index e2311ef6027e..cbd8f2b73e7a 100644 --- a/Services/Badge/classes/Sorting.php +++ b/Services/Badge/classes/Sorting.php @@ -100,6 +100,6 @@ private function reverse(): int private function minus(): Closure { - return static fn (int $x, int $y): int => $x - $y; + return static fn(int $x, int $y): int => $x - $y; } } diff --git a/Services/Badge/classes/Tile.php b/Services/Badge/classes/Tile.php index 4f4e2572e0ca..3acb0852edad 100644 --- a/Services/Badge/classes/Tile.php +++ b/Services/Badge/classes/Tile.php @@ -56,7 +56,7 @@ public function __construct( $this->sign_file = Closure::fromCallable($sign_file); if (!$format_date) { class_exists(ilDateTime::class); // Ensure ilDateTime is loaded as IL_CAL_UNIX is defined in ilDateTime.php. - $format_date = static fn ($date, int $format = IL_CAL_UNIX): string => ( + $format_date = static fn($date, int $format = IL_CAL_UNIX): string => ( ilDatePresentation::formatDate(new ilDateTime($date, $format)) ); } @@ -150,7 +150,7 @@ public function modalContent(ilBadge $badge): ModalContent $awarded_by = $this->parent->asProperty($badge); return new ModalContent($badge, [ $this->txt('criteria') => $badge->getCriteria(), - ...(null !== $awarded_by ? [$this->txt('awarded_by') => $awarded_by] : []), + ...(null !== $awarded_by ? [$this->txt('awarded_by') => $awarded_by] : []), $this->txt('valid_until') => $this->tryFormating($badge->getValid()), ]); } diff --git a/Services/Badge/classes/class.ilBadgeHandler.php b/Services/Badge/classes/class.ilBadgeHandler.php index 63b2556bab3f..0baeb16c078f 100644 --- a/Services/Badge/classes/class.ilBadgeHandler.php +++ b/Services/Badge/classes/class.ilBadgeHandler.php @@ -97,7 +97,8 @@ public function setComponents(array $a_components = null): void $a_components = null; } $this->settings->set( - 'components', $a_components !== null + 'components', + $a_components !== null ? serialize(array_unique($a_components)) : '' ); @@ -200,7 +201,8 @@ public function setInactiveTypes(array $a_types = null): void $a_types = null; } $this->settings->set( - 'inactive_types', $a_types !== null + 'inactive_types', + $a_types !== null ? serialize(array_unique($a_types)) : '' ); diff --git a/Services/Badge/classes/class.ilBadgeManagementGUI.php b/Services/Badge/classes/class.ilBadgeManagementGUI.php index f70d806153fe..ab6417d0cc80 100644 --- a/Services/Badge/classes/class.ilBadgeManagementGUI.php +++ b/Services/Badge/classes/class.ilBadgeManagementGUI.php @@ -392,7 +392,7 @@ protected function saveBadge(): void if ($form->getInput('img_mode') === 'up') { $badge->uploadImage($_FILES['img']); } else { - $tmpl = new ilBadgeImageTemplate($form->getInput('tmpl')); + $tmpl = new ilBadgeImageTemplate($form->getInput('tmpl')); $badge->importImage($tmpl->getImage(), $tmpl->getImagePath()); } } catch (BadgeException $e) { diff --git a/Services/Badge/classes/class.ilBadgePersonalTableGUI.php b/Services/Badge/classes/class.ilBadgePersonalTableGUI.php index 798e26b044c1..69de19d7402e 100644 --- a/Services/Badge/classes/class.ilBadgePersonalTableGUI.php +++ b/Services/Badge/classes/class.ilBadgePersonalTableGUI.php @@ -106,7 +106,7 @@ public function getItems(int $a_user_id): void "parent_title" => $parent ? $parent["title"] : null, "parent" => $parent, "active" => (bool) $ass->getPosition(), - "renderer" => fn () => $this->tile->asTitle( + "renderer" => fn() => $this->tile->asTitle( $this->tile->modalContentWithAssignment($badge, $ass) ), ); diff --git a/Services/Badge/classes/class.ilBadgeTableGUI.php b/Services/Badge/classes/class.ilBadgeTableGUI.php index 0357ddda5031..3a8f31f77eac 100644 --- a/Services/Badge/classes/class.ilBadgeTableGUI.php +++ b/Services/Badge/classes/class.ilBadgeTableGUI.php @@ -123,7 +123,7 @@ public function getItems(int $a_parent_obj_id): void ? ilBadge::getExtendedTypeCaption($badge->getTypeInstance()) : $badge->getTypeInstance()->getCaption(), "manual" => (!$badge->getTypeInstance() instanceof ilBadgeAuto), - "renderer" => fn () => $this->tile->asTitle($this->tile->modalContent($badge)), + "renderer" => fn() => $this->tile->asTitle($this->tile->modalContent($badge)), ); } diff --git a/Services/Badge/classes/class.ilBadgeWAC.php b/Services/Badge/classes/class.ilBadgeWAC.php index 4ca2dc7851aa..16e413dd37fe 100644 --- a/Services/Badge/classes/class.ilBadgeWAC.php +++ b/Services/Badge/classes/class.ilBadgeWAC.php @@ -70,7 +70,7 @@ private function hasAccessToBadgeParentIdNode( \ILIAS\DI\Container $DIC, int $badge_id, bool $has_global_badge_administration_access - ) : bool { + ): bool { // If the acting user still does not have access, check if the image is used in an object badge type $badge = new ilBadge($badge_id); if ($badge->getParentId() > 0) { @@ -102,7 +102,7 @@ private function hasAccessToBadgeParentIdNode( return $has_access; } - private function isAssignedBadge(\ILIAS\DI\Container $DIC, int $badge_id) : bool + private function isAssignedBadge(\ILIAS\DI\Container $DIC, int $badge_id): bool { // First, check all badge assignments of the current user for a match $badges_of_user = ilBadgeAssignment::getInstancesByUserId($DIC->user()->getId()); @@ -115,7 +115,7 @@ private function isAssignedBadge(\ILIAS\DI\Container $DIC, int $badge_id) : bool return false; } - private function isAssignedBadgeOfPublishedUserProfile(\ILIAS\DI\Container $DIC, int $badge_id) : bool + private function isAssignedBadgeOfPublishedUserProfile(\ILIAS\DI\Container $DIC, int $badge_id): bool { // It seems the badge is not assigned to the curent user, so check if the profile of the badge user is made visible $assignments = ilBadgeAssignment::getInstancesByBadgeId($badge_id); diff --git a/Services/Badge/classes/class.ilObjectBadgeTableGUI.php b/Services/Badge/classes/class.ilObjectBadgeTableGUI.php index cab3ef9e9528..9a9257183bf0 100644 --- a/Services/Badge/classes/class.ilObjectBadgeTableGUI.php +++ b/Services/Badge/classes/class.ilObjectBadgeTableGUI.php @@ -132,7 +132,7 @@ public function getItems(): void 'container_deleted' => (bool) ($badge_item['deleted'] ?? false), 'container_id' => (int) $badge_item['parent_id'], 'container_type' => $badge_item['parent_type'], - 'renderer' => fn () => $this->tile->asTitle( + 'renderer' => fn() => $this->tile->asTitle( $this->tile->modalContent(new ilBadge((int) $badge_item['id'])) ) ]; diff --git a/Services/Badge/test/BadgeParentTest.php b/Services/Badge/test/BadgeParentTest.php index c68ff3a6bda0..191ec84f763f 100644 --- a/Services/Badge/test/BadgeParentTest.php +++ b/Services/Badge/test/BadgeParentTest.php @@ -61,7 +61,7 @@ public function testShowWithParentReadRight(): void $standard_link = $this->getMockBuilder(StandardLink::class)->disableOriginalConstructor()->getMock(); $ui = $this->getMockBuilder(UIServices::class)->disableOriginalConstructor()->getMock(); - $language->method('txt')->willReturnCallback(static fn (string $name): string => $name . ' translated'); + $language->method('txt')->willReturnCallback(static fn(string $name): string => $name . ' translated'); $listing->expects(self::once())->method('descriptive')->with([ 'object translated' => $legacy, @@ -97,7 +97,7 @@ public function testShowWithParentReadRight(): void return 'Some image path.'; }; - $references_of = static fn (): array => [89]; + $references_of = static fn(): array => [89]; $link_to = function (int $ref_id): string { $this->assertSame(89, $ref_id); @@ -124,7 +124,7 @@ public function testShowWithoutParentReadRight(): void $renderer = $this->getMockBuilder(Renderer::class)->disableOriginalConstructor()->getMock(); $ui = $this->getMockBuilder(UIServices::class)->disableOriginalConstructor()->getMock(); - $language->method('txt')->willReturnCallback(static fn (string $name): string => $name . ' translated'); + $language->method('txt')->willReturnCallback(static fn(string $name): string => $name . ' translated'); $listing->expects(self::once())->method('descriptive')->with([ 'object translated' => $legacy, @@ -157,7 +157,7 @@ public function testShowWithoutParentReadRight(): void return 'Some image path.'; }; - $references_of = static fn (): array => [89]; + $references_of = static fn(): array => [89]; $link_to = function (int $ref_id): string { $this->assertSame(89, $ref_id); diff --git a/Services/Badge/test/ModalTest.php b/Services/Badge/test/ModalTest.php index f518eeeb82a0..67b24b9fb271 100644 --- a/Services/Badge/test/ModalTest.php +++ b/Services/Badge/test/ModalTest.php @@ -90,7 +90,7 @@ public function testComponents(): void $content->method('badge')->willReturn($badge); $content->method('properties')->willReturn($properties); - $modal = new Modal($container, fn (string $file): string => '/'); + $modal = new Modal($container, fn(string $file): string => '/'); $this->assertSame([$image_component, $divider_component, $item_component], $modal->components($content)); } diff --git a/Services/Badge/test/PresentationHeaderTest.php b/Services/Badge/test/PresentationHeaderTest.php index 5c3e21d86b70..28d5f48f6a4c 100644 --- a/Services/Badge/test/PresentationHeaderTest.php +++ b/Services/Badge/test/PresentationHeaderTest.php @@ -76,7 +76,7 @@ public function testShow(bool $additional = false): void )->willReturnOnConsecutiveCalls('list URL', 'manage URL'); $language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock(); - $language->method('txt')->willReturnCallback(static fn (string $name): string => $name); + $language->method('txt')->willReturnCallback(static fn(string $name): string => $name); $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); $container->expects(self::once())->method('toolbar')->willReturn($toolbar); diff --git a/Services/Badge/test/TileTest.php b/Services/Badge/test/TileTest.php index fb84b2b7c32d..15ca83491d3d 100644 --- a/Services/Badge/test/TileTest.php +++ b/Services/Badge/test/TileTest.php @@ -53,8 +53,8 @@ public function testConstruct(): void $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); $parent = $this->getMockBuilder(BadgeParent::class)->disableOriginalConstructor()->getMock(); $modal = $this->getMockBuilder(Modal::class)->disableOriginalConstructor()->getMock(); - $sign_file = static fn (string $x): string => ''; - $format_date = static fn (int $x): string => ''; + $sign_file = static fn(string $x): string => ''; + $format_date = static fn(int $x): string => ''; $this->assertInstanceOf(Tile::class, new Tile($container, $parent, $modal, $sign_file, $format_date)); } @@ -91,7 +91,7 @@ public function testInDeck(): void $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); $parent = $this->getMockBuilder(BadgeParent::class)->disableOriginalConstructor()->getMock(); $modal = $this->getMockBuilder(Modal::class)->disableOriginalConstructor()->getMock(); - $format_date = fn (int $x): string => 'Dummy'; + $format_date = fn(int $x): string => 'Dummy'; $sign_file = function (string $path) use ($signed_file, $badge_image_path): string { $this->assertSame($badge_image_path, $path); return $signed_file; @@ -136,7 +136,7 @@ public function testInDeck(): void ); $language->method('txt')->willReturnCallback( - static fn (string $lang_key) => 'Translated: ' . $lang_key + static fn(string $lang_key) => 'Translated: ' . $lang_key ); $container->method('ui')->willReturn($ui); diff --git a/Services/Badge/test/TileViewTest.php b/Services/Badge/test/TileViewTest.php index 0ff4454526c9..4e7b55ee5de2 100644 --- a/Services/Badge/test/TileViewTest.php +++ b/Services/Badge/test/TileViewTest.php @@ -82,7 +82,7 @@ public function testShow(): void $ctrl = $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock(); $language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock(); - $language->method('txt')->willReturnCallback(static fn (string $name): string => $name); + $language->method('txt')->willReturnCallback(static fn(string $name): string => $name); $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); $container->method('http')->willReturn($http); @@ -94,7 +94,7 @@ public function testShow(): void $tile = $this->getMockBuilder(Tile::class)->disableOriginalConstructor()->getMock(); $head = $this->getMockBuilder(PresentationHeader::class)->disableOriginalConstructor()->getMock(); - $assignments_of_user = static fn () => []; + $assignments_of_user = static fn() => []; $tile = new TileView($container, 'Some class.', $tile, $head, $assignments_of_user); $this->assertEquals('', $tile->show());