Skip to content

Commit

Permalink
Merge branch 'dev-context-translator' into dev-datetime-period
Browse files Browse the repository at this point in the history
  • Loading branch information
cevro authored Oct 27, 2024
2 parents 61bf8db + ed50479 commit ff19071
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '8.1']
php: ['8.1']
steps:
- uses: actions/checkout@v2
name: Checkout
Expand Down
12 changes: 3 additions & 9 deletions src/Components/DIComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@
*/
abstract class DIComponent extends Control
{
protected readonly Container $container;
protected ?GettextTranslator $translator;

public function __construct(Container $container)
{
$this->container = $container;
public function __construct(
protected readonly Container $container
) {
$container->callInjects($this);
}

protected function getContext(): Container
{
return $this->container;
}

public function injectTranslator(?GettextTranslator $translator): void
{
$this->translator = $translator;
Expand Down
13 changes: 11 additions & 2 deletions src/Localization/LangMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ public function __construct(array $variants)
* @phpstan-param TLang $key
* @phpstan-return TValue
*/
public function get(string $key): mixed
public function __get(string $lang): mixed
{
return $this->variants[$key] ?? null;
return $this->get($lang);
}

/**
* @phpstan-param TLang $lang
* @phpstan-return TValue
*/
public function get(string $lang): mixed
{
return $this->variants[$lang] ?? null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Logging/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Message
{
public function __construct(
public readonly string | Html $text,
public readonly string|Html $text,
public readonly MessageLevel $level
) {
}
Expand All @@ -21,7 +21,7 @@ public function __toArray(): array
{
return [
'text' => ($this->text instanceof Html) ? $this->text->toHtml() : $this->text,
'level' => $this->level,
'level' => $this->level->value,
];
}
}
14 changes: 7 additions & 7 deletions src/Price/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

namespace Fykosak\Utils\Price;

/**
* @phpstan-type TSerializedPrice array{currency:string,amount:float}
*/
final class Price
{
private float $amount;

public function __construct(
public readonly Currency $currency,
private float $amount = 0,
private readonly Currency $currency,
?float $amount = null
) {
$this->amount = $amount ?? 0;
}

/**
* @throws \LogicException
*/
public function add(Price $price): void
{
if ($this->currency !== $price->currency) {
if ($this->currency !== $price->getCurrency()) {
throw new \LogicException('Currencies are not a same');
}
$this->amount += $price->getAmount();
Expand All @@ -42,7 +42,7 @@ public function __toString(): string
}

/**
* @phpstan-return TSerializedPrice
* @phpstan-return array{currency:string,amount:float}
*/
public function __serialize(): array
{
Expand Down
1 change: 0 additions & 1 deletion src/UI/Navigation/NavItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class NavItem
{
/**
* @phpstan-param array<string,scalar> $linkParams
* @phpstan-param NavItem[] $children
*/
public function __construct(
public readonly Title $title,
Expand Down
8 changes: 4 additions & 4 deletions src/UI/PageTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
class PageTitle extends Title
{
public function __construct(
string | Html $title,
?string $id,
string|Html $title,
?string $icon = null,
public readonly string | Html | null $subTitle = null,
?string $id = null
public string|Html|null $subTitle = null
) {
parent::__construct($title, icon: $icon, id: $id);
parent::__construct($id, $title, $icon);
}

public function toHtml(bool $includeSubTitle = false): Html
Expand Down
6 changes: 3 additions & 3 deletions src/UI/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Title
public readonly string $id;

public function __construct(
public readonly string | Html $title,
public readonly ?string $icon = null,
?string $id = null,
?string $id,
public readonly string|Html $title,
public readonly ?string $icon = null
) {
$this->id = $id ?? Random::generate(10, 'a-z');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Tests/Price/TestCurrency.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TestCurrency extends BaseTest
public function testRender(): void
{
$currency = Currency::CZK;
Assert::same('2.00', $currency->format(2.0));
Assert::same('2.00 ', $currency->format(2.0));
}
}

Expand Down

0 comments on commit ff19071

Please sign in to comment.