Skip to content

Commit 669c300

Browse files
authored
[BC break] Added implements \Stringable to Translation Value Object (#344)
For more details see #344 Breaking changes: Any class extending `\Ibexa\Contracts\Core\Repository\Values\Translation` will need to implement `\Stringable`.
1 parent 4b0a3e5 commit 669c300

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8530,11 +8530,6 @@ parameters:
85308530
count: 1
85318531
path: src/lib/Base/Exceptions/UnauthorizedException.php
85328532

8533-
-
8534-
message: "#^Cannot cast Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Translation to string\\.$#"
8535-
count: 1
8536-
path: src/lib/Base/Exceptions/UserPasswordValidationException.php
8537-
85388533
-
85398534
message: "#^Method Ibexa\\\\Core\\\\Base\\\\Exceptions\\\\UserPasswordValidationException\\:\\:__construct\\(\\) has parameter \\$errors with no value type specified in iterable type array\\.$#"
85408535
count: 1
@@ -43040,11 +43035,6 @@ parameters:
4304043035
count: 1
4304143036
path: tests/lib/FieldType/FloatValueValidatorTest.php
4304243037

43043-
-
43044-
message: "#^Cannot cast Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Translation to string\\.$#"
43045-
count: 1
43046-
path: tests/lib/FieldType/Generic/GenericTest.php
43047-
4304843038
-
4304943039
message: "#^Class Symfony\\\\Component\\\\Validator\\\\ConstraintViolation constructor invoked with 1 parameter, 6\\-10 required\\.$#"
4305043040
count: 1

src/contracts/Repository/Values/Translation.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88

99
namespace Ibexa\Contracts\Core\Repository\Values;
1010

11+
use Stringable;
12+
1113
/**
12-
* Base class fro translation messages.
14+
* Abstract for UI translation messages, use its extensions: Translation\Message, Translation\Plural.
1315
*
14-
* Use its extensions: Translation\Singular, Translation\Plural.
16+
* @see \Ibexa\Contracts\Core\Repository\Values\Translation\Message
17+
* @see \Ibexa\Contracts\Core\Repository\Values\Translation\Plural
1518
*/
16-
abstract class Translation extends ValueObject
19+
abstract class Translation extends ValueObject implements Stringable
1720
{
1821
}
1922

src/contracts/Repository/Values/Translation/Message.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function __construct($message, array $values = [])
4242
{
4343
$this->message = $message;
4444
$this->values = $values;
45+
46+
parent::__construct();
4547
}
4648

47-
/**
48-
* {@inheritdoc}
49-
*/
50-
public function __toString()
49+
#[\Override]
50+
public function __toString(): string
5151
{
5252
return strtr($this->message, $this->values);
5353
}

src/contracts/Repository/Values/Translation/Plural.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public function __construct($singular, $plural, array $values)
6767
$this->singular = $singular;
6868
$this->plural = $plural;
6969
$this->values = $values;
70+
71+
parent::__construct();
7072
}
7173

72-
/**
73-
* {@inheritdoc}
74-
*/
75-
public function __toString()
74+
#[\Override]
75+
public function __toString(): string
7676
{
7777
return strtr(current($this->values) == 1 ? $this->plural : $this->singular, $this->values);
7878
}

0 commit comments

Comments
 (0)