Skip to content

Commit

Permalink
Badge: Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Apr 11, 2024
1 parent ff0aac3 commit e3007a0
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Services/Badge/classes/Sorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions Services/Badge/classes/Tile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}
Expand Down Expand Up @@ -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()),
]);
}
Expand Down
6 changes: 4 additions & 2 deletions Services/Badge/classes/class.ilBadgeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
: ''
);
Expand Down Expand Up @@ -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))
: ''
);
Expand Down
2 changes: 1 addition & 1 deletion Services/Badge/classes/class.ilBadgeManagementGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Services/Badge/classes/class.ilBadgePersonalTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
),
);
Expand Down
2 changes: 1 addition & 1 deletion Services/Badge/classes/class.ilBadgeTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
}

Expand Down
6 changes: 3 additions & 3 deletions Services/Badge/classes/class.ilBadgeWAC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Services/Badge/classes/class.ilObjectBadgeTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
)
];
Expand Down
8 changes: 4 additions & 4 deletions Services/Badge/test/BadgeParentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Services/Badge/test/ModalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion Services/Badge/test/PresentationHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Services/Badge/test/TileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Services/Badge/test/TileViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down

0 comments on commit e3007a0

Please sign in to comment.