mirror of
https://github.com/symfony/ux-translator.git
synced 2026-03-24 00:12:19 +01:00
Run PHP-CS-Fixer (no_useless_else & static_lambda)
This commit is contained in:
@@ -52,14 +52,14 @@ class Configuration implements ConfigurationInterface
|
|||||||
->canBeUnset()
|
->canBeUnset()
|
||||||
->beforeNormalization()
|
->beforeNormalization()
|
||||||
->ifString()
|
->ifString()
|
||||||
->then(fn ($v) => ['elements' => [$v]])
|
->then(static fn ($v) => ['elements' => [$v]])
|
||||||
->end()
|
->end()
|
||||||
->beforeNormalization()
|
->beforeNormalization()
|
||||||
->ifTrue(function ($v) { return \is_array($v) && is_numeric(key($v)); })
|
->ifTrue(static function ($v) { return \is_array($v) && is_numeric(key($v)); })
|
||||||
->then(function ($v) { return ['elements' => $v]; })
|
->then(static function ($v) { return ['elements' => $v]; })
|
||||||
->end()
|
->end()
|
||||||
->validate()
|
->validate()
|
||||||
->always(function ($v) {
|
->always(static function ($v) {
|
||||||
$isExclusive = null;
|
$isExclusive = null;
|
||||||
$elements = [];
|
$elements = [];
|
||||||
if (isset($v['type'])) {
|
if (isset($v['type'])) {
|
||||||
@@ -94,7 +94,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->scalarPrototype()->end()
|
->scalarPrototype()->end()
|
||||||
->beforeNormalization()
|
->beforeNormalization()
|
||||||
->ifString()
|
->ifString()
|
||||||
->then(fn ($v) => [$v])
|
->then(static fn ($v) => [$v])
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
|
|||||||
@@ -82,12 +82,12 @@ final class IntlMessageParser
|
|||||||
) {
|
) {
|
||||||
if ($expectingCloseTag) {
|
if ($expectingCloseTag) {
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
return $this->error(
|
|
||||||
ErrorKind::UNMATCHED_CLOSING_TAG,
|
|
||||||
new Location(clone $this->position, clone $this->position)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->error(
|
||||||
|
ErrorKind::UNMATCHED_CLOSING_TAG,
|
||||||
|
new Location(clone $this->position, clone $this->position)
|
||||||
|
);
|
||||||
} elseif (
|
} elseif (
|
||||||
60 === $char /* `<` */
|
60 === $char /* `<` */
|
||||||
&& !$this->ignoreTag
|
&& !$this->ignoreTag
|
||||||
@@ -267,11 +267,11 @@ final class IntlMessageParser
|
|||||||
|| (125 === $ch /* `}` */ && $nestingLevel > 0)
|
|| (125 === $ch /* `}` */ && $nestingLevel > 0)
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
|
||||||
$this->bump();
|
|
||||||
|
|
||||||
return Utils::fromCodePoint($ch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->bump();
|
||||||
|
|
||||||
|
return Utils::fromCodePoint($ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -473,32 +473,32 @@ final class IntlMessageParser
|
|||||||
],
|
],
|
||||||
'err' => null,
|
'err' => null,
|
||||||
];
|
];
|
||||||
} else {
|
|
||||||
if (0 === s($skeleton)->length()) {
|
|
||||||
return $this->error(ErrorKind::EXPECT_DATE_TIME_SKELETON, $location);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dateTimePattern = $skeleton;
|
|
||||||
|
|
||||||
$style = [
|
|
||||||
'type' => SkeletonType::DATE_TIME,
|
|
||||||
'pattern' => $dateTimePattern,
|
|
||||||
'location' => $styleAndLocation['styleLocation'],
|
|
||||||
'parsedOptions' => [],
|
|
||||||
];
|
|
||||||
|
|
||||||
$type = 'date' === $argType ? Type::DATE : Type::TIME;
|
|
||||||
|
|
||||||
return [
|
|
||||||
'val' => [
|
|
||||||
'type' => $type,
|
|
||||||
'value' => $value,
|
|
||||||
'location' => $location,
|
|
||||||
'style' => $style,
|
|
||||||
],
|
|
||||||
'err' => null,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 === s($skeleton)->length()) {
|
||||||
|
return $this->error(ErrorKind::EXPECT_DATE_TIME_SKELETON, $location);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dateTimePattern = $skeleton;
|
||||||
|
|
||||||
|
$style = [
|
||||||
|
'type' => SkeletonType::DATE_TIME,
|
||||||
|
'pattern' => $dateTimePattern,
|
||||||
|
'location' => $styleAndLocation['styleLocation'],
|
||||||
|
'parsedOptions' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
$type = 'date' === $argType ? Type::DATE : Type::TIME;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'val' => [
|
||||||
|
'type' => $type,
|
||||||
|
'value' => $value,
|
||||||
|
'location' => $location,
|
||||||
|
'style' => $style,
|
||||||
|
],
|
||||||
|
'err' => null,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regular style or no style.
|
// Regular style or no style.
|
||||||
@@ -593,21 +593,20 @@ final class IntlMessageParser
|
|||||||
],
|
],
|
||||||
'err' => null,
|
'err' => null,
|
||||||
];
|
];
|
||||||
} else {
|
|
||||||
return [
|
|
||||||
'val' => [
|
|
||||||
'type' => Type::PLURAL,
|
|
||||||
'value' => $value,
|
|
||||||
'offset' => $pluralOffset,
|
|
||||||
'options' => $optionsResult['val'],
|
|
||||||
'pluralType' => 'plural' === $argType ? 'cardinal' : 'ordinal',
|
|
||||||
'location' => $location,
|
|
||||||
],
|
|
||||||
'err' => null,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// no break
|
return [
|
||||||
|
'val' => [
|
||||||
|
'type' => Type::PLURAL,
|
||||||
|
'value' => $value,
|
||||||
|
'offset' => $pluralOffset,
|
||||||
|
'options' => $optionsResult['val'],
|
||||||
|
'pluralType' => 'plural' === $argType ? 'cardinal' : 'ordinal',
|
||||||
|
'location' => $location,
|
||||||
|
],
|
||||||
|
'err' => null,
|
||||||
|
];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return $this->error(
|
return $this->error(
|
||||||
ErrorKind::INVALID_ARGUMENT_TYPE,
|
ErrorKind::INVALID_ARGUMENT_TYPE,
|
||||||
@@ -962,11 +961,11 @@ final class IntlMessageParser
|
|||||||
$this->bumpTo($index);
|
$this->bumpTo($index);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
$this->bumpTo($this->messageLength);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->bumpTo($this->messageLength);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ final class TypeScriptMessageParametersPrinter
|
|||||||
$value = implode(
|
$value = implode(
|
||||||
'|',
|
'|',
|
||||||
array_map(
|
array_map(
|
||||||
fn (string $val) => 'other' === $val ? 'string' : "'".$val."'",
|
static fn (string $val) => 'other' === $val ? 'string' : "'".$val."'",
|
||||||
$parameter['values']
|
$parameter['values']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ class TranslationsDumper
|
|||||||
return \sprintf(
|
return \sprintf(
|
||||||
'Message<{ %s }, %s>',
|
'Message<{ %s }, %s>',
|
||||||
implode(', ', $typeScriptParametersType),
|
implode(', ', $typeScriptParametersType),
|
||||||
implode('|', array_map(fn (string $locale) => "'$locale'", array_unique($locales))),
|
implode('|', array_map(static fn (string $locale) => "'$locale'", array_unique($locales))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ class TranslationsDumper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter empty patterns and deduplicate
|
// Filter empty patterns and deduplicate
|
||||||
$patterns = array_reduce($patterns, function (array $carry, string $pattern) {
|
$patterns = array_reduce($patterns, static function (array $carry, string $pattern) {
|
||||||
$trimmed = trim($pattern);
|
$trimmed = trim($pattern);
|
||||||
if ('' !== $trimmed && !\in_array($trimmed, $carry, true)) {
|
if ('' !== $trimmed && !\in_array($trimmed, $carry, true)) {
|
||||||
$carry[] = $trimmed;
|
$carry[] = $trimmed;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class FrameworkAppKernel extends Kernel
|
|||||||
|
|
||||||
public function registerContainerConfiguration(LoaderInterface $loader): void
|
public function registerContainerConfiguration(LoaderInterface $loader): void
|
||||||
{
|
{
|
||||||
$loader->load(function (ContainerBuilder $container) {
|
$loader->load(static function (ContainerBuilder $container) {
|
||||||
$container->loadFromExtension('framework', [
|
$container->loadFromExtension('framework', [
|
||||||
'secret' => '$ecret',
|
'secret' => '$ecret',
|
||||||
'test' => true,
|
'test' => true,
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ class TranslationsDumperTest extends TestCase
|
|||||||
{
|
{
|
||||||
yield 'included patterns' => [
|
yield 'included patterns' => [
|
||||||
['symfony.*', 'notification.*'],
|
['symfony.*', 'notification.*'],
|
||||||
function (self $test, string $content) {
|
static function (self $test, string $content) {
|
||||||
// Should include keys matching patterns
|
// Should include keys matching patterns
|
||||||
$test->assertStringContainsString('symfony.great', $content);
|
$test->assertStringContainsString('symfony.great', $content);
|
||||||
$test->assertStringContainsString('symfony.what', $content);
|
$test->assertStringContainsString('symfony.what', $content);
|
||||||
@@ -226,7 +226,7 @@ class TranslationsDumperTest extends TestCase
|
|||||||
|
|
||||||
yield 'excluded patterns' => [
|
yield 'excluded patterns' => [
|
||||||
['!apples.*', '!what.*'],
|
['!apples.*', '!what.*'],
|
||||||
function (self $test, string $content) {
|
static function (self $test, string $content) {
|
||||||
// Should exclude keys matching exclusion patterns
|
// Should exclude keys matching exclusion patterns
|
||||||
$test->assertStringNotContainsString('apples.count', $content);
|
$test->assertStringNotContainsString('apples.count', $content);
|
||||||
$test->assertStringNotContainsString('what.count', $content);
|
$test->assertStringNotContainsString('what.count', $content);
|
||||||
@@ -240,7 +240,7 @@ class TranslationsDumperTest extends TestCase
|
|||||||
|
|
||||||
yield 'mixed patterns' => [
|
yield 'mixed patterns' => [
|
||||||
['symfony.*', 'notification.*', '!*.what*'],
|
['symfony.*', 'notification.*', '!*.what*'],
|
||||||
function (self $test, string $content) {
|
static function (self $test, string $content) {
|
||||||
// Should include symfony.* but exclude *.what*
|
// Should include symfony.* but exclude *.what*
|
||||||
$test->assertStringContainsString('symfony.great', $content);
|
$test->assertStringContainsString('symfony.great', $content);
|
||||||
$test->assertStringNotContainsString('symfony.what', $content);
|
$test->assertStringNotContainsString('symfony.what', $content);
|
||||||
@@ -255,7 +255,7 @@ class TranslationsDumperTest extends TestCase
|
|||||||
|
|
||||||
yield 'wildcard patterns' => [
|
yield 'wildcard patterns' => [
|
||||||
['*.count.*'],
|
['*.count.*'],
|
||||||
function (self $test, string $content) {
|
static function (self $test, string $content) {
|
||||||
// Should include keys matching *.count.*
|
// Should include keys matching *.count.*
|
||||||
$test->assertStringContainsString('apples.count.0', $content);
|
$test->assertStringContainsString('apples.count.0', $content);
|
||||||
$test->assertStringContainsString('what.count.1', $content);
|
$test->assertStringContainsString('what.count.1', $content);
|
||||||
@@ -268,7 +268,7 @@ class TranslationsDumperTest extends TestCase
|
|||||||
|
|
||||||
yield 'empty pattern array' => [
|
yield 'empty pattern array' => [
|
||||||
[],
|
[],
|
||||||
function (self $test, string $content) {
|
static function (self $test, string $content) {
|
||||||
// Should include all keys when pattern array is empty
|
// Should include all keys when pattern array is empty
|
||||||
$test->assertStringContainsString('symfony.great', $content);
|
$test->assertStringContainsString('symfony.great', $content);
|
||||||
$test->assertStringContainsString('symfony.what', $content);
|
$test->assertStringContainsString('symfony.what', $content);
|
||||||
@@ -281,7 +281,7 @@ class TranslationsDumperTest extends TestCase
|
|||||||
|
|
||||||
yield 'empty string patterns' => [
|
yield 'empty string patterns' => [
|
||||||
['', 'symfony.*', ''],
|
['', 'symfony.*', ''],
|
||||||
function (self $test, string $content) {
|
static function (self $test, string $content) {
|
||||||
// Empty strings should be filtered out, only 'symfony.*' should apply
|
// Empty strings should be filtered out, only 'symfony.*' should apply
|
||||||
$test->assertStringContainsString('symfony.great', $content);
|
$test->assertStringContainsString('symfony.great', $content);
|
||||||
$test->assertStringContainsString('symfony.what', $content);
|
$test->assertStringContainsString('symfony.what', $content);
|
||||||
@@ -294,7 +294,7 @@ class TranslationsDumperTest extends TestCase
|
|||||||
|
|
||||||
yield 'malformed exclusion pattern' => [
|
yield 'malformed exclusion pattern' => [
|
||||||
['!'],
|
['!'],
|
||||||
function (self $test, string $content) {
|
static function (self $test, string $content) {
|
||||||
// A single '!' should be treated as invalid and include all keys
|
// A single '!' should be treated as invalid and include all keys
|
||||||
$test->assertStringContainsString('symfony.great', $content);
|
$test->assertStringContainsString('symfony.great', $content);
|
||||||
$test->assertStringContainsString('notification.comment_created', $content);
|
$test->assertStringContainsString('notification.comment_created', $content);
|
||||||
@@ -304,7 +304,7 @@ class TranslationsDumperTest extends TestCase
|
|||||||
|
|
||||||
yield 'patterns with special regex characters in key names' => [
|
yield 'patterns with special regex characters in key names' => [
|
||||||
['animal.*'],
|
['animal.*'],
|
||||||
function (self $test, string $content) {
|
static function (self $test, string $content) {
|
||||||
// Should match keys with dashes and underscores
|
// Should match keys with dashes and underscores
|
||||||
$test->assertStringContainsString('animal.dog-cat', $content);
|
$test->assertStringContainsString('animal.dog-cat', $content);
|
||||||
$test->assertStringContainsString('animal.dog_cat', $content);
|
$test->assertStringContainsString('animal.dog_cat', $content);
|
||||||
@@ -316,7 +316,7 @@ class TranslationsDumperTest extends TestCase
|
|||||||
|
|
||||||
yield 'pattern matching keys starting with numeric' => [
|
yield 'pattern matching keys starting with numeric' => [
|
||||||
['0starts.*'],
|
['0starts.*'],
|
||||||
function (self $test, string $content) {
|
static function (self $test, string $content) {
|
||||||
// Should match keys starting with numeric characters
|
// Should match keys starting with numeric characters
|
||||||
$test->assertStringContainsString('0starts.with.numeric', $content);
|
$test->assertStringContainsString('0starts.with.numeric', $content);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user