Lines 100.00% 6 / 6
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
CustomMedal 100.00% 6 / 6 100.00% 2 / 2 6 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 image 100.00% 5 / 5 100.00% 1 / 1 5
1<?php
2
3declare(strict_types=1);
4
5namespace App\Medal;
6
7/**
8 * A custom medal: one an agent can't take from the stats, as in 4e-website's
9 * MedalChecker::$customMedals (the app's data/CustomMedals.kt).
10 */
11final readonly class CustomMedal
12{
13    /**
14     * @param string       $group anomaly, annual or event
15     * @param list<string> $tiers the tiers in 4e's order, empty for a medal without tiers
16     */
17    public function __construct(
18        public string $group,
19        public string $key,
20        public string $title,
21        public array $tiers = [],
22    ) {
23    }
24
25    /** The image for [$tier] ("" for none), as MedalChecker::getBadgeName. */
26    public function image(string $tier): string
27    {
28        $suffix = '' === $tier ? '' : '_'.$tier;
29
30        return 'custom_medals/'.match ($this->group) {
31            'anomaly' => 'anomaly_'.$this->key.$suffix,
32            'event' => 'event_badge_'.$this->key.$suffix,
33            default => 'badge_'.$this->key.$suffix,
34        }.'.webp';
35    }
36}