Skip to content

Commit 83d1c9f

Browse files
committed
Prefix all sprintf() calls
1 parent 5c29591 commit 83d1c9f

9 files changed

+23
-23
lines changed

AbstractUid.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ abstract public function toBinary(): string;
9393
*/
9494
public function toBase58(): string
9595
{
96-
return strtr(sprintf('%022s', BinaryUtil::toBase($this->toBinary(), BinaryUtil::BASE58)), '0', '1');
96+
return strtr(\sprintf('%022s', BinaryUtil::toBase($this->toBinary(), BinaryUtil::BASE58)), '0', '1');
9797
}
9898

9999
/**
@@ -106,7 +106,7 @@ public function toBase58(): string
106106
public function toBase32(): string
107107
{
108108
$uid = bin2hex($this->toBinary());
109-
$uid = sprintf('%02s%04s%04s%04s%04s%04s%04s',
109+
$uid = \sprintf('%02s%04s%04s%04s%04s%04s%04s',
110110
base_convert(substr($uid, 0, 2), 16, 32),
111111
base_convert(substr($uid, 2, 5), 16, 32),
112112
base_convert(substr($uid, 7, 5), 16, 32),

Command/GenerateUlidCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function configure(): void
3737
->setDefinition([
3838
new InputOption('time', null, InputOption::VALUE_REQUIRED, 'The ULID timestamp: a parsable date/time string'),
3939
new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of ULID to generate', 1),
40-
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, sprintf('The ULID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'base32'),
40+
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, \sprintf('The ULID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'base32'),
4141
])
4242
->setHelp(<<<'EOF'
4343
The <info>%command.name%</info> command generates a ULID.
@@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6868
try {
6969
$time = new \DateTimeImmutable($time);
7070
} catch (\Exception $e) {
71-
$io->error(sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage())));
71+
$io->error(\sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage())));
7272

7373
return 1;
7474
}
@@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7979
if (\in_array($formatOption, $this->getAvailableFormatOptions(), true)) {
8080
$format = 'to'.ucfirst($formatOption);
8181
} else {
82-
$io->error(sprintf('Invalid format "%s", supported formats are "%s".', $formatOption, implode('", "', $this->getAvailableFormatOptions())));
82+
$io->error(\sprintf('Invalid format "%s", supported formats are "%s".', $formatOption, implode('", "', $this->getAvailableFormatOptions())));
8383

8484
return 1;
8585
}

Command/GenerateUuidCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function configure(): void
4242
new InputOption('namespace', null, InputOption::VALUE_REQUIRED, 'The UUID to use at the namespace for named-based UUIDs, predefined namespaces keywords "dns", "url", "oid" and "x500" are accepted'),
4343
new InputOption('random-based', null, InputOption::VALUE_NONE, 'To generate a random-based UUID'),
4444
new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of UUID to generate', 1),
45-
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, sprintf('The UUID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'rfc4122'),
45+
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, \sprintf('The UUID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'rfc4122'),
4646
])
4747
->setHelp(<<<'EOF'
4848
The <info>%command.name%</info> generates a UUID.
@@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
115115
try {
116116
$node = Uuid::fromString($node);
117117
} catch (\InvalidArgumentException $e) {
118-
$io->error(sprintf('Invalid node "%s": %s', $node, $e->getMessage()));
118+
$io->error(\sprintf('Invalid node "%s": %s', $node, $e->getMessage()));
119119

120120
return 1;
121121
}
@@ -124,7 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
124124
try {
125125
new \DateTimeImmutable($time);
126126
} catch (\Exception $e) {
127-
$io->error(sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage())));
127+
$io->error(\sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage())));
128128

129129
return 1;
130130
}
@@ -137,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
137137
try {
138138
$namespace = Uuid::fromString($namespace);
139139
} catch (\InvalidArgumentException $e) {
140-
$io->error(sprintf('Invalid namespace "%s": %s', $namespace, $e->getMessage()));
140+
$io->error(\sprintf('Invalid namespace "%s": %s', $namespace, $e->getMessage()));
141141

142142
return 1;
143143
}
@@ -168,7 +168,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
168168
if (\in_array($formatOption, $this->getAvailableFormatOptions(), true)) {
169169
$format = 'to'.ucfirst($formatOption);
170170
} else {
171-
$io->error(sprintf('Invalid format "%s", supported formats are "%s".', $formatOption, implode('", "', $this->getAvailableFormatOptions())));
171+
$io->error(\sprintf('Invalid format "%s", supported formats are "%s".', $formatOption, implode('", "', $this->getAvailableFormatOptions())));
172172

173173
return 1;
174174
}

Factory/UuidFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function nameBased(Uuid|string|null $namespace = null): NameBasedUuidFact
7272
$namespace ??= $this->nameBasedNamespace;
7373

7474
if (null === $namespace) {
75-
throw new \LogicException(sprintf('A namespace should be defined when using "%s()".', __METHOD__));
75+
throw new \LogicException(\sprintf('A namespace should be defined when using "%s()".', __METHOD__));
7676
}
7777

7878
return new NameBasedUuidFactory($this->nameBasedClass, $this->getNamespace($namespace));

Ulid.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(?string $ulid = null)
3636
$this->uid = $ulid;
3737
} else {
3838
if (!self::isValid($ulid)) {
39-
throw new \InvalidArgumentException(sprintf('Invalid ULID: "%s".', $ulid));
39+
throw new \InvalidArgumentException(\sprintf('Invalid ULID: "%s".', $ulid));
4040
}
4141

4242
$this->uid = strtoupper($ulid);
@@ -73,7 +73,7 @@ public static function fromString(string $ulid): static
7373
}
7474

7575
$ulid = bin2hex($ulid);
76-
$ulid = sprintf('%02s%04s%04s%04s%04s%04s%04s',
76+
$ulid = \sprintf('%02s%04s%04s%04s%04s%04s%04s',
7777
base_convert(substr($ulid, 0, 2), 16, 32),
7878
base_convert(substr($ulid, 2, 5), 16, 32),
7979
base_convert(substr($ulid, 7, 5), 16, 32),
@@ -101,7 +101,7 @@ public function toBinary(): string
101101
{
102102
$ulid = strtr($this->uid, 'ABCDEFGHJKMNPQRSTVWXYZ', 'abcdefghijklmnopqrstuv');
103103

104-
$ulid = sprintf('%02s%05s%05s%05s%05s%05s%05s',
104+
$ulid = \sprintf('%02s%05s%05s%05s%05s%05s%05s',
105105
base_convert(substr($ulid, 0, 2), 32, 16),
106106
base_convert(substr($ulid, 2, 4), 32, 16),
107107
base_convert(substr($ulid, 6, 4), 32, 16),
@@ -133,7 +133,7 @@ public function getDateTime(): \DateTimeImmutable
133133
if (\PHP_INT_SIZE >= 8) {
134134
$time = (string) hexdec(base_convert($time, 32, 16));
135135
} else {
136-
$time = sprintf('%02s%05s%05s',
136+
$time = \sprintf('%02s%05s%05s',
137137
base_convert(substr($time, 0, 2), 32, 16),
138138
base_convert(substr($time, 2, 4), 32, 16),
139139
base_convert(substr($time, 6, 4), 32, 16)
@@ -190,14 +190,14 @@ public static function generate(?\DateTimeInterface $time = null): string
190190
$time = base_convert($time, 10, 32);
191191
} else {
192192
$time = str_pad(bin2hex(BinaryUtil::fromBase($time, BinaryUtil::BASE10)), 12, '0', \STR_PAD_LEFT);
193-
$time = sprintf('%s%04s%04s',
193+
$time = \sprintf('%s%04s%04s',
194194
base_convert(substr($time, 0, 2), 16, 32),
195195
base_convert(substr($time, 2, 5), 16, 32),
196196
base_convert(substr($time, 7, 5), 16, 32)
197197
);
198198
}
199199

200-
return strtr(sprintf('%010s%04s%04s%04s%04s',
200+
return strtr(\sprintf('%010s%04s%04s%04s%04s',
201201
$time,
202202
base_convert(self::$rand[1], 10, 32),
203203
base_convert(self::$rand[2], 10, 32),

Uuid.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public function __construct(string $uuid, bool $checkVariant = false)
3232
$type = preg_match('{^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$}Di', $uuid) ? (int) $uuid[14] : false;
3333

3434
if (false === $type || (static::TYPE ?: $type) !== $type) {
35-
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid));
35+
throw new \InvalidArgumentException(\sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid));
3636
}
3737

3838
$this->uid = strtolower($uuid);
3939

4040
if ($checkVariant && !\in_array($this->uid[19], ['8', '9', 'a', 'b'], true)) {
41-
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid));
41+
throw new \InvalidArgumentException(\sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid));
4242
}
4343
}
4444

UuidV1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function generate(?\DateTimeInterface $time = null, ?Uuid $node =
6666
$seq = substr($uuid, 19, 4);
6767

6868
do {
69-
self::$clockSeq = sprintf('%04x', random_int(0, 0x3FFF) | 0x8000);
69+
self::$clockSeq = \sprintf('%04x', random_int(0, 0x3FFF) | 0x8000);
7070
} while ($seq === self::$clockSeq);
7171

7272
$seq = self::$clockSeq;

UuidV6.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function toV7(): UuidV7
5959
$time = substr($time, 1);
6060
}
6161

62-
return new UuidV7(substr_replace(sprintf(
62+
return new UuidV7(substr_replace(\sprintf(
6363
'%012s-7%s-%s%s-%s%06s',
6464
\PHP_INT_SIZE >= 8 ? dechex($ms) : bin2hex(BinaryUtil::fromBase($ms, BinaryUtil::BASE10)),
6565
substr($uuid, -6, 3),
@@ -85,7 +85,7 @@ public static function generate(?\DateTimeInterface $time = null, ?Uuid $node =
8585
if (!isset(self::$node)) {
8686
$seed = [random_int(0, 0xFFFFFF), random_int(0, 0xFFFFFF)];
8787
$node = unpack('N2', hex2bin('00'.substr($uuidV1, 24, 6)).hex2bin('00'.substr($uuidV1, 30)));
88-
self::$node = sprintf('%06x%06x', ($seed[0] ^ $node[1]) | 0x010000, $seed[1] ^ $node[2]);
88+
self::$node = \sprintf('%06x%06x', ($seed[0] ^ $node[1]) | 0x010000, $seed[1] ^ $node[2]);
8989
}
9090

9191
return $uuid.self::$node;

UuidV7.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static function generate(?\DateTimeInterface $time = null): string
113113
$time = bin2hex(BinaryUtil::fromBase($time, BinaryUtil::BASE10));
114114
}
115115

116-
return substr_replace(sprintf('%012s-%04x-%04x-%04x%04x%04x',
116+
return substr_replace(\sprintf('%012s-%04x-%04x-%04x%04x%04x',
117117
$time,
118118
0x7000 | (self::$rand[1] << 2) | (self::$rand[2] >> 14),
119119
0x8000 | (self::$rand[2] & 0x3FFF),

0 commit comments

Comments
 (0)