Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9156,18 +9156,6 @@ parameters:
count: 1
path: src/lib/MVC/Symfony/Translation/TranslatableExceptionsFileVisitor.php

-
message: '#^Access to an undefined property PhpParser\\Node\\Arg\|PhpParser\\Node\\VariadicPlaceholder\:\:\$value\.$#'
identifier: property.notFound
count: 2
path: src/lib/MVC/Symfony/Translation/ValidationErrorFileVisitor.php

-
message: '#^Method Ibexa\\Core\\MVC\\Symfony\\Translation\\ValidationErrorFileVisitor\:\:setLogger\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/lib/MVC/Symfony/Translation/ValidationErrorFileVisitor.php

-
message: '#^Parameter \#1 \$desc of method JMS\\TranslationBundle\\Model\\Message\:\:setDesc\(\) expects string, string\|null given\.$#'
identifier: argument.type
Expand Down
7 changes: 7 additions & 0 deletions src/bundle/Core/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,10 @@ services:
decoration_priority: 500
arguments:
$inner: '@.inner'


jms_translation.doc_parser:
class: Doctrine\Common\Annotations\DocParser
calls:
- [setImports, [{ desc: 'JMS\TranslationBundle\Annotation\Desc', domain: 'Ibexa\Core\MVC\Symfony\Translation\Annotation\Domain', ignore: 'JMS\TranslationBundle\Annotation\Ignore', meaning: 'JMS\TranslationBundle\Annotation\Meaning' }]]
- [setIgnoreNotImportedAnnotations, [true]]

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/bundle/Core/Resources/translations/validators.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
<trans-unit id="cb73b740405234713ab9927dd526edf48a250f60" resname="ibexa.identifier_already_exists">
<source>Identifier already exists.</source>
<target state="new">Identifier already exists.</target>
<target>Identifier already exists.</target>
<note>key: ibexa.identifier_already_exists</note>
</trans-unit>
</body>
Expand Down
7 changes: 3 additions & 4 deletions src/lib/FieldType/BaseTextType.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ protected function checkValueStructure(BaseValue $value): void
protected function buildUnknownValidatorError(string $parameterName, string $validatorIdentifier): ValidationError
{
return new ValidationError(
"Validator '$parameterName' is unknown",
/** @Desc("Validator '%parameter%' is unknown") */
"Validator '%parameter%' is unknown",
null,
[
$parameterName => $validatorIdentifier,
]
['%parameter%' => $parameterName]
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib/FieldType/ISBN/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Ibexa\Core\FieldType\FieldType;
use Ibexa\Core\FieldType\ValidationError;
use Ibexa\Core\FieldType\Value as BaseValue;
use JMS\TranslationBundle\Annotation\Ignore;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;

Expand Down Expand Up @@ -157,7 +158,10 @@
} else {
// ISBN-13 check
if (!$this->validateISBN13Checksum($isbnTestNumber, $error)) {
// TODO: Replace the out-parameter error flow with stable translation keys/templates.

Check warning on line 161 in src/lib/FieldType/ISBN/Type.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=ibexa_core&issues=AZ3YibkTKXKk9puB8CrZ&open=AZ3YibkTKXKk9puB8CrZ&pullRequest=735
// JMS extraction cannot read a ValidationError ID passed through a variable.
$validationErrors[] = new ValidationError(
/** @Ignore */
$error,
null,
[],
Expand Down
3 changes: 2 additions & 1 deletion src/lib/FieldType/Keyword/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
class Type extends FieldType implements TranslationContainerInterface
{
public const MAX_KEYWORD_LENGTH = 255;
private const string ERROR_MESSAGE_MAX_KEYWORD_LENGTH = 'Keyword value must be less than or equal to 255 characters.';

/**
* Returns the field type identifier for this field type.
Expand Down Expand Up @@ -120,7 +121,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue)
);
} elseif (mb_strlen($keyword) > self::MAX_KEYWORD_LENGTH) {
$validationErrors[] = new ValidationError(
'Keyword value must be less than or equal to ' . self::MAX_KEYWORD_LENGTH . ' characters.',
self::ERROR_MESSAGE_MAX_KEYWORD_LENGTH,
null,
[],
'values'
Expand Down
4 changes: 4 additions & 0 deletions src/lib/FieldType/Validator/BaseNumericValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Ibexa\Core\FieldType\ValidationError;
use Ibexa\Core\FieldType\Validator;
use JMS\TranslationBundle\Annotation\Ignore;

abstract class BaseNumericValidator extends Validator
{
Expand All @@ -24,7 +25,10 @@
foreach ($constraints as $name => $value) {
$validationErrorMessage = $this->getConstraintsValidationErrorMessage($name, $value);
if (null !== $validationErrorMessage) {
// TODO: Return stable translation keys/templates instead of a computed message string.

Check warning on line 28 in src/lib/FieldType/Validator/BaseNumericValidator.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=ibexa_core&issues=AZ3YibolKXKk9puB8Cra&open=AZ3YibolKXKk9puB8Cra&pullRequest=735
// JMS extraction cannot read a ValidationError ID passed through a variable.
$validationErrors[] = new ValidationError(
/** @Ignore */
$validationErrorMessage,
null,
[
Expand Down
8 changes: 4 additions & 4 deletions src/lib/FieldType/Validator/StringLengthValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Ibexa\Core\FieldType\ValidationError;
use Ibexa\Core\FieldType\Validator;
use Ibexa\Core\FieldType\Value as BaseValue;
use JMS\TranslationBundle\Annotation\Desc;

/**
* Validator for checking min. and max. length of strings.
Expand Down Expand Up @@ -47,11 +48,10 @@ public function validateConstraints($constraints)
case 'maxStringLength':
if ($value !== false && !is_int($value) && !(null === $value)) {
$validationErrors[] = new ValidationError(
sprintf('Validator parameter \'%s\' value must be of integer type', self::PARAMETER_NAME),
/** @Desc("Validator parameter '%parameter%' value must be of integer type") */
"Validator parameter '%parameter%' value must be of integer type",
null,
[
self::PARAMETER_NAME => $name,
]
[self::PARAMETER_NAME => $name]
);
} elseif ($value < 0) {
$validationErrors[] = new ValidationError(
Expand Down
7 changes: 2 additions & 5 deletions src/lib/Limitation/SiteAccessLimitationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,9 @@ public function validate(APILimitationValue $limitationValue): array
foreach ($limitationValue->limitationValues as $key => $value) {
if (!isset($siteAccessList[$value])) {
$validationErrors[] = new ValidationError(
"\$limitationValue->limitationValues[%key%] => Invalid SiteAccess value \"$value\"",
"\$limitationValue->limitationValues[%key%] => Invalid SiteAccess value '%value%'",
null,
[
'value' => $value,
'key' => $key,
]
['%key%' => $key, '%value%' => $value]
);
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/lib/MVC/Symfony/Translation/Annotation/Domain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Core\MVC\Symfony\Translation\Annotation;

use JMS\TranslationBundle\Exception\RuntimeException;

/**
* @Annotation
*/
final class Domain
{
/** @var string @Required */
public $value;

public function __construct()
{
if (0 === func_num_args()) {
return;
}

$values = func_get_arg(0);

if (!isset($values['value'])) {
throw new RuntimeException('The "value" attribute for annotation "@Domain" must be set.');
}

$this->value = $values['value'];
}
}
Loading
Loading