Skip to content

Commit 1e742d5

Browse files
CS fixes
1 parent 0efdbc8 commit 1e742d5

12 files changed

+44
-44
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())) {
@@ -173,7 +173,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
173173
}
174174
if ($sleep) {
175175
foreach ($sleep as $n => $v) {
176-
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), \E_USER_NOTICE);
176+
trigger_error(\sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), \E_USER_NOTICE);
177177
}
178178
}
179179
if (method_exists($class, '__unserialize')) {
@@ -226,10 +226,10 @@ public static function export($value, $indent = '')
226226
$subIndent = $indent.' ';
227227

228228
if (\is_string($value)) {
229-
$code = sprintf("'%s'", addcslashes($value, "'\\"));
229+
$code = \sprintf("'%s'", addcslashes($value, "'\\"));
230230

231231
$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) {
232-
$m[1] = sprintf('\'."%s".\'', str_replace(
232+
$m[1] = \sprintf('\'."%s".\'', str_replace(
233233
["\0", "\r", "\n", "\u{202A}", "\u{202B}", "\u{202D}", "\u{202E}", "\u{2066}", "\u{2067}", "\u{2068}", "\u{202C}", "\u{2069}", '\n\\'],
234234
['\0', '\r', '\n', '\u{202A}', '\u{202B}', '\u{202D}', '\u{202E}', '\u{2066}', '\u{2067}', '\u{2068}', '\u{202C}', '\u{2069}', '\n"'."\n".$subIndent.'."\\'],
235235
$m[1]
@@ -287,7 +287,7 @@ public static function export($value, $indent = '')
287287
return self::exportHydrator($value, $indent, $subIndent);
288288
}
289289

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

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

Internal/Hydrator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public static function getHydrator($class)
7373
return $baseHydrator;
7474

7575
case 'ErrorException':
76-
return $baseHydrator->bindTo(null, new class() extends \ErrorException {
76+
return $baseHydrator->bindTo(null, new class extends \ErrorException {
7777
});
7878

7979
case 'TypeError':
80-
return $baseHydrator->bindTo(null, new class() extends \Error {
80+
return $baseHydrator->bindTo(null, new class extends \Error {
8181
});
8282

8383
case 'SplObjectStorage':
@@ -178,11 +178,11 @@ public static function getSimpleHydrator($class)
178178
return $baseHydrator;
179179

180180
case 'ErrorException':
181-
return $baseHydrator->bindTo(new \stdClass(), new class() extends \ErrorException {
181+
return $baseHydrator->bindTo(new \stdClass(), new class extends \ErrorException {
182182
});
183183

184184
case 'TypeError':
185-
return $baseHydrator->bindTo(new \stdClass(), new class() extends \Error {
185+
return $baseHydrator->bindTo(new \stdClass(), new class extends \Error {
186186
});
187187

188188
case 'SplObjectStorage':

Internal/LazyObjectState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function initialize($instance, $propertyName, $writeScope)
6767

6868
if ($initializer = $this->initializer["\0"] ?? null) {
6969
if (!\is_array($values = $initializer($instance, LazyObjectRegistry::$defaultProperties[$class]))) {
70-
throw new \TypeError(sprintf('The lazy-initializer defined for instance of "%s" must return an array, got "%s".', $class, get_debug_type($values)));
70+
throw new \TypeError(\sprintf('The lazy-initializer defined for instance of "%s" must return an array, got "%s".', $class, get_debug_type($values)));
7171
}
7272
$properties = (array) $instance;
7373
foreach ($values as $key => $value) {

LazyGhostTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function initializeLazyObject(): static
120120

121121
if (null === $values) {
122122
if (!\is_array($values = ($state->initializer["\0"])($this, Registry::$defaultProperties[$class]))) {
123-
throw new \TypeError(sprintf('The lazy-initializer defined for instance of "%s" must return an array, got "%s".', $class, get_debug_type($values)));
123+
throw new \TypeError(\sprintf('The lazy-initializer defined for instance of "%s" must return an array, got "%s".', $class, get_debug_type($values)));
124124
}
125125

126126
if (\array_key_exists($key, $properties = (array) $this)) {
@@ -198,7 +198,7 @@ public function &__get($name): mixed
198198

199199
if (null === $class) {
200200
$frame = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
201-
trigger_error(sprintf('Undefined property: %s::$%s in %s on line %s', $this::class, $name, $frame['file'], $frame['line']), \E_USER_NOTICE);
201+
trigger_error(\sprintf('Undefined property: %s::$%s in %s on line %s', $this::class, $name, $frame['file'], $frame['line']), \E_USER_NOTICE);
202202
}
203203

204204
get_in_scope:
@@ -375,7 +375,7 @@ public function __serialize(): array
375375
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0$class\0$name"] ?? $properties[$k = "\0$scope\0$name"] ?? $k = null;
376376

377377
if (null === $k) {
378-
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $name), \E_USER_NOTICE);
378+
trigger_error(\sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $name), \E_USER_NOTICE);
379379
} else {
380380
$data[$k] = $value;
381381
}

LazyProxyTrait.php

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

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

126126
get_in_scope:
@@ -306,7 +306,7 @@ public function __serialize(): array
306306
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0$class\0$name"] ?? $properties[$k = "\0$scope\0$name"] ?? $k = null;
307307

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

ProxyHelper.php

Lines changed: 16 additions & 16 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 >= 80200 && \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() || $class->isTrait()) {
3737
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

@@ -70,7 +70,7 @@ public static function generateLazyGhost(\ReflectionClass $class): string
7070
}
7171

7272
if ($flags & (\ReflectionProperty::IS_FINAL | \ReflectionProperty::IS_PRIVATE)) {
73-
throw new LogicException(sprintf('Cannot generate lazy ghost: property "%s::$%s" is final or private(set).', $class->name, $name));
73+
throw new LogicException(\sprintf('Cannot generate lazy ghost: property "%s::$%s" is final or private(set).', $class->name, $name));
7474
}
7575

7676
$p = $propertyScopes[$k][4] ?? Hydrator::$propertyScopes[$class->name][$k][4] = new \ReflectionProperty($scope, $name);
@@ -92,7 +92,7 @@ public static function generateLazyGhost(\ReflectionClass $class): string
9292
$arg = '$'.$method->getParameters()[0]->name;
9393
$hooks .= " set({$parameters}) { \$this->initializeLazyObject(); parent::\${$name}::set({$arg}); }\n";
9494
} else {
95-
throw new LogicException(sprintf('Cannot generate lazy ghost: hook "%s::%s()" is not supported.', $class->name, $method->name));
95+
throw new LogicException(\sprintf('Cannot generate lazy ghost: hook "%s::%s()" is not supported.', $class->name, $method->name));
9696
}
9797
}
9898

@@ -127,13 +127,13 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
127127
public static function generateLazyProxy(?\ReflectionClass $class, array $interfaces = []): string
128128
{
129129
if (!class_exists($class?->name ?? \stdClass::class, false)) {
130-
throw new LogicException(sprintf('Cannot generate lazy proxy: "%s" is not a class.', $class->name));
130+
throw new LogicException(\sprintf('Cannot generate lazy proxy: "%s" is not a class.', $class->name));
131131
}
132132
if ($class?->isFinal()) {
133-
throw new LogicException(sprintf('Cannot generate lazy proxy: class "%s" is final.', $class->name));
133+
throw new LogicException(\sprintf('Cannot generate lazy proxy: class "%s" is final.', $class->name));
134134
}
135135
if (\PHP_VERSION_ID >= 80200 && \PHP_VERSION_ID < 80300 && $class?->isReadOnly()) {
136-
throw new LogicException(sprintf('Cannot generate lazy proxy with PHP < 8.3: class "%s" is readonly.', $class->name));
136+
throw new LogicException(\sprintf('Cannot generate lazy proxy with PHP < 8.3: class "%s" is readonly.', $class->name));
137137
}
138138

139139
$propertyScopes = $class ? Hydrator::$propertyScopes[$class->name] ??= Hydrator::getPropertyScopes($class->name) : [];
@@ -159,7 +159,7 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
159159
}
160160

161161
if ($flags & (\ReflectionProperty::IS_FINAL | \ReflectionProperty::IS_PRIVATE)) {
162-
throw new LogicException(sprintf('Cannot generate lazy proxy: property "%s::$%s" is final or private(set).', $class->name, $name));
162+
throw new LogicException(\sprintf('Cannot generate lazy proxy: property "%s::$%s" is final or private(set).', $class->name, $name));
163163
}
164164

165165
$p = $propertyScopes[$k][4] ?? Hydrator::$propertyScopes[$class->name][$k][4] = new \ReflectionProperty($scope, $name);
@@ -170,7 +170,7 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
170170
$methodReflectors = [$class?->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) ?? []];
171171
foreach ($interfaces as $interface) {
172172
if (!$interface->isInterface()) {
173-
throw new LogicException(sprintf('Cannot generate lazy proxy: "%s" is not an interface.', $interface->name));
173+
throw new LogicException(\sprintf('Cannot generate lazy proxy: "%s" is not an interface.', $interface->name));
174174
}
175175
$methodReflectors[] = $interface->getMethods();
176176

@@ -228,7 +228,7 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
228228
229229
EOPHP;
230230
} else {
231-
throw new LogicException(sprintf('Cannot generate lazy proxy: hook "%s::%s()" is not supported.', $class->name, $method->name));
231+
throw new LogicException(\sprintf('Cannot generate lazy proxy: hook "%s::%s()" is not supported.', $class->name, $method->name));
232232
}
233233
}
234234

@@ -266,7 +266,7 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
266266
}
267267
if ($method->isFinal()) {
268268
if ($extendsInternalClass || $methodsHaveToBeProxied || method_exists(LazyProxyTrait::class, $method->name)) {
269-
throw new LogicException(sprintf('Cannot generate lazy proxy: method "%s::%s()" is final.', $class->name, $method->name));
269+
throw new LogicException(\sprintf('Cannot generate lazy proxy: method "%s::%s()" is final.', $class->name, $method->name));
270270
}
271271
continue;
272272
}
@@ -396,7 +396,7 @@ public static function exportParameters(\ReflectionFunctionAbstract $function, b
396396
$args = substr($args, 0, -2);
397397
} else {
398398
$args = explode(', ', $args, 1 + $byRefIndex);
399-
$args[$byRefIndex] = sprintf('...\array_slice(\func_get_args(), %d)', $byRefIndex);
399+
$args[$byRefIndex] = \sprintf('...\array_slice(\func_get_args(), %d)', $byRefIndex);
400400
$args = implode(', ', $args);
401401
}
402402

Tests/LazyGhostTraitTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public function testFullInitializationAfterPartialInitialization()
426426

427427
public function testIndirectModification()
428428
{
429-
$obj = new class() {
429+
$obj = new class {
430430
public array $foo;
431431
};
432432
$proxy = $this->createLazyGhost($obj::class, fn () => null);
@@ -518,7 +518,7 @@ public function testPropertyHooksWithDefaultValue()
518518

519519
$this->assertSame(321, $object->backedIntWithDefault);
520520
$this->assertSame('321', $object->backedStringWithDefault);
521-
$this->assertSame(false, $object->backedBoolWithDefault);
521+
$this->assertFalse($object->backedBoolWithDefault);
522522
$this->assertTrue($initialized);
523523

524524
$initialized = false;
@@ -531,7 +531,7 @@ public function testPropertyHooksWithDefaultValue()
531531
$this->assertTrue($initialized);
532532
$this->assertSame(654, $object->backedIntWithDefault);
533533
$this->assertSame('654', $object->backedStringWithDefault);
534-
$this->assertSame(true, $object->backedBoolWithDefault);
534+
$this->assertTrue($object->backedBoolWithDefault);
535535
}
536536

537537
/**

Tests/LazyProxyTraitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function testOverwritePropClass()
208208

209209
public function testWither()
210210
{
211-
$obj = new class() {
211+
$obj = new class {
212212
public $foo = 123;
213213

214214
public function withFoo($foo): static
@@ -229,7 +229,7 @@ public function withFoo($foo): static
229229

230230
public function testFluent()
231231
{
232-
$obj = new class() {
232+
$obj = new class {
233233
public $foo = 123;
234234

235235
public function setFoo($foo): static
@@ -247,7 +247,7 @@ public function setFoo($foo): static
247247

248248
public function testIndirectModification()
249249
{
250-
$obj = new class() {
250+
$obj = new class {
251251
public array $foo;
252252
};
253253
$proxy = $this->createLazyProxy($obj::class, fn () => $obj);
@@ -274,7 +274,7 @@ public function testReadOnlyClass()
274274

275275
public function testLazyDecoratorClass()
276276
{
277-
$obj = new class() extends TestClass {
277+
$obj = new class extends TestClass {
278278
use LazyProxyTrait {
279279
createLazyProxy as private;
280280
}

0 commit comments

Comments
 (0)