Autoformat

This commit is contained in:
brabli
2025-02-26 09:49:10 +00:00
parent 623fc60af2
commit fc9161b2d8
2 changed files with 13 additions and 11 deletions

View File

@@ -15,5 +15,7 @@ final readonly class BadgePalette
* @param string $backgroundColourClass Background colour Tailwind class * @param string $backgroundColourClass Background colour Tailwind class
*/ */
public function __construct(public string $textColourClass, public string $borderColourClass, public string $backgroundColourClass) public function __construct(public string $textColourClass, public string $borderColourClass, public string $backgroundColourClass)
{} {
}
} }

View File

@@ -9,7 +9,7 @@ use Pcm\BadgeBundle\Interface\BadgeableInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use TailwindMerge\TailwindMerge; use TailwindMerge\TailwindMerge;
#[AsTwigComponent(name: 'Pcm:Badge', template: "@PcmBadge/Badge.html.twig")] #[AsTwigComponent(name: 'Pcm:Badge', template: '@PcmBadge/Badge.html.twig')]
final class Badge final class Badge
{ {
public string $finalClasses; public string $finalClasses;
@@ -19,21 +19,21 @@ final class Badge
} }
/** /**
* @param ?BadgeableInterface $obj The object to be converted into a badge. * @param ?BadgeableInterface $obj the object to be converted into a badge
* @param ?string $class Extra classes to add to the badge element. * @param ?string $class Extra classes to add to the badge element.
* These will override the base classes in case * These will override the base classes in case
* of conflicts. * of conflicts.
* @param ?string $colour Specify the colour of an objectless badge. * @param ?string $colour specify the colour of an objectless badge
* @param bool $outline If the badge should be rendered as an outline. * @param bool $outline if the badge should be rendered as an outline
*/ */
public function mount(?BadgeableInterface $obj = null, ?string $class = null, string $colour = null, bool $outline = false): void public function mount(?BadgeableInterface $obj = null, ?string $class = null, ?string $colour = null, bool $outline = false): void
{ {
if (!$obj && !$colour) { if (!$obj && !$colour) {
throw new \RuntimeException(sprintf("You must specify either a colour an instance of \"%s\".", BadgeableInterface::class)); throw new \RuntimeException(sprintf('You must specify either a colour an instance of "%s".', BadgeableInterface::class));
} }
if ($obj && $colour) { if ($obj && $colour) {
throw new \RuntimeException(sprintf("You have specified both the colour \"%s\" and an instance of \"%s\". Please use one or the other.", $colour, $obj::class)); throw new \RuntimeException(sprintf('You have specified both the colour "%s" and an instance of "%s". Please use one or the other.', $colour, $obj::class));
} }
if ($obj) { if ($obj) {
@@ -41,14 +41,14 @@ final class Badge
} }
if ($colour) { if ($colour) {
$cases = array_map(fn(EnumBadge $b) => strtolower($b->name), EnumBadge::cases()); $cases = array_map(fn (EnumBadge $b) => strtolower($b->name), EnumBadge::cases());
if (!in_array($colour, $cases)) { if (!in_array($colour, $cases)) {
$formattedCases = implode(", ", array_map(fn(string $s) => '"'.$s.'"', $cases)); $formattedCases = implode(', ', array_map(fn (string $s) => '"'.$s.'"', $cases));
throw new \RuntimeException(sprintf('"%s" is not a valid Badge colour. Available options are: %s', $colour, $formattedCases)); throw new \RuntimeException(sprintf('"%s" is not a valid Badge colour. Available options are: %s', $colour, $formattedCases));
} }
$colour = strtoupper($colour); $colour = strtoupper($colour);
$palette = EnumBadge::{$colour}->getPalette(); $palette = EnumBadge::{$colour}->getPalette();
} }