Skip to content

Commit beb9785

Browse files
CS fixes
1 parent 80e0378 commit beb9785

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

Exception/UnexpectedTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class UnexpectedTypeException extends RuntimeException
2626
*/
2727
public function __construct(mixed $value, PropertyPathInterface $path, int $pathIndex)
2828
{
29-
$message = sprintf(
29+
$message = \sprintf(
3030
'PropertyAccessor requires a graph of objects or arrays to operate on, '.
3131
'but it found type "%s" while trying to traverse path "%s" at property "%s".',
3232
\gettype($value),

PropertyAccessor.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ private static function throwInvalidArgumentException(string $message, array $tr
195195
if (preg_match('/^\S+::\S+\(\): Argument #\d+ \(\$\S+\) must be of type (\S+), (\S+) given/', $message, $matches)) {
196196
[, $expectedType, $actualType] = $matches;
197197

198-
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
198+
throw new InvalidArgumentException(\sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
199199
}
200200
if (preg_match('/^Cannot assign (\S+) to property \S+::\$\S+ of type (\S+)$/', $message, $matches)) {
201201
[, $actualType, $expectedType] = $matches;
202202

203-
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
203+
throw new InvalidArgumentException(\sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
204204
}
205205
}
206206

@@ -216,7 +216,7 @@ public function isReadable(object|array $objectOrArray, string|PropertyPathInter
216216
];
217217

218218
// handle stdClass with properties with a dot in the name
219-
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
219+
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
220220
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);
221221
} else {
222222
$this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
@@ -308,13 +308,13 @@ private function readPropertiesUntil(array $zval, PropertyPathInterface $propert
308308
if (!$ignoreInvalidIndices && !$isNullSafe) {
309309
if (!\is_array($zval[self::VALUE])) {
310310
if (!$zval[self::VALUE] instanceof \Traversable) {
311-
throw new NoSuchIndexException(sprintf('Cannot read index "%s" while trying to traverse path "%s".', $property, (string) $propertyPath));
311+
throw new NoSuchIndexException(\sprintf('Cannot read index "%s" while trying to traverse path "%s".', $property, (string) $propertyPath));
312312
}
313313

314314
$zval[self::VALUE] = iterator_to_array($zval[self::VALUE]);
315315
}
316316

317-
throw new NoSuchIndexException(sprintf('Cannot read index "%s" while trying to traverse path "%s". Available indices are "%s".', $property, (string) $propertyPath, print_r(array_keys($zval[self::VALUE]), true)));
317+
throw new NoSuchIndexException(\sprintf('Cannot read index "%s" while trying to traverse path "%s". Available indices are "%s".', $property, (string) $propertyPath, print_r(array_keys($zval[self::VALUE]), true)));
318318
}
319319

320320
if ($i + 1 < $propertyPath->getLength()) {
@@ -366,7 +366,7 @@ private function readPropertiesUntil(array $zval, PropertyPathInterface $propert
366366
private function readIndex(array $zval, string|int $index): array
367367
{
368368
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
369-
throw new NoSuchIndexException(sprintf('Cannot read index "%s" from object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
369+
throw new NoSuchIndexException(\sprintf('Cannot read index "%s" from object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
370370
}
371371

372372
$result = self::RESULT_PROTO;
@@ -394,7 +394,7 @@ private function readIndex(array $zval, string|int $index): array
394394
private function readProperty(array $zval, string $property, bool $ignoreInvalidProperty = false, bool $isNullSafe = false): array
395395
{
396396
if (!\is_object($zval[self::VALUE])) {
397-
throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you intended to write the property path as "[%1$s]" instead.', $property));
397+
throw new NoSuchPropertyException(\sprintf('Cannot read property "%s" from an array. Maybe you intended to write the property path as "[%1$s]" instead.', $property));
398398
}
399399

400400
$result = self::RESULT_PROTO;
@@ -419,7 +419,7 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
419419
&& $object instanceof $trace['class']
420420
&& preg_match('/Return value (?:of .*::\w+\(\) )?must be of (?:the )?type (\w+), null returned$/', $e->getMessage(), $matches)
421421
) {
422-
throw new UninitializedPropertyException(sprintf('The method "%s::%s()" returned "null", but expected type "%3$s". Did you forget to initialize a property or to make the return type nullable using "?%3$s"?', get_debug_type($object), $name, $matches[1]), 0, $e);
422+
throw new UninitializedPropertyException(\sprintf('The method "%s::%s()" returned "null", but expected type "%3$s". Did you forget to initialize a property or to make the return type nullable using "?%3$s"?', get_debug_type($object), $name, $matches[1]), 0, $e);
423423
}
424424

425425
throw $e;
@@ -430,11 +430,11 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
430430
$r = new \ReflectionProperty($class, $name);
431431

432432
if ($r->isPublic() && !$r->hasType()) {
433-
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', $class, $name));
433+
throw new UninitializedPropertyException(\sprintf('The property "%s::$%s" is not initialized.', $class, $name));
434434
}
435435
} catch (\ReflectionException $e) {
436436
if (!$ignoreInvalidProperty) {
437-
throw new NoSuchPropertyException(sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
437+
throw new NoSuchPropertyException(\sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
438438
}
439439
}
440440
}
@@ -451,7 +451,7 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
451451
$r = new \ReflectionProperty(str_contains($matches[1], '@anonymous') ? $class : $matches[1], $matches[2]);
452452
$type = ($type = $r->getType()) instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
453453

454-
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not readable because it is typed "%s". You should initialize it or declare a default value instead.', $matches[1], $r->getName(), $type), 0, $e);
454+
throw new UninitializedPropertyException(\sprintf('The property "%s::$%s" is not readable because it is typed "%s". You should initialize it or declare a default value instead.', $matches[1], $r->getName(), $type), 0, $e);
455455
}
456456

457457
throw $e;
@@ -464,7 +464,7 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
464464
} elseif ($isNullSafe) {
465465
$result[self::VALUE] = null;
466466
} elseif (!$ignoreInvalidProperty) {
467-
throw new NoSuchPropertyException(sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
467+
throw new NoSuchPropertyException(\sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
468468
}
469469

470470
// Objects are always passed around by reference
@@ -514,7 +514,7 @@ private function getReadInfo(string $class, string $property): ?PropertyReadInfo
514514
private function writeIndex(array $zval, string|int $index, mixed $value): void
515515
{
516516
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
517-
throw new NoSuchIndexException(sprintf('Cannot modify index "%s" in object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
517+
throw new NoSuchIndexException(\sprintf('Cannot modify index "%s" in object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
518518
}
519519

520520
$zval[self::REF][$index] = $value;
@@ -528,7 +528,7 @@ private function writeIndex(array $zval, string|int $index, mixed $value): void
528528
private function writeProperty(array $zval, string $property, mixed $value, bool $recursive = false): void
529529
{
530530
if (!\is_object($zval[self::VALUE])) {
531-
throw new NoSuchPropertyException(sprintf('Cannot write property "%s" to an array. Maybe you should write the property path as "[%1$s]" instead?', $property));
531+
throw new NoSuchPropertyException(\sprintf('Cannot write property "%s" to an array. Maybe you should write the property path as "[%1$s]" instead?', $property));
532532
}
533533

534534
$object = $zval[self::VALUE];
@@ -553,7 +553,7 @@ private function writeProperty(array $zval, string $property, mixed $value, bool
553553
throw new NoSuchPropertyException(implode('. ', $mutator->getErrors()).'.');
554554
}
555555

556-
throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s" in class "%s".', $property, get_debug_type($object)));
556+
throw new NoSuchPropertyException(\sprintf('Could not determine access type for property "%s" in class "%s".', $property, get_debug_type($object)));
557557
}
558558
} catch (\TypeError $e) {
559559
if ($recursive || !$value instanceof \DateTimeInterface || !\in_array($value::class, ['DateTime', 'DateTimeImmutable'], true) || __FILE__ !== ($e->getTrace()[0]['file'] ?? null)) {
@@ -646,7 +646,7 @@ private function isPropertyWritable(object $object, string $property): bool
646646

647647
$mutatorForArray = $this->getWriteInfo($object::class, $property, []);
648648
if (PropertyWriteInfo::TYPE_PROPERTY === $mutatorForArray->getType()) {
649-
return $mutatorForArray->getVisibility() === 'public';
649+
return 'public' === $mutatorForArray->getVisibility();
650650
}
651651

652652
if (PropertyWriteInfo::TYPE_NONE !== $mutatorForArray->getType()) {
@@ -696,7 +696,7 @@ private function getPropertyPath(string|PropertyPath $propertyPath): PropertyPat
696696
public static function createCache(string $namespace, int $defaultLifetime, string $version, ?LoggerInterface $logger = null): AdapterInterface
697697
{
698698
if (!class_exists(ApcuAdapter::class)) {
699-
throw new \LogicException(sprintf('The Symfony Cache component must be installed to use "%s()".', __METHOD__));
699+
throw new \LogicException(\sprintf('The Symfony Cache component must be installed to use "%s()".', __METHOD__));
700700
}
701701

702702
if (!ApcuAdapter::isSupported()) {

PropertyPath.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function __construct(self|string $propertyPath)
122122
}
123123

124124
if ('' !== $remaining) {
125-
throw new InvalidPropertyPathException(sprintf('Could not parse property path "%s". Unexpected token "%s" at position %d.', $propertyPath, $remaining[0], $position));
125+
throw new InvalidPropertyPathException(\sprintf('Could not parse property path "%s". Unexpected token "%s" at position %d.', $propertyPath, $remaining[0], $position));
126126
}
127127

128128
$this->length = \count($this->elements);
@@ -171,7 +171,7 @@ public function getElements(): array
171171
public function getElement(int $index): string
172172
{
173173
if (!isset($this->elements[$index])) {
174-
throw new OutOfBoundsException(sprintf('The index "%s" is not within the property path.', $index));
174+
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the property path.', $index));
175175
}
176176

177177
return $this->elements[$index];
@@ -180,7 +180,7 @@ public function getElement(int $index): string
180180
public function isProperty(int $index): bool
181181
{
182182
if (!isset($this->isIndex[$index])) {
183-
throw new OutOfBoundsException(sprintf('The index "%s" is not within the property path.', $index));
183+
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the property path.', $index));
184184
}
185185

186186
return !$this->isIndex[$index];
@@ -189,7 +189,7 @@ public function isProperty(int $index): bool
189189
public function isIndex(int $index): bool
190190
{
191191
if (!isset($this->isIndex[$index])) {
192-
throw new OutOfBoundsException(sprintf('The index "%s" is not within the property path.', $index));
192+
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the property path.', $index));
193193
}
194194

195195
return $this->isIndex[$index];
@@ -198,7 +198,7 @@ public function isIndex(int $index): bool
198198
public function isNullSafe(int $index): bool
199199
{
200200
if (!isset($this->isNullSafe[$index])) {
201-
throw new OutOfBoundsException(sprintf('The index "%s" is not within the property path.', $index));
201+
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the property path.', $index));
202202
}
203203

204204
return $this->isNullSafe[$index];

PropertyPathBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function appendProperty(string $name)
8686
public function remove(int $offset, int $length = 1)
8787
{
8888
if (!isset($this->elements[$offset])) {
89-
throw new OutOfBoundsException(sprintf('The offset "%s" is not within the property path.', $offset));
89+
throw new OutOfBoundsException(\sprintf('The offset "%s" is not within the property path.', $offset));
9090
}
9191

9292
$this->resize($offset, $length, 0);
@@ -137,7 +137,7 @@ public function replace(int $offset, int $length, PropertyPathInterface|string $
137137
public function replaceByIndex(int $offset, ?string $name = null)
138138
{
139139
if (!isset($this->elements[$offset])) {
140-
throw new OutOfBoundsException(sprintf('The offset "%s" is not within the property path.', $offset));
140+
throw new OutOfBoundsException(\sprintf('The offset "%s" is not within the property path.', $offset));
141141
}
142142

143143
if (null !== $name) {
@@ -157,7 +157,7 @@ public function replaceByIndex(int $offset, ?string $name = null)
157157
public function replaceByProperty(int $offset, ?string $name = null)
158158
{
159159
if (!isset($this->elements[$offset])) {
160-
throw new OutOfBoundsException(sprintf('The offset "%s" is not within the property path.', $offset));
160+
throw new OutOfBoundsException(\sprintf('The offset "%s" is not within the property path.', $offset));
161161
}
162162

163163
if (null !== $name) {

Tests/PropertyAccessorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAn
149149
$this->expectException(UninitializedPropertyException::class);
150150
$this->expectExceptionMessage('The method "class@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
151151

152-
$object = new class() {
152+
$object = new class {
153153
private $uninitialized;
154154

155155
public function getUninitialized(): array
@@ -166,7 +166,7 @@ public function testGetValueThrowsExceptionIfUninitializedNotNullablePropertyWit
166166
$this->expectException(UninitializedPropertyException::class);
167167
$this->expectExceptionMessage('The property "class@anonymous::$uninitialized" is not readable because it is typed "string". You should initialize it or declare a default value instead.');
168168

169-
$object = new class() {
169+
$object = new class {
170170
private string $uninitialized;
171171

172172
public function getUninitialized(): string
@@ -183,7 +183,7 @@ public function testGetValueThrowsExceptionIfUninitializedPropertyOfAnonymousCla
183183
$this->expectException(UninitializedPropertyException::class);
184184
$this->expectExceptionMessage('The property "class@anonymous::$uninitialized" is not readable because it is typed "string". You should initialize it or declare a default value instead.');
185185

186-
$object = new class() {
186+
$object = new class {
187187
public string $uninitialized;
188188
};
189189

@@ -211,7 +211,7 @@ public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAn
211211
$this->expectException(UninitializedPropertyException::class);
212212
$this->expectExceptionMessage('The method "stdClass@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
213213

214-
$object = new class() extends \stdClass {
214+
$object = new class extends \stdClass {
215215
private $uninitialized;
216216

217217
public function getUninitialized(): array
@@ -228,7 +228,7 @@ public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAn
228228
$this->expectException(UninitializedPropertyException::class);
229229
$this->expectExceptionMessage('The method "Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedPrivateProperty@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
230230

231-
$object = new class() extends UninitializedPrivateProperty {
231+
$object = new class extends UninitializedPrivateProperty {
232232
};
233233

234234
$this->propertyAccessor->getValue($object, 'uninitialized');
@@ -1010,7 +1010,7 @@ public function testIsReadableWithMissingPropertyAndLazyGhost()
10101010
private function createUninitializedObjectPropertyGhost(): UninitializedObjectProperty
10111011
{
10121012
if (!class_exists(ProxyHelper::class)) {
1013-
$this->markTestSkipped(sprintf('Class "%s" is required to run this test.', ProxyHelper::class));
1013+
$this->markTestSkipped(\sprintf('Class "%s" is required to run this test.', ProxyHelper::class));
10141014
}
10151015

10161016
$class = 'UninitializedObjectPropertyGhost';
@@ -1072,7 +1072,7 @@ public function testSetValueWithAsymmetricVisibility(string $propertyPath, ?stri
10721072
}
10731073

10741074
/**
1075-
* @return iterable<array{0: string, 1: null|class-string}>
1075+
* @return iterable<array{0: string, 1: class-string|null}>
10761076
*/
10771077
public static function setValueWithAsymmetricVisibilityDataProvider(): iterable
10781078
{

0 commit comments

Comments
 (0)