Skip to content

Commit

Permalink
[BC break] Added implements \Stringable to Translation Value Obje…
Browse files Browse the repository at this point in the history
…ct (#344)

For more details see #344

Breaking changes:

Any class extending `\Ibexa\Contracts\Core\Repository\Values\Translation` will need to implement `\Stringable`.
  • Loading branch information
alongosz authored Apr 25, 2024
1 parent 4b0a3e5 commit 669c300
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8530,11 +8530,6 @@ parameters:
count: 1
path: src/lib/Base/Exceptions/UnauthorizedException.php

-
message: "#^Cannot cast Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Translation to string\\.$#"
count: 1
path: src/lib/Base/Exceptions/UserPasswordValidationException.php

-
message: "#^Method Ibexa\\\\Core\\\\Base\\\\Exceptions\\\\UserPasswordValidationException\\:\\:__construct\\(\\) has parameter \\$errors with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -43040,11 +43035,6 @@ parameters:
count: 1
path: tests/lib/FieldType/FloatValueValidatorTest.php

-
message: "#^Cannot cast Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Translation to string\\.$#"
count: 1
path: tests/lib/FieldType/Generic/GenericTest.php

-
message: "#^Class Symfony\\\\Component\\\\Validator\\\\ConstraintViolation constructor invoked with 1 parameter, 6\\-10 required\\.$#"
count: 1
Expand Down
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 669c300

Please sign in to comment.