diff --git a/src/Logging/Message.php b/src/Logging/Message.php index 1816464..16442a0 100644 --- a/src/Logging/Message.php +++ b/src/Logging/Message.php @@ -4,29 +4,20 @@ namespace Fykosak\Utils\Logging; -use Nette\SmartObject; use Nette\Utils\Html; class Message { - use SmartObject; - public const LVL_ERROR = 'danger'; public const LVL_WARNING = 'warning'; public const LVL_SUCCESS = 'success'; public const LVL_INFO = 'info'; public const LVL_PRIMARY = 'primary'; - public $text; - public string $level; - - /** - * @param string|Html $message - */ - public function __construct($message, string $level) - { - $this->text = $message; - $this->level = $level; + public function __construct( + public readonly string|Html $text, + public readonly string $level + ) { } /** diff --git a/src/Price/Currency.php b/src/Price/Currency.php index 65e3cbe..c6df72d 100644 --- a/src/Price/Currency.php +++ b/src/Price/Currency.php @@ -4,67 +4,20 @@ namespace Fykosak\Utils\Price; -use Nette\NotImplementedException; -use Nette\SmartObject; - /** * something like enum :) */ -final class Currency +enum Currency: string { - use SmartObject; - - public const EUR = 'EUR'; - public const CZK = 'CZK'; - - public string $value; - - /** - * @throws NotImplementedException - */ - public function __construct(string $currency) - { - $currency = strtoupper($currency); - if (!in_array($currency, [self::EUR, self::CZK])) { - throw new NotImplementedException(sprintf(_('Currency "%s" is not supported'), $currency)); - } - $this->value = $currency; - } - - /** - * @return self[] - */ - public static function cases(): array - { - return [new self(self::CZK), new self(self::EUR)]; - } - - public static function tryFrom(string $currency): ?self - { - try { - return new self($currency); - } catch (NotImplementedException $exception) { - return null; - } - } - - /** - * @throws NotImplementedException - */ - public static function from(string $currency): self - { - return new self($currency); - } + case EUR = 'EUR'; + case CZK = 'CZK'; public function getLabel(): string { - switch ($this->value) { - case self::EUR: - return '€'; - case self::CZK: - return 'Kč'; - } - return ''; + return match ($this) { + self::EUR => '€', + self::CZK => 'Kč', + }; } public function format(float $amount): string diff --git a/src/Price/Price.php b/src/Price/Price.php index 64fae1b..26554ed 100644 --- a/src/Price/Price.php +++ b/src/Price/Price.php @@ -4,22 +4,15 @@ namespace Fykosak\Utils\Price; -use Nette\SmartObject; - -/** - * @phpstan-type TSerializedPrice array{currency:string,amount:float} - */ final class Price { - use SmartObject; - - private Currency $currency; private float $amount; - public function __construct(Currency $currency, ?float $amount = null) - { + public function __construct( + private readonly Currency $currency, + ?float $amount = null + ) { $this->amount = $amount ?? 0; - $this->currency = $currency; } /** @@ -54,7 +47,7 @@ public function __toString(): string } /** - * @phpstan-return TSerializedPrice + * @phpstan-return array{currency:string,amount:float} */ public function __serialize(): array { diff --git a/src/UI/Navigation/NavItem.php b/src/UI/Navigation/NavItem.php index 3683fef..b873300 100644 --- a/src/UI/Navigation/NavItem.php +++ b/src/UI/Navigation/NavItem.php @@ -5,35 +5,19 @@ namespace Fykosak\Utils\UI\Navigation; use Fykosak\Utils\UI\Title; -use Nette\SmartObject; class NavItem { - use SmartObject; - - public string $destination; - /** @phpstan-var array */ - public array $linkParams; - public Title $title; - /** @var NavItem[] */ - public array $children; - public bool $active; - /** * @phpstan-param array $linkParams * @phpstan-param NavItem[] $children */ public function __construct( - Title $title, - string $destination = '#', - array $linkParams = [], - array $children = [], - bool $active = false + public readonly Title $title, + public readonly string $destination = '#', + public readonly array $linkParams = [], + public readonly array $children = [], + public readonly bool $active = false ) { - $this->active = $active; - $this->destination = $destination; - $this->linkParams = $linkParams; - $this->title = $title; - $this->children = $children; } } diff --git a/src/UI/PageTitle.php b/src/UI/PageTitle.php index 983dc7b..9eb9085 100644 --- a/src/UI/PageTitle.php +++ b/src/UI/PageTitle.php @@ -8,17 +8,14 @@ class PageTitle extends Title { - /** @var string|Html|null */ - public $subTitle; - - /** - * @param string|Html $title - * @param string|Html|null $subTitle - */ - public function __construct(?string $id, $title, ?string $icon = null, $subTitle = null) + public function __construct( + ?string $id, + string|Html $title, + ?string $icon = null, + public string|Html|null $subTitle = null + ) { parent::__construct($id, $title, $icon); - $this->subTitle = $subTitle; } public function toHtml(bool $includeSubTitle = false): Html diff --git a/src/UI/Title.php b/src/UI/Title.php index b5fbeb8..5cbaf7b 100644 --- a/src/UI/Title.php +++ b/src/UI/Title.php @@ -9,18 +9,13 @@ class Title { - /** @var string|Html */ - public $title; - public ?string $icon; - public string $id; + public readonly string $id; - /** - * @param string|Html $title - */ - public function __construct(?string $id, $title, ?string $icon = null) - { - $this->title = $title; - $this->icon = $icon; + public function __construct( + ?string $id, + public readonly string|Html $title, + public readonly ?string $icon = null + ) { $this->id = $id ?? Random::generate(10, 'a-z'); }