Skip to content

Commit

Permalink
Fix return type of getTranslatedAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
dood- committed Jan 11, 2024
1 parent aca368e commit 1c91d13
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/guide/en/configuring-rules-via-php-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final class User

> **Note:** [readonly properties] are supported only starting from PHP 8.1.
Error messages may include an `{attribute}` placeholder that is replaced with the name of the property. If you would
Error messages may include `{attribute}` or `{Attribute}` placeholder that is replaced with the name of the property. If you would
like the name to be replaced with a custom value, you can specify it using the `Label` attribute:

```php
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/en/customizing-error-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ To use a non-default error message, pass a custom message/template when creating
`message` option is responsible for storing error message:

```php
new Required(message: '{attribute} is required.');
new Required(message: '{Attribute} is required.');
```

Some rules have multiple error messages and are overridden via different corresponding options.
Expand Down Expand Up @@ -113,13 +113,13 @@ use Yiisoft\Validator\Validator;
final class ChangePasswordForm implements AttributeTranslatorProviderInterface
{
public function __construct(
#[Required(message: '{attribute} обязателен для ввода.')]
#[Required(message: '{Attribute} обязателен для ввода.')]
public string $currentPassword = '',

#[Length(
min: 8,
skipOnEmpty: false,
lessThanMinMessage: '{attribute} должен быть сложный, не менее 8 символов.'
lessThanMinMessage: '{Attribute} должен быть сложный, не менее 8 символов.'
)]
public string $newPassword = '',
) {
Expand Down
5 changes: 2 additions & 3 deletions src/ValidationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,9 @@ public function getAttributeLabel(): ?string
/**
* Get translated attribute name.
*
* @return string|null Translated attribute name. `null` if a single value is validated and there is nothing
* to translate.
* @return string Translated attribute name. `value` if a single value is validated and a label is not set.
*/
public function getTranslatedAttribute(): ?string
public function getTranslatedAttribute(): string
{
$label = $this->attributeLabel ?? $this->attribute ?? 'value';

Expand Down

0 comments on commit 1c91d13

Please sign in to comment.