Skip to content

Commit ada3dfc

Browse files
committed
Prefix all sprintf() calls
1 parent db82c2b commit ada3dfc

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

Exception/ClassNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ class ClassNotFoundException extends \Exception implements ExceptionInterface
1515
{
1616
public function __construct(string $class, ?\Throwable $previous = null)
1717
{
18-
parent::__construct(sprintf('Class "%s" not found.', $class), 0, $previous);
18+
parent::__construct(\sprintf('Class "%s" not found.', $class), 0, $previous);
1919
}
2020
}

Exception/NotInstantiableTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ class NotInstantiableTypeException extends \Exception implements ExceptionInterf
1515
{
1616
public function __construct(string $type, ?\Throwable $previous = null)
1717
{
18-
parent::__construct(sprintf('Type "%s" is not instantiable.', $type), 0, $previous);
18+
parent::__construct(\sprintf('Type "%s" is not instantiable.', $type), 0, $previous);
1919
}
2020
}

Internal/Exporter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
7979

8080
if ($reflector->hasMethod('__serialize')) {
8181
if (!$reflector->getMethod('__serialize')->isPublic()) {
82-
throw new \Error(sprintf('Call to %s method "%s::__serialize()".', $reflector->getMethod('__serialize')->isProtected() ? 'protected' : 'private', $class));
82+
throw new \Error(\sprintf('Call to %s method "%s::__serialize()".', $reflector->getMethod('__serialize')->isProtected() ? 'protected' : 'private', $class));
8383
}
8484

8585
if (!\is_array($serializeProperties = $value->__serialize())) {
@@ -170,7 +170,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
170170
}
171171
if ($sleep) {
172172
foreach ($sleep as $n => $v) {
173-
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), \E_USER_NOTICE);
173+
trigger_error(\sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), \E_USER_NOTICE);
174174
}
175175
}
176176
if (method_exists($class, '__unserialize')) {
@@ -223,10 +223,10 @@ public static function export($value, $indent = '')
223223
$subIndent = $indent.' ';
224224

225225
if (\is_string($value)) {
226-
$code = sprintf("'%s'", addcslashes($value, "'\\"));
226+
$code = \sprintf("'%s'", addcslashes($value, "'\\"));
227227

228228
$code = preg_replace_callback("/((?:[\\0\\r\\n]|\u{202A}|\u{202B}|\u{202D}|\u{202E}|\u{2066}|\u{2067}|\u{2068}|\u{202C}|\u{2069})++)(.)/", function ($m) use ($subIndent) {
229-
$m[1] = sprintf('\'."%s".\'', str_replace(
229+
$m[1] = \sprintf('\'."%s".\'', str_replace(
230230
["\0", "\r", "\n", "\u{202A}", "\u{202B}", "\u{202D}", "\u{202E}", "\u{2066}", "\u{2067}", "\u{2068}", "\u{202C}", "\u{2069}", '\n\\'],
231231
['\0', '\r', '\n', '\u{202A}', '\u{202B}', '\u{202D}', '\u{202E}', '\u{2066}', '\u{2067}', '\u{2068}', '\u{202C}', '\u{2069}', '\n"'."\n".$subIndent.'."\\'],
232232
$m[1]
@@ -284,7 +284,7 @@ public static function export($value, $indent = '')
284284
return self::exportHydrator($value, $indent, $subIndent);
285285
}
286286

287-
throw new \UnexpectedValueException(sprintf('Cannot export value of type "%s".', get_debug_type($value)));
287+
throw new \UnexpectedValueException(\sprintf('Cannot export value of type "%s".', get_debug_type($value)));
288288
}
289289

290290
private static function exportRegistry(Registry $value, string $indent, string $subIndent): string

LazyGhostTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function &__get($name): mixed
143143

144144
if (null === $class) {
145145
$frame = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
146-
trigger_error(sprintf('Undefined property: %s::$%s in %s on line %s', $this::class, $name, $frame['file'], $frame['line']), \E_USER_NOTICE);
146+
trigger_error(\sprintf('Undefined property: %s::$%s in %s on line %s', $this::class, $name, $frame['file'], $frame['line']), \E_USER_NOTICE);
147147
}
148148

149149
get_in_scope:
@@ -320,7 +320,7 @@ public function __serialize(): array
320320
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0$class\0$name"] ?? $properties[$k = "\0$scope\0$name"] ?? $k = null;
321321

322322
if (null === $k) {
323-
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $name), \E_USER_NOTICE);
323+
trigger_error(\sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $name), \E_USER_NOTICE);
324324
} else {
325325
$data[$k] = $value;
326326
}

LazyProxyTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function &__get($name): mixed
125125

126126
if (!$parent && null === $class && !\array_key_exists($name, (array) $instance)) {
127127
$frame = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
128-
trigger_error(sprintf('Undefined property: %s::$%s in %s on line %s', $instance::class, $name, $frame['file'], $frame['line']), \E_USER_NOTICE);
128+
trigger_error(\sprintf('Undefined property: %s::$%s in %s on line %s', $instance::class, $name, $frame['file'], $frame['line']), \E_USER_NOTICE);
129129
}
130130

131131
get_in_scope:
@@ -310,7 +310,7 @@ public function __serialize(): array
310310
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0$class\0$name"] ?? $properties[$k = "\0$scope\0$name"] ?? $k = null;
311311

312312
if (null === $k) {
313-
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $name), \E_USER_NOTICE);
313+
trigger_error(\sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $name), \E_USER_NOTICE);
314314
} else {
315315
$data[$k] = $value;
316316
}

ProxyHelper.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,34 @@ final class ProxyHelper
2828
public static function generateLazyGhost(\ReflectionClass $class): string
2929
{
3030
if (\PHP_VERSION_ID < 80300 && $class->isReadOnly()) {
31-
throw new LogicException(sprintf('Cannot generate lazy ghost with PHP < 8.3: class "%s" is readonly.', $class->name));
31+
throw new LogicException(\sprintf('Cannot generate lazy ghost with PHP < 8.3: class "%s" is readonly.', $class->name));
3232
}
3333
if ($class->isFinal()) {
34-
throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" is final.', $class->name));
34+
throw new LogicException(\sprintf('Cannot generate lazy ghost: class "%s" is final.', $class->name));
3535
}
3636
if ($class->isInterface() || $class->isAbstract()) {
37-
throw new LogicException(sprintf('Cannot generate lazy ghost: "%s" is not a concrete class.', $class->name));
37+
throw new LogicException(\sprintf('Cannot generate lazy ghost: "%s" is not a concrete class.', $class->name));
3838
}
3939
if (\stdClass::class !== $class->name && $class->isInternal()) {
40-
throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" is internal.', $class->name));
40+
throw new LogicException(\sprintf('Cannot generate lazy ghost: class "%s" is internal.', $class->name));
4141
}
4242
if ($class->hasMethod('__get') && 'mixed' !== (self::exportType($class->getMethod('__get')) ?? 'mixed')) {
43-
throw new LogicException(sprintf('Cannot generate lazy ghost: return type of method "%s::__get()" should be "mixed".', $class->name));
43+
throw new LogicException(\sprintf('Cannot generate lazy ghost: return type of method "%s::__get()" should be "mixed".', $class->name));
4444
}
4545

4646
static $traitMethods;
4747
$traitMethods ??= (new \ReflectionClass(LazyGhostTrait::class))->getMethods();
4848

4949
foreach ($traitMethods as $method) {
5050
if ($class->hasMethod($method->name) && $class->getMethod($method->name)->isFinal()) {
51-
throw new LogicException(sprintf('Cannot generate lazy ghost: method "%s::%s()" is final.', $class->name, $method->name));
51+
throw new LogicException(\sprintf('Cannot generate lazy ghost: method "%s::%s()" is final.', $class->name, $method->name));
5252
}
5353
}
5454

5555
$parent = $class;
5656
while ($parent = $parent->getParentClass()) {
5757
if (\stdClass::class !== $parent->name && $parent->isInternal()) {
58-
throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" extends "%s" which is internal.', $class->name, $parent->name));
58+
throw new LogicException(\sprintf('Cannot generate lazy ghost: class "%s" extends "%s" which is internal.', $class->name, $parent->name));
5959
}
6060
}
6161
$propertyScopes = self::exportPropertyScopes($class->name);
@@ -86,19 +86,19 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
8686
public static function generateLazyProxy(?\ReflectionClass $class, array $interfaces = []): string
8787
{
8888
if (!class_exists($class?->name ?? \stdClass::class, false)) {
89-
throw new LogicException(sprintf('Cannot generate lazy proxy: "%s" is not a class.', $class->name));
89+
throw new LogicException(\sprintf('Cannot generate lazy proxy: "%s" is not a class.', $class->name));
9090
}
9191
if ($class?->isFinal()) {
92-
throw new LogicException(sprintf('Cannot generate lazy proxy: class "%s" is final.', $class->name));
92+
throw new LogicException(\sprintf('Cannot generate lazy proxy: class "%s" is final.', $class->name));
9393
}
9494
if (\PHP_VERSION_ID < 80300 && $class?->isReadOnly()) {
95-
throw new LogicException(sprintf('Cannot generate lazy proxy with PHP < 8.3: class "%s" is readonly.', $class->name));
95+
throw new LogicException(\sprintf('Cannot generate lazy proxy with PHP < 8.3: class "%s" is readonly.', $class->name));
9696
}
9797

9898
$methodReflectors = [$class?->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) ?? []];
9999
foreach ($interfaces as $interface) {
100100
if (!$interface->isInterface()) {
101-
throw new LogicException(sprintf('Cannot generate lazy proxy: "%s" is not an interface.', $interface->name));
101+
throw new LogicException(\sprintf('Cannot generate lazy proxy: "%s" is not an interface.', $interface->name));
102102
}
103103
$methodReflectors[] = $interface->getMethods();
104104
}
@@ -134,7 +134,7 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
134134
}
135135
if ($method->isFinal()) {
136136
if ($extendsInternalClass || $methodsHaveToBeProxied || method_exists(LazyProxyTrait::class, $method->name)) {
137-
throw new LogicException(sprintf('Cannot generate lazy proxy: method "%s::%s()" is final.', $class->name, $method->name));
137+
throw new LogicException(\sprintf('Cannot generate lazy proxy: method "%s::%s()" is final.', $class->name, $method->name));
138138
}
139139
continue;
140140
}
@@ -239,7 +239,7 @@ public static function exportSignature(\ReflectionFunctionAbstract $function, bo
239239
$args = substr($args, 0, -2);
240240
} else {
241241
$args = explode(', ', $args, 1 + $byRefIndex);
242-
$args[$byRefIndex] = sprintf('...\array_slice(\func_get_args(), %d)', $byRefIndex);
242+
$args[$byRefIndex] = \sprintf('...\array_slice(\func_get_args(), %d)', $byRefIndex);
243243
$args = implode(', ', $args);
244244
}
245245

0 commit comments

Comments
 (0)