Skip to content

Commit

Permalink
Required child classes of Values\Translation to implement Stringable
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Apr 24, 2024
1 parent 4b0a3e5 commit f09a2bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/contracts/Repository/Values/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

namespace Ibexa\Contracts\Core\Repository\Values;

use Stringable;

/**
* Base class fro translation messages.
* Abstract for UI translation messages, use its extensions: Translation\Message, Translation\Plural.
*
* Use its extensions: Translation\Singular, Translation\Plural.
* @see \Ibexa\Contracts\Core\Repository\Values\Translation\Message
* @see \Ibexa\Contracts\Core\Repository\Values\Translation\Plural
*/
abstract class Translation extends ValueObject
abstract class Translation extends ValueObject implements Stringable
{
}

Expand Down
8 changes: 4 additions & 4 deletions src/contracts/Repository/Values/Translation/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public function __construct($message, array $values = [])
{
$this->message = $message;
$this->values = $values;

parent::__construct();
}

/**
* {@inheritdoc}
*/
public function __toString()
#[\Override]
public function __toString(): string
{
return strtr($this->message, $this->values);
}
Expand Down
8 changes: 4 additions & 4 deletions src/contracts/Repository/Values/Translation/Plural.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public function __construct($singular, $plural, array $values)
$this->singular = $singular;
$this->plural = $plural;
$this->values = $values;

parent::__construct();
}

/**
* {@inheritdoc}
*/
public function __toString()
#[\Override]
public function __toString(): string
{
return strtr(current($this->values) == 1 ? $this->plural : $this->singular, $this->values);
}
Expand Down

0 comments on commit f09a2bf

Please sign in to comment.