Skip to content

Commit eab7db5

Browse files
smnandrekbond
authored andcommitted
[CS] Optimize sprintf calls for PHP 8.4
1 parent fed00e2 commit eab7db5

File tree

106 files changed

+295
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+295
-290
lines changed

.php-cs-fixer.dist.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
EOF;
2424

2525
return (new PhpCsFixer\Config())
26+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
2627
->setRules([
2728
'@PHPUnit75Migration:risky' => true,
2829
'@Symfony' => true,
2930
'@Symfony:risky' => true,
3031
'header_comment' => ['header' => $fileHeaderComment],
32+
// TODO: Remove once the "compiler_optimized" set includes "sprintf"
33+
'native_function_invocation' => ['include' => ['@compiler_optimized', 'sprintf'], 'scope' => 'namespaced', 'strict' => true],
3134
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']],
3235
])
3336
->setRiskyAllowed(true)

src/Autocomplete/src/AutocompleteResultsExecutor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function fetchResults(EntityAutocompleterInterface $autocompleter, string
9898
}
9999

100100
if (!\is_callable($groupBy)) {
101-
throw new \InvalidArgumentException(sprintf('Option "group_by" must be callable, "%s" given.', get_debug_type($groupBy)));
101+
throw new \InvalidArgumentException(\sprintf('Option "group_by" must be callable, "%s" given.', get_debug_type($groupBy)));
102102
}
103103

104104
$optgroupLabels = [];

src/Autocomplete/src/Controller/EntityAutocompleteController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __invoke(string $alias, Request $request): Response
4242
{
4343
$autocompleter = $this->autocompleteFieldRegistry->getAutocompleter($alias);
4444
if (!$autocompleter) {
45-
throw new NotFoundHttpException(sprintf('No autocompleter found for "%s". Available autocompleters are: (%s)', $alias, implode(', ', $this->autocompleteFieldRegistry->getAutocompleterNames())));
45+
throw new NotFoundHttpException(\sprintf('No autocompleter found for "%s". Available autocompleters are: (%s)', $alias, implode(', ', $this->autocompleteFieldRegistry->getAutocompleterNames())));
4646
}
4747

4848
if ($autocompleter instanceof OptionsAwareEntityAutocompleterInterface) {

src/Autocomplete/src/DependencyInjection/AutocompleteFormTypePass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private function processEntityAutocompleteFieldTag(ContainerBuilder $container)
4040
foreach ($container->findTaggedServiceIds(self::ENTITY_AUTOCOMPLETE_FIELD_TAG, true) as $serviceId => $tag) {
4141
$serviceDefinition = $container->getDefinition($serviceId);
4242
if (!$serviceDefinition->hasTag('form.type')) {
43-
throw new \LogicException(sprintf('Service "%s" has the "%s" tag, but is not tagged with "form.type". Did you add the "%s" attribute to a class that is not a form type?', $serviceId, self::ENTITY_AUTOCOMPLETE_FIELD_TAG, AsEntityAutocompleteField::class));
43+
throw new \LogicException(\sprintf('Service "%s" has the "%s" tag, but is not tagged with "form.type". Did you add the "%s" attribute to a class that is not a form type?', $serviceId, self::ENTITY_AUTOCOMPLETE_FIELD_TAG, AsEntityAutocompleteField::class));
4444
}
4545
$alias = $this->getAlias($serviceId, $serviceDefinition, $tag);
4646

@@ -61,7 +61,7 @@ private function getAlias(string $serviceId, Definition $serviceDefinition, arra
6161
$class = $serviceDefinition->getClass();
6262
$attribute = AsEntityAutocompleteField::getInstance($class);
6363
if (null === $attribute) {
64-
throw new \LogicException(sprintf('The service "%s" either needs to have the #[%s] attribute above its class or its "%s" tag needs an "alias" key.', $serviceId, self::ENTITY_AUTOCOMPLETE_FIELD_TAG, AsEntityAutocompleteField::class));
64+
throw new \LogicException(\sprintf('The service "%s" either needs to have the #[%s] attribute above its class or its "%s" tag needs an "alias" key.', $serviceId, self::ENTITY_AUTOCOMPLETE_FIELD_TAG, AsEntityAutocompleteField::class));
6565
}
6666

6767
return $attribute->getAlias() ?: AsEntityAutocompleteField::shortName($class);
@@ -72,7 +72,7 @@ private function processEntityAutocompleterTag(ContainerBuilder $container)
7272
$servicesMap = [];
7373
foreach ($container->findTaggedServiceIds(self::ENTITY_AUTOCOMPLETER_TAG, true) as $serviceId => $tag) {
7474
if (!isset($tag[0]['alias'])) {
75-
throw new \LogicException(sprintf('The "%s" tag of the "%s" service needs "alias" key.', self::ENTITY_AUTOCOMPLETER_TAG, $serviceId));
75+
throw new \LogicException(\sprintf('The "%s" tag of the "%s" service needs "alias" key.', self::ENTITY_AUTOCOMPLETER_TAG, $serviceId));
7676
}
7777

7878
$servicesMap[$tag[0]['alias']] = new Reference($serviceId);

src/Autocomplete/src/Doctrine/EntityMetadata.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getFieldMetadata(string $propertyName): array
6565
return (array) $this->metadata->fieldMappings[$propertyName];
6666
}
6767

68-
throw new \InvalidArgumentException(sprintf('The "%s" field does not exist in the "%s" entity.', $propertyName, $this->metadata->getName()));
68+
throw new \InvalidArgumentException(\sprintf('The "%s" field does not exist in the "%s" entity.', $propertyName, $this->metadata->getName()));
6969
}
7070

7171
/**
@@ -86,7 +86,7 @@ public function getAssociationMetadata(string $propertyName): array
8686
return $associationMapping;
8787
}
8888

89-
throw new \InvalidArgumentException(sprintf('The "%s" field does not exist in the "%s" entity.', $propertyName, $this->metadata->getName()));
89+
throw new \InvalidArgumentException(\sprintf('The "%s" field does not exist in the "%s" entity.', $propertyName, $this->metadata->getName()));
9090
}
9191

9292
public function getPropertyDataType(string $propertyName): string

src/Autocomplete/src/Doctrine/EntityMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private function getEntityMetadata(string $entityFqcn): ClassMetadata
3737
$entityMetadata = $entityManager->getClassMetadata($entityFqcn);
3838

3939
if (1 !== \count($entityMetadata->getIdentifierFieldNames())) {
40-
throw new \RuntimeException(sprintf('Autocomplete does not support Doctrine entities with composite primary keys (such as the ones used in the "%s" entity).', $entityFqcn));
40+
throw new \RuntimeException(\sprintf('Autocomplete does not support Doctrine entities with composite primary keys (such as the ones used in the "%s" entity).', $entityFqcn));
4141
}
4242

4343
return $entityMetadata;
@@ -46,7 +46,7 @@ private function getEntityMetadata(string $entityFqcn): ClassMetadata
4646
private function getEntityManager(string $entityFqcn): ObjectManager
4747
{
4848
if (null === $entityManager = $this->doctrine->getManagerForClass($entityFqcn)) {
49-
throw new \RuntimeException(sprintf('There is no Doctrine Entity Manager defined for the "%s" class', $entityFqcn));
49+
throw new \RuntimeException(\sprintf('There is no Doctrine Entity Manager defined for the "%s" class', $entityFqcn));
5050
}
5151

5252
return $entityManager;

src/Autocomplete/src/Doctrine/EntitySearchUtil.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function addSearchClause(QueryBuilder $queryBuilder, string $query, strin
5656
$numAssociatedProperties = \count($associatedProperties);
5757

5858
if (1 === $numAssociatedProperties) {
59-
throw new \InvalidArgumentException(sprintf('The "%s" property included in the setSearchFields() method is not a valid search field. When using associated properties in search, you must also define the exact field used in the search (e.g. \'%s.id\', \'%s.name\', etc.)', $propertyName, $propertyName, $propertyName));
59+
throw new \InvalidArgumentException(\sprintf('The "%s" property included in the setSearchFields() method is not a valid search field. When using associated properties in search, you must also define the exact field used in the search (e.g. \'%s.id\', \'%s.name\', etc.)', $propertyName, $propertyName, $propertyName));
6060
}
6161

6262
$originalPropertyName = $associatedProperties[0];
@@ -102,19 +102,19 @@ public function addSearchClause(QueryBuilder $queryBuilder, string $query, strin
102102
|| ($isIntegerProperty && $isIntegerQuery)
103103
|| ($isNumericProperty && $isNumericQuery)
104104
) {
105-
$expressions[] = $queryBuilder->expr()->eq(sprintf('%s.%s', $entityName, $propertyName), ':query_for_numbers');
105+
$expressions[] = $queryBuilder->expr()->eq(\sprintf('%s.%s', $entityName, $propertyName), ':query_for_numbers');
106106
$queryBuilder->setParameter('query_for_numbers', $dqlParameters['numeric_query']);
107107
} elseif ($isGuidProperty && $isUuidQuery) {
108-
$expressions[] = $queryBuilder->expr()->eq(sprintf('%s.%s', $entityName, $propertyName), ':query_for_uuids');
108+
$expressions[] = $queryBuilder->expr()->eq(\sprintf('%s.%s', $entityName, $propertyName), ':query_for_uuids');
109109
$queryBuilder->setParameter('query_for_uuids', $dqlParameters['uuid_query'], 'uuid' === $propertyDataType ? 'uuid' : null);
110110
} elseif ($isUlidProperty && $isUlidQuery) {
111-
$expressions[] = $queryBuilder->expr()->eq(sprintf('%s.%s', $entityName, $propertyName), ':query_for_uuids');
111+
$expressions[] = $queryBuilder->expr()->eq(\sprintf('%s.%s', $entityName, $propertyName), ':query_for_uuids');
112112
$queryBuilder->setParameter('query_for_uuids', $dqlParameters['uuid_query'], 'ulid');
113113
} elseif ($isTextProperty) {
114-
$expressions[] = $queryBuilder->expr()->like(sprintf('LOWER(%s.%s)', $entityName, $propertyName), ':query_for_text');
114+
$expressions[] = $queryBuilder->expr()->like(\sprintf('LOWER(%s.%s)', $entityName, $propertyName), ':query_for_text');
115115
$queryBuilder->setParameter('query_for_text', $dqlParameters['text_query']);
116116

117-
$expressions[] = $queryBuilder->expr()->in(sprintf('LOWER(%s.%s)', $entityName, $propertyName), ':query_as_words');
117+
$expressions[] = $queryBuilder->expr()->in(\sprintf('LOWER(%s.%s)', $entityName, $propertyName), ':query_as_words');
118118
$queryBuilder->setParameter('query_as_words', $dqlParameters['words_query']);
119119
}
120120
}

src/Autocomplete/src/Form/AutocompleteChoiceTypeExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private function getUrlWithExtraOptions(string $url, array $extraOptions): strin
108108
$extraOptions[self::CHECKSUM_KEY] = $this->checksumCalculator->calculateForArray($extraOptions);
109109
$extraOptions = base64_encode(json_encode($extraOptions));
110110

111-
return sprintf(
111+
return \sprintf(
112112
'%s%s%s',
113113
$url,
114114
$this->hasUrlParameters($url) ? '&' : '?',
@@ -127,7 +127,7 @@ private function validateExtraOptions(array $extraOptions): void
127127
{
128128
foreach ($extraOptions as $optionKey => $option) {
129129
if (!\is_scalar($option) && !\is_array($option) && null !== $option) {
130-
throw new \InvalidArgumentException(sprintf('Extra option with key "%s" must be a scalar value, an array or null. Got "%s".', $optionKey, get_debug_type($option)));
130+
throw new \InvalidArgumentException(\sprintf('Extra option with key "%s" must be a scalar value, an array or null. Got "%s".', $optionKey, get_debug_type($option)));
131131
}
132132

133133
if (\is_array($option)) {

src/Autocomplete/src/Form/AutocompleteEntityTypeSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @internal
2525
*
26-
* @deprecated since 2.13
26+
* @deprecated since UX 2.13
2727
*/
2828
final class AutocompleteEntityTypeSubscriber implements EventSubscriberInterface
2929
{
@@ -77,7 +77,7 @@ public function preSubmit(FormEvent $event)
7777

7878
if ($params) {
7979
$queryBuilder
80-
->andWhere(sprintf("$rootAlias.$idField IN (%s)", implode(', ', array_keys($params))))
80+
->andWhere(\sprintf("$rootAlias.$idField IN (%s)", implode(', ', array_keys($params))))
8181
;
8282
foreach ($params as $key => $param) {
8383
$queryBuilder->setParameter($key, $param[0], $param[1]);

src/Autocomplete/src/Form/BaseEntityAutocompleteType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private function getAutocompleteUrl(FormBuilderInterface $builder, array $option
9898
$attribute = AsEntityAutocompleteField::getInstance($formType::class);
9999

100100
if (!$attribute) {
101-
throw new \LogicException(sprintf('You must either provide your own autocomplete_url, or add #[AsEntityAutocompleteField] attribute to %s.', $formType::class));
101+
throw new \LogicException(\sprintf('You must either provide your own autocomplete_url, or add #[AsEntityAutocompleteField] attribute to "%s".', $formType::class));
102102
}
103103

104104
return $this->urlGenerator->generate($attribute->getRoute(), [

0 commit comments

Comments
 (0)