Skip to content

Commit d63c92c

Browse files
committed
Prefix all sprintf() calls
1 parent 69c1f1b commit d63c92c

15 files changed

+38
-38
lines changed

Lock.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function acquire(bool $blocking = false): bool
9898
} catch (\Exception) {
9999
// swallow exception to not hide the original issue
100100
}
101-
throw new LockExpiredException(sprintf('Failed to store the "%s" lock.', $this->key));
101+
throw new LockExpiredException(\sprintf('Failed to store the "%s" lock.', $this->key));
102102
}
103103

104104
return true;
@@ -113,7 +113,7 @@ public function acquire(bool $blocking = false): bool
113113
return false;
114114
} catch (\Exception $e) {
115115
$this->logger?->notice('Failed to acquire the "{resource}" lock.', ['resource' => $this->key, 'exception' => $e]);
116-
throw new LockAcquiringException(sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
116+
throw new LockAcquiringException(\sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
117117
}
118118
}
119119

@@ -156,7 +156,7 @@ public function acquireRead(bool $blocking = false): bool
156156
} catch (\Exception) {
157157
// swallow exception to not hide the original issue
158158
}
159-
throw new LockExpiredException(sprintf('Failed to store the "%s" lock.', $this->key));
159+
throw new LockExpiredException(\sprintf('Failed to store the "%s" lock.', $this->key));
160160
}
161161

162162
return true;
@@ -171,7 +171,7 @@ public function acquireRead(bool $blocking = false): bool
171171
return false;
172172
} catch (\Exception $e) {
173173
$this->logger?->notice('Failed to acquire the "{resource}" lock.', ['resource' => $this->key, 'exception' => $e]);
174-
throw new LockAcquiringException(sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
174+
throw new LockAcquiringException(\sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
175175
}
176176
}
177177

@@ -192,7 +192,7 @@ public function refresh(?float $ttl = null): void
192192
} catch (\Exception) {
193193
// swallow exception to not hide the original issue
194194
}
195-
throw new LockExpiredException(sprintf('Failed to put off the expiration of the "%s" lock within the specified time.', $this->key));
195+
throw new LockExpiredException(\sprintf('Failed to put off the expiration of the "%s" lock within the specified time.', $this->key));
196196
}
197197

198198
$this->logger?->debug('Expiration defined for "{resource}" lock for "{ttl}" seconds.', ['resource' => $this->key, 'ttl' => $ttl]);
@@ -202,7 +202,7 @@ public function refresh(?float $ttl = null): void
202202
throw $e;
203203
} catch (\Exception $e) {
204204
$this->logger?->notice('Failed to define an expiration for the "{resource}" lock.', ['resource' => $this->key, 'exception' => $e]);
205-
throw new LockAcquiringException(sprintf('Failed to define an expiration for the "%s" lock.', $this->key), 0, $e);
205+
throw new LockAcquiringException(\sprintf('Failed to define an expiration for the "%s" lock.', $this->key), 0, $e);
206206
}
207207
}
208208

@@ -220,11 +220,11 @@ public function release(): void
220220
} catch (LockReleasingException $e) {
221221
throw $e;
222222
} catch (\Exception $e) {
223-
throw new LockReleasingException(sprintf('Failed to release the "%s" lock.', $this->key), 0, $e);
223+
throw new LockReleasingException(\sprintf('Failed to release the "%s" lock.', $this->key), 0, $e);
224224
}
225225

226226
if ($this->store->exists($this->key)) {
227-
throw new LockReleasingException(sprintf('Failed to release the "%s" lock, the resource is still locked.', $this->key));
227+
throw new LockReleasingException(\sprintf('Failed to release the "%s" lock, the resource is still locked.', $this->key));
228228
}
229229

230230
$this->logger?->debug('Successfully released the "{resource}" lock.', ['resource' => $this->key]);

Store/CombinedStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
) {
4242
foreach ($stores as $store) {
4343
if (!$store instanceof PersistingStoreInterface) {
44-
throw new InvalidArgumentException(sprintf('The store must implement "%s". Got "%s".', PersistingStoreInterface::class, get_debug_type($store)));
44+
throw new InvalidArgumentException(\sprintf('The store must implement "%s". Got "%s".', PersistingStoreInterface::class, get_debug_type($store)));
4545
}
4646
}
4747
}

Store/DatabaseTableTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ trait DatabaseTableTrait
3030
private function init(array $options, float $gcProbability, int $initialTtl): void
3131
{
3232
if ($gcProbability < 0 || $gcProbability > 1) {
33-
throw new InvalidArgumentException(sprintf('"%s" requires gcProbability between 0 and 1, "%f" given.', __METHOD__, $gcProbability));
33+
throw new InvalidArgumentException(\sprintf('"%s" requires gcProbability between 0 and 1, "%f" given.', __METHOD__, $gcProbability));
3434
}
3535
if ($initialTtl < 1) {
36-
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL, "%d" given.', __METHOD__, $initialTtl));
36+
throw new InvalidTtlException(\sprintf('"%s()" expects a strictly positive TTL, "%d" given.', __METHOD__, $initialTtl));
3737
}
3838

3939
$this->table = $options['db_table'] ?? $this->table;

Store/DoctrineDbalPostgreSqlStore.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(#[\SensitiveParameter] Connection|string $connOrUrl)
4545
{
4646
if ($connOrUrl instanceof Connection) {
4747
if (!$connOrUrl->getDatabasePlatform() instanceof PostgreSQLPlatform) {
48-
throw new InvalidArgumentException(sprintf('The adapter "%s" does not support the "%s" platform.', __CLASS__, $connOrUrl->getDatabasePlatform()::class));
48+
throw new InvalidArgumentException(\sprintf('The adapter "%s" does not support the "%s" platform.', __CLASS__, $connOrUrl->getDatabasePlatform()::class));
4949
}
5050
$this->conn = $connOrUrl;
5151
} else {
@@ -270,10 +270,10 @@ private function filterDsn(#[\SensitiveParameter] string $dsn): string
270270
[$scheme, $rest] = explode(':', $dsn, 2);
271271
$driver = strtok($scheme, '+');
272272
if (!\in_array($driver, ['pgsql', 'postgres', 'postgresql'])) {
273-
throw new InvalidArgumentException(sprintf('The adapter "%s" does not support the "%s" driver.', __CLASS__, $driver));
273+
throw new InvalidArgumentException(\sprintf('The adapter "%s" does not support the "%s" driver.', __CLASS__, $driver));
274274
}
275275

276-
return sprintf('%s:%s', $driver, $rest);
276+
return \sprintf('%s:%s', $driver, $rest);
277277
}
278278

279279
private function getInternalStore(): SharedLockStoreInterface

Store/DoctrineDbalStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function save(Key $key): void
132132
public function putOffExpiration(Key $key, $ttl): void
133133
{
134134
if ($ttl < 1) {
135-
throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
135+
throw new InvalidTtlException(\sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
136136
}
137137

138138
$key->reduceLifetime($ttl);

Store/ExpiringStoreTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private function checkNotExpired(Key $key): void
2424
} catch (\Exception) {
2525
// swallow exception to not hide the original issue
2626
}
27-
throw new LockExpiredException(sprintf('Failed to store the "%s" lock.', $key));
27+
throw new LockExpiredException(\sprintf('Failed to store the "%s" lock.', $key));
2828
}
2929
}
3030
}

Store/FlockStore.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public function __construct(?string $lockPath = null)
4141
{
4242
if (!is_dir($lockPath ??= sys_get_temp_dir())) {
4343
if (false === @mkdir($lockPath, 0777, true) && !is_dir($lockPath)) {
44-
throw new InvalidArgumentException(sprintf('The FlockStore directory "%s" does not exists and cannot be created.', $lockPath));
44+
throw new InvalidArgumentException(\sprintf('The FlockStore directory "%s" does not exists and cannot be created.', $lockPath));
4545
}
4646
} elseif (!is_writable($lockPath)) {
47-
throw new InvalidArgumentException(sprintf('The FlockStore directory "%s" is not writable.', $lockPath));
47+
throw new InvalidArgumentException(\sprintf('The FlockStore directory "%s" is not writable.', $lockPath));
4848
}
4949

5050
$this->lockPath = $lockPath;
@@ -83,7 +83,7 @@ private function lock(Key $key, bool $read, bool $blocking): void
8383
}
8484

8585
if (!$handle) {
86-
$fileName = sprintf('%s/sf.%s.%s.lock',
86+
$fileName = \sprintf('%s/sf.%s.%s.lock',
8787
$this->lockPath,
8888
substr(preg_replace('/[^a-z0-9\._-]+/i', '-', $key), 0, 50),
8989
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')

Store/MemcachedStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(
4545
}
4646

4747
if ($initialTtl < 1) {
48-
throw new InvalidArgumentException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
48+
throw new InvalidArgumentException(\sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
4949
}
5050
}
5151

@@ -64,7 +64,7 @@ public function save(Key $key): void
6464
public function putOffExpiration(Key $key, float $ttl): void
6565
{
6666
if ($ttl < 1) {
67-
throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));
67+
throw new InvalidTtlException(\sprintf('"%s()" expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));
6868
}
6969

7070
// Interface defines a float value but Store required an integer.

Store/MongoDbStore.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ public function __construct(
121121
}
122122

123123
if (null === $this->options['database']) {
124-
throw new InvalidArgumentException(sprintf('"%s()" requires the "database" in the URI path or option.', __METHOD__));
124+
throw new InvalidArgumentException(\sprintf('"%s()" requires the "database" in the URI path or option.', __METHOD__));
125125
}
126126
if (null === $this->options['collection']) {
127-
throw new InvalidArgumentException(sprintf('"%s()" requires the "collection" in the URI querystring or option.', __METHOD__));
127+
throw new InvalidArgumentException(\sprintf('"%s()" requires the "collection" in the URI querystring or option.', __METHOD__));
128128
}
129129
$this->namespace = $this->options['database'].'.'.$this->options['collection'];
130130

131131
if ($this->options['gcProbability'] < 0.0 || $this->options['gcProbability'] > 1.0) {
132-
throw new InvalidArgumentException(sprintf('"%s()" gcProbability must be a float from 0.0 to 1.0, "%f" given.', __METHOD__, $this->options['gcProbability']));
132+
throw new InvalidArgumentException(\sprintf('"%s()" gcProbability must be a float from 0.0 to 1.0, "%f" given.', __METHOD__, $this->options['gcProbability']));
133133
}
134134

135135
if ($this->initialTtl <= 0) {
136-
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL, got "%d".', __METHOD__, $this->initialTtl));
136+
throw new InvalidTtlException(\sprintf('"%s()" expects a strictly positive TTL, got "%d".', __METHOD__, $this->initialTtl));
137137
}
138138
}
139139

@@ -147,11 +147,11 @@ public function __construct(
147147
private function skimUri(string $uri): string
148148
{
149149
if (!str_starts_with($uri, 'mongodb://') && !str_starts_with($uri, 'mongodb+srv://')) {
150-
throw new InvalidArgumentException(sprintf('The given MongoDB Connection URI "%s" is invalid. Expecting "mongodb://" or "mongodb+srv://".', $uri));
150+
throw new InvalidArgumentException(\sprintf('The given MongoDB Connection URI "%s" is invalid. Expecting "mongodb://" or "mongodb+srv://".', $uri));
151151
}
152152

153153
if (false === $params = parse_url($uri)) {
154-
throw new InvalidArgumentException(sprintf('The given MongoDB Connection URI "%s" is invalid.', $uri));
154+
throw new InvalidArgumentException(\sprintf('The given MongoDB Connection URI "%s" is invalid.', $uri));
155155
}
156156
$pathDb = ltrim($params['path'] ?? '', '/') ?: null;
157157
if (null !== $pathDb) {

Store/PdoStore.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function __construct(#[\SensitiveParameter] \PDO|string $connOrDsn, #[\Se
7070

7171
if ($connOrDsn instanceof \PDO) {
7272
if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
73-
throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __METHOD__));
73+
throw new InvalidArgumentException(\sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __METHOD__));
7474
}
7575

7676
$this->conn = $connOrDsn;
@@ -125,7 +125,7 @@ public function save(Key $key): void
125125
public function putOffExpiration(Key $key, float $ttl): void
126126
{
127127
if ($ttl < 1) {
128-
throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
128+
throw new InvalidTtlException(\sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
129129
}
130130

131131
$key->reduceLifetime($ttl);
@@ -193,7 +193,7 @@ public function createTable(): void
193193
'pgsql' => "CREATE TABLE $this->table ($this->idCol VARCHAR(64) NOT NULL PRIMARY KEY, $this->tokenCol VARCHAR(64) NOT NULL, $this->expirationCol INTEGER)",
194194
'oci' => "CREATE TABLE $this->table ($this->idCol VARCHAR2(64) NOT NULL PRIMARY KEY, $this->tokenCol VARCHAR2(64) NOT NULL, $this->expirationCol INTEGER)",
195195
'sqlsrv' => "CREATE TABLE $this->table ($this->idCol VARCHAR(64) NOT NULL PRIMARY KEY, $this->tokenCol VARCHAR(64) NOT NULL, $this->expirationCol INTEGER)",
196-
default => throw new \DomainException(sprintf('Creating the lock table is currently not implemented for platform "%s".', $driver)),
196+
default => throw new \DomainException(\sprintf('Creating the lock table is currently not implemented for platform "%s".', $driver)),
197197
};
198198

199199
$this->getConnection()->exec($sql);

Store/PostgreSqlStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(#[\SensitiveParameter] \PDO|string $connOrDsn, #[\Se
5353
{
5454
if ($connOrDsn instanceof \PDO) {
5555
if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
56-
throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __METHOD__));
56+
throw new InvalidArgumentException(\sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __METHOD__));
5757
}
5858

5959
$this->conn = $connOrDsn;
@@ -277,7 +277,7 @@ private function getConnection(): \PDO
277277
private function checkDriver(): void
278278
{
279279
if ('pgsql' !== $driver = $this->conn->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
280-
throw new InvalidArgumentException(sprintf('The adapter "%s" does not support the "%s" driver.', __CLASS__, $driver));
280+
throw new InvalidArgumentException(\sprintf('The adapter "%s" does not support the "%s" driver.', __CLASS__, $driver));
281281
}
282282
}
283283

Store/RedisStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(
4040
private float $initialTtl = 300.0,
4141
) {
4242
if ($initialTtl <= 0) {
43-
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
43+
throw new InvalidTtlException(\sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
4444
}
4545
}
4646

Store/StoreFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function createStore(#[\SensitiveParameter] object|string $connect
5050
return new ZookeeperStore($connection);
5151

5252
case !\is_string($connection):
53-
throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', get_debug_type($connection)));
53+
throw new InvalidArgumentException(\sprintf('Unsupported Connection: "%s".', get_debug_type($connection)));
5454
case 'flock' === $connection:
5555
return new FlockStore();
5656

@@ -108,6 +108,6 @@ public static function createStore(#[\SensitiveParameter] object|string $connect
108108
return new InMemoryStore();
109109
}
110110

111-
throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection));
111+
throw new InvalidArgumentException(\sprintf('Unsupported Connection: "%s".', $connection));
112112
}
113113
}

Tests/Store/AbstractRedisStoreTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private function evaluate(string $script, string $resource, array $args)
9898
return $this->redis->eval(...array_merge([$script, 1, $resource], $args));
9999
}
100100

101-
throw new InvalidArgumentException(sprintf('"%s()" expects being initialized with a Redis, Relay, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($this->redis)));
101+
throw new InvalidArgumentException(\sprintf('"%s()" expects being initialized with a Redis, Relay, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($this->redis)));
102102
}
103103

104104
private function getUniqueToken(Key $key): string

Tests/Store/FlockStoreTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testSaveSanitizeName()
6666

6767
$key = new Key('<?php echo "% hello word ! %" ?>');
6868

69-
$file = sprintf(
69+
$file = \sprintf(
7070
'%s/sf.-php-echo-hello-word-.%s.lock',
7171
sys_get_temp_dir(),
7272
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
@@ -87,7 +87,7 @@ public function testSaveSanitizeLongName()
8787

8888
$key = new Key(str_repeat(__CLASS__, 100));
8989

90-
$file = sprintf(
90+
$file = \sprintf(
9191
'%s/sf.Symfony-Component-Lock-Tests-Store-FlockStoreTestS.%s.lock',
9292
sys_get_temp_dir(),
9393
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')

0 commit comments

Comments
 (0)