Skip to content

Commit 0174ad0

Browse files
committed
Prefix all sprintf() calls
1 parent d8480ea commit 0174ad0

17 files changed

+51
-51
lines changed

ArgumentResolver/EntityValueResolver.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
5757
$message = '';
5858
if (null !== $options->expr) {
5959
if (null === $object = $this->findViaExpression($manager, $request, $options)) {
60-
$message = sprintf(' The expression "%s" returned null.', $options->expr);
60+
$message = \sprintf(' The expression "%s" returned null.', $options->expr);
6161
}
6262
// find by identifier?
6363
} elseif (false === $object = $this->find($manager, $request, $options, $argument)) {
@@ -73,7 +73,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
7373
}
7474

7575
if (null === $object && !$argument->isNullable()) {
76-
throw new NotFoundHttpException($options->message ?? (sprintf('"%s" object not found by "%s".', $options->class, self::class).$message));
76+
throw new NotFoundHttpException($options->message ?? (\sprintf('"%s" object not found by "%s".', $options->class, self::class).$message));
7777
}
7878

7979
return [$object];
@@ -126,7 +126,7 @@ private function getIdentifier(Request $request, MapEntity $options, ArgumentMet
126126
foreach ($options->id as $field) {
127127
// Convert "%s_uuid" to "foobar_uuid"
128128
if (str_contains($field, '%s')) {
129-
$field = sprintf($field, $argument->getName());
129+
$field = \sprintf($field, $argument->getName());
130130
}
131131

132132
$id[$field] = $request->attributes->get($field);
@@ -214,7 +214,7 @@ private function getCriteria(Request $request, MapEntity $options, ObjectManager
214214
private function findViaExpression(ObjectManager $manager, Request $request, MapEntity $options): object|iterable|null
215215
{
216216
if (!$this->expressionLanguage) {
217-
throw new \LogicException(sprintf('You cannot use the "%s" if the ExpressionLanguage component is not available. Try running "composer require symfony/expression-language".', __CLASS__));
217+
throw new \LogicException(\sprintf('You cannot use the "%s" if the ExpressionLanguage component is not available. Try running "composer require symfony/expression-language".', __CLASS__));
218218
}
219219

220220
$repository = $manager->getRepository($options->class);

CacheWarmer/ProxyCacheWarmer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public function warmUp(string $cacheDir, ?string $buildDir = null): array
4646
// we need the directory no matter the proxy cache generation strategy
4747
if (!is_dir($proxyCacheDir = $em->getConfiguration()->getProxyDir())) {
4848
if (false === @mkdir($proxyCacheDir, 0777, true) && !is_dir($proxyCacheDir)) {
49-
throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory "%s".', $proxyCacheDir));
49+
throw new \RuntimeException(\sprintf('Unable to create the Doctrine Proxy directory "%s".', $proxyCacheDir));
5050
}
5151
} elseif (!is_writable($proxyCacheDir)) {
52-
throw new \RuntimeException(sprintf('The Doctrine Proxy directory "%s" is not writeable for the current system user.', $proxyCacheDir));
52+
throw new \RuntimeException(\sprintf('The Doctrine Proxy directory "%s" is not writeable for the current system user.', $proxyCacheDir));
5353
}
5454

5555
// if proxies are autogenerated we don't need to generate them in the cache warmer

ContainerAwareEventManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private function initializeSubscribers(): void
193193
continue;
194194
}
195195

196-
throw new \InvalidArgumentException(sprintf('Using Doctrine subscriber "%s" is not allowed. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.', \is_object($listener) ? get_debug_type($listener) : $listener));
196+
throw new \InvalidArgumentException(\sprintf('Using Doctrine subscriber "%s" is not allowed. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.', \is_object($listener) ? get_debug_type($listener) : $listener));
197197
}
198198
}
199199

DataCollector/DoctrineDataCollector.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function getCasters(): array
126126
return [Caster::PREFIX_VIRTUAL.'__toString()' => (string) $o->getObject()];
127127
}
128128

129-
return [Caster::PREFIX_VIRTUAL.'' => sprintf('Object of class "%s" could not be converted to string.', $o->getClass())];
129+
return [Caster::PREFIX_VIRTUAL.'' => \sprintf('Object of class "%s" could not be converted to string.', $o->getClass())];
130130
},
131131
];
132132
}
@@ -214,7 +214,7 @@ private function sanitizeParam(mixed $var, ?\Throwable $error): array
214214
}
215215

216216
if (\is_resource($var)) {
217-
return [sprintf('/* Resource(%s) */', get_resource_type($var)), false, false];
217+
return [\sprintf('/* Resource(%s) */', get_resource_type($var)), false, false];
218218
}
219219

220220
return [$var, true, true];

DependencyInjection/AbstractDoctrineExtension.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
8383
}
8484

8585
if (null === $bundle) {
86-
throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled.', $mappingName));
86+
throw new \InvalidArgumentException(\sprintf('Bundle "%s" does not exist or it is not enabled.', $mappingName));
8787
}
8888

8989
$mappingConfig = $this->getMappingDriverBundleConfigDefaults($mappingConfig, $bundle, $container, $bundleMetadata['path']);
@@ -123,7 +123,7 @@ protected function setMappingDriverConfig(array $mappingConfig, string $mappingN
123123
{
124124
$mappingDirectory = $mappingConfig['dir'];
125125
if (!is_dir($mappingDirectory)) {
126-
throw new \InvalidArgumentException(sprintf('Invalid Doctrine mapping path given. Cannot load Doctrine mapping/bundle named "%s".', $mappingName));
126+
throw new \InvalidArgumentException(\sprintf('Invalid Doctrine mapping path given. Cannot load Doctrine mapping/bundle named "%s".', $mappingName));
127127
}
128128

129129
$this->drivers[$mappingConfig['type']][$mappingConfig['prefix']] = realpath($mappingDirectory) ?: $mappingDirectory;
@@ -218,15 +218,15 @@ protected function registerMappingDrivers(array $objectManager, ContainerBuilder
218218
protected function assertValidMappingConfiguration(array $mappingConfig, string $objectManagerName): void
219219
{
220220
if (!$mappingConfig['type'] || !$mappingConfig['dir'] || !$mappingConfig['prefix']) {
221-
throw new \InvalidArgumentException(sprintf('Mapping definitions for Doctrine manager "%s" require at least the "type", "dir" and "prefix" options.', $objectManagerName));
221+
throw new \InvalidArgumentException(\sprintf('Mapping definitions for Doctrine manager "%s" require at least the "type", "dir" and "prefix" options.', $objectManagerName));
222222
}
223223

224224
if (!is_dir($mappingConfig['dir'])) {
225-
throw new \InvalidArgumentException(sprintf('Specified non-existing directory "%s" as Doctrine mapping source.', $mappingConfig['dir']));
225+
throw new \InvalidArgumentException(\sprintf('Specified non-existing directory "%s" as Doctrine mapping source.', $mappingConfig['dir']));
226226
}
227227

228228
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'php', 'staticphp', 'attribute'])) {
229-
throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "php", "staticphp" or "attribute" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. You can register them by adding a new driver to the "%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'_metadata_driver')));
229+
throw new \InvalidArgumentException(\sprintf('Can only configure "xml", "yml", "php", "staticphp" or "attribute" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. You can register them by adding a new driver to the "%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'_metadata_driver')));
230230
}
231231
}
232232

@@ -297,8 +297,8 @@ protected function loadCacheDriver(string $cacheName, string $objectManagerName,
297297
$memcachedInstance->addMethodCall('addServer', [
298298
$memcachedHost, $memcachedPort,
299299
]);
300-
$container->setDefinition($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName)), $memcachedInstance);
301-
$cacheDef->addMethodCall('setMemcached', [new Reference($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName)))]);
300+
$container->setDefinition($this->getObjectManagerElementName(\sprintf('%s_memcached_instance', $objectManagerName)), $memcachedInstance);
301+
$cacheDef->addMethodCall('setMemcached', [new Reference($this->getObjectManagerElementName(\sprintf('%s_memcached_instance', $objectManagerName)))]);
302302
break;
303303
case 'redis':
304304
$redisClass = !empty($cacheDriver['class']) ? $cacheDriver['class'] : '%'.$this->getObjectManagerElementName('cache.redis.class').'%';
@@ -310,19 +310,19 @@ protected function loadCacheDriver(string $cacheName, string $objectManagerName,
310310
$redisInstance->addMethodCall('connect', [
311311
$redisHost, $redisPort,
312312
]);
313-
$container->setDefinition($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName)), $redisInstance);
314-
$cacheDef->addMethodCall('setRedis', [new Reference($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName)))]);
313+
$container->setDefinition($this->getObjectManagerElementName(\sprintf('%s_redis_instance', $objectManagerName)), $redisInstance);
314+
$cacheDef->addMethodCall('setRedis', [new Reference($this->getObjectManagerElementName(\sprintf('%s_redis_instance', $objectManagerName)))]);
315315
break;
316316
case 'apc':
317317
case 'apcu':
318318
case 'array':
319319
case 'xcache':
320320
case 'wincache':
321321
case 'zenddata':
322-
$cacheDef = new Definition('%'.$this->getObjectManagerElementName(sprintf('cache.%s.class', $cacheDriver['type'])).'%');
322+
$cacheDef = new Definition('%'.$this->getObjectManagerElementName(\sprintf('cache.%s.class', $cacheDriver['type'])).'%');
323323
break;
324324
default:
325-
throw new \InvalidArgumentException(sprintf('"%s" is an unrecognized Doctrine cache driver.', $cacheDriver['type']));
325+
throw new \InvalidArgumentException(\sprintf('"%s" is an unrecognized Doctrine cache driver.', $cacheDriver['type']));
326326
}
327327

328328
if (!isset($cacheDriver['namespace'])) {
@@ -414,7 +414,7 @@ private function validateAutoMapping(array $managerConfigs): ?string
414414
}
415415

416416
if (null !== $autoMappedManager) {
417-
throw new \LogicException(sprintf('You cannot enable "auto_mapping" on more than one manager at the same time (found in "%s" and "%s"").', $autoMappedManager, $name));
417+
throw new \LogicException(\sprintf('You cannot enable "auto_mapping" on more than one manager at the same time (found in "%s" and "%s"").', $autoMappedManager, $name));
418418
}
419419

420420
$autoMappedManager = $name;

DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ private function addTaggedServices(ContainerBuilder $container): array
7575
? [$container->getParameterBag()->resolveValue($tag['connection'])]
7676
: array_keys($this->connections);
7777
if (!isset($tag['event'])) {
78-
throw new InvalidArgumentException(sprintf('Doctrine event listener "%s" must specify the "event" attribute.', $id));
78+
throw new InvalidArgumentException(\sprintf('Doctrine event listener "%s" must specify the "event" attribute.', $id));
7979
}
8080
foreach ($connections as $con) {
8181
if (!isset($this->connections[$con])) {
82-
throw new RuntimeException(sprintf('The Doctrine connection "%s" referenced in service "%s" does not exist. Available connections names: "%s".', $con, $id, implode('", "', array_keys($this->connections))));
82+
throw new RuntimeException(\sprintf('The Doctrine connection "%s" referenced in service "%s" does not exist. Available connections names: "%s".', $con, $id, implode('", "', array_keys($this->connections))));
8383
}
8484

8585
if (!isset($managerDefs[$con])) {
@@ -110,7 +110,7 @@ private function addTaggedServices(ContainerBuilder $container): array
110110
private function getEventManagerDef(ContainerBuilder $container, string $name): Definition
111111
{
112112
if (!isset($this->eventManagers[$name])) {
113-
$this->eventManagers[$name] = $container->getDefinition(sprintf($this->managerTemplate, $name));
113+
$this->eventManagers[$name] = $container->getDefinition(\sprintf($this->managerTemplate, $name));
114114
}
115115

116116
return $this->eventManagers[$name];

DependencyInjection/CompilerPass/RegisterMappingsPass.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function process(ContainerBuilder $container): void
108108
*/
109109
protected function getChainDriverServiceName(ContainerBuilder $container): string
110110
{
111-
return sprintf($this->driverPattern, $this->getManagerName($container));
111+
return \sprintf($this->driverPattern, $this->getManagerName($container));
112112
}
113113

114114
/**
@@ -130,7 +130,7 @@ protected function getDriver(ContainerBuilder $container): Definition|Reference
130130
*/
131131
private function getConfigurationServiceName(ContainerBuilder $container): string
132132
{
133-
return sprintf($this->configurationPattern, $this->getManagerName($container));
133+
return \sprintf($this->configurationPattern, $this->getManagerName($container));
134134
}
135135

136136
/**
@@ -152,7 +152,7 @@ private function getManagerName(ContainerBuilder $container): string
152152
}
153153
}
154154

155-
throw new InvalidArgumentException(sprintf('Could not find the manager name parameter in the container. Tried the following parameter names: "%s".', implode('", "', $this->managerParameters)));
155+
throw new InvalidArgumentException(\sprintf('Could not find the manager name parameter in the container. Tried the following parameter names: "%s".', implode('", "', $this->managerParameters)));
156156
}
157157

158158
/**

Form/ChoiceList/DoctrineChoiceLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
private readonly ?EntityLoaderInterface $objectLoader = null,
4242
) {
4343
if ($idReader && !$idReader->isSingleId()) {
44-
throw new \InvalidArgumentException(sprintf('The "$idReader" argument of "%s" must be null when the query cannot be optimized because of composite id fields.', __METHOD__));
44+
throw new \InvalidArgumentException(\sprintf('The "$idReader" argument of "%s" must be null when the query cannot be optimized because of composite id fields.', __METHOD__));
4545
}
4646

4747
$this->class = $manager->getClassMetadata($class)->getName();

Form/ChoiceList/IdReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getIdValue(?object $object = null): string
8383
}
8484

8585
if (!$this->om->contains($object)) {
86-
throw new RuntimeException(sprintf('Entity of type "%s" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?', get_debug_type($object)));
86+
throw new RuntimeException(\sprintf('Entity of type "%s" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?', get_debug_type($object)));
8787
}
8888

8989
$this->om->initializeObject($object);

Form/ChoiceList/ORMQueryBuilderLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getEntitiesByIds(string $identifier, array $values): array
8181
try {
8282
$value = $doctrineType->convertToDatabaseValue($value, $platform);
8383
} catch (ConversionException $e) {
84-
throw new TransformationFailedException(sprintf('Failed to transform "%s" into "%s".', $value, $type), 0, $e);
84+
throw new TransformationFailedException(\sprintf('Failed to transform "%s" into "%s".', $value, $type), 0, $e);
8585
}
8686
}
8787
unset($value);

Form/Type/DoctrineType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function configureOptions(OptionsResolver $resolver): void
170170
$em = $this->registry->getManagerForClass($options['class']);
171171

172172
if (null === $em) {
173-
throw new RuntimeException(sprintf('Class "%s" seems not to be a managed Doctrine entity. Did you forget to map it?', $options['class']));
173+
throw new RuntimeException(\sprintf('Class "%s" seems not to be a managed Doctrine entity. Did you forget to map it?', $options['class']));
174174
}
175175

176176
return $em;

Form/Type/EntityType.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function configureOptions(OptionsResolver $resolver): void
5151
public function getLoader(ObjectManager $manager, object $queryBuilder, string $class): ORMQueryBuilderLoader
5252
{
5353
if (!$queryBuilder instanceof QueryBuilder) {
54-
throw new \TypeError(sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, get_debug_type($queryBuilder)));
54+
throw new \TypeError(\sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, get_debug_type($queryBuilder)));
5555
}
5656

5757
return new ORMQueryBuilderLoader($queryBuilder);
@@ -74,7 +74,7 @@ public function getBlockPrefix(): string
7474
public function getQueryBuilderPartsForCachingHash(object $queryBuilder): ?array
7575
{
7676
if (!$queryBuilder instanceof QueryBuilder) {
77-
throw new \TypeError(sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, get_debug_type($queryBuilder)));
77+
throw new \TypeError(\sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, get_debug_type($queryBuilder)));
7878
}
7979

8080
return [

ManagerRegistry.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ protected function resetService($name): void
4040

4141
if ($manager instanceof LazyObjectInterface) {
4242
if (!$manager->resetLazyObject()) {
43-
throw new \LogicException(sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
43+
throw new \LogicException(\sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
4444
}
4545

4646
return;
4747
}
4848
if (!$manager instanceof LazyLoadingInterface) {
49-
throw new \LogicException(sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
49+
throw new \LogicException(\sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
5050
}
5151
if ($manager instanceof GhostObjectInterface) {
5252
throw new \LogicException('Resetting a lazy-ghost-object manager service is not supported.');

SchemaListener/AbstractSchemaListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function getIsSameDatabaseChecker(Connection $connection): \Closure
3636
$schemaManager->createTable($table);
3737

3838
try {
39-
$exec(sprintf('DROP TABLE %s', $checkTable));
39+
$exec(\sprintf('DROP TABLE %s', $checkTable));
4040
} catch (\Exception) {
4141
// ignore
4242
}

0 commit comments

Comments
 (0)