Skip to content

Commit acd9ded

Browse files
CS fixes
1 parent af5917a commit acd9ded

32 files changed

+150
-151
lines changed

Builder/ClassBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public function build(): string
6363
}
6464
unset($path[$key]);
6565
}
66-
$require .= sprintf('require_once __DIR__.\DIRECTORY_SEPARATOR.\'%s\';', implode('\'.\DIRECTORY_SEPARATOR.\'', $path))."\n";
66+
$require .= \sprintf('require_once __DIR__.\DIRECTORY_SEPARATOR.\'%s\';', implode('\'.\DIRECTORY_SEPARATOR.\'', $path))."\n";
6767
}
6868
$use = $require ? "\n" : '';
6969
foreach (array_keys($this->use) as $statement) {
70-
$use .= sprintf('use %s;', $statement)."\n";
70+
$use .= \sprintf('use %s;', $statement)."\n";
7171
}
7272

7373
$implements = [] === $this->implements ? '' : 'implements '.implode(', ', $this->implements);
@@ -126,8 +126,8 @@ public function addProperty(string $name, ?string $classType = null, ?string $de
126126
$property->setType($classType);
127127
}
128128
$this->properties[] = $property;
129-
$defaultValue = null !== $defaultValue ? sprintf(' = %s', $defaultValue) : '';
130-
$property->setContent(sprintf('private $%s%s;', $property->getName(), $defaultValue));
129+
$defaultValue = null !== $defaultValue ? \sprintf(' = %s', $defaultValue) : '';
130+
$property->setContent(\sprintf('private $%s%s;', $property->getName(), $defaultValue));
131131

132132
return $property;
133133
}

Builder/ConfigBuilderGenerator.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private function buildNode(NodeInterface $node, ClassBuilder $class, string $nam
115115
$child instanceof PrototypedArrayNode => $this->handlePrototypedArrayNode($child, $class, $namespace),
116116
$child instanceof VariableNode => $this->handleVariableNode($child, $class),
117117
$child instanceof ArrayNode => $this->handleArrayNode($child, $class, $namespace),
118-
default => throw new \RuntimeException(sprintf('Unknown node "%s".', $child::class)),
118+
default => throw new \RuntimeException(\sprintf('Unknown node "%s".', $child::class)),
119119
};
120120
}
121121
}
@@ -130,9 +130,9 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
130130
$hasNormalizationClosures = $this->hasNormalizationClosures($node);
131131
$comment = $this->getComment($node);
132132
if ($hasNormalizationClosures) {
133-
$comment = sprintf(" * @template TValue\n * @param TValue \$value\n%s", $comment);
134-
$comment .= sprintf(' * @return %s|$this'."\n", $childClass->getFqcn());
135-
$comment .= sprintf(' * @psalm-return (TValue is array ? %s : static)'."\n ", $childClass->getFqcn());
133+
$comment = \sprintf(" * @template TValue\n * @param TValue \$value\n%s", $comment);
134+
$comment .= \sprintf(' * @return %s|$this'."\n", $childClass->getFqcn());
135+
$comment .= \sprintf(' * @psalm-return (TValue is array ? %s : static)'."\n ", $childClass->getFqcn());
136136
}
137137
if ('' !== $comment) {
138138
$comment = "/**\n$comment*/\n";
@@ -282,9 +282,9 @@ public function NAME(string $VAR, TYPE $VALUE): static
282282

283283
$comment = $this->getComment($node);
284284
if ($hasNormalizationClosures) {
285-
$comment = sprintf(" * @template TValue\n * @param TValue \$value\n%s", $comment);
286-
$comment .= sprintf(' * @return %s|$this'."\n", $childClass->getFqcn());
287-
$comment .= sprintf(' * @psalm-return (TValue is array ? %s : static)'."\n ", $childClass->getFqcn());
285+
$comment = \sprintf(" * @template TValue\n * @param TValue \$value\n%s", $comment);
286+
$comment .= \sprintf(' * @return %s|$this'."\n", $childClass->getFqcn());
287+
$comment .= \sprintf(' * @psalm-return (TValue is array ? %s : static)'."\n ", $childClass->getFqcn());
288288
}
289289
if ('' !== $comment) {
290290
$comment = "/**\n$comment*/\n";
@@ -426,7 +426,7 @@ private function getComment(BaseNode $node): string
426426
}
427427

428428
if ($node instanceof EnumNode) {
429-
$comment .= sprintf('@param ParamConfigurator|%s $value', implode('|', array_unique(array_map(fn ($a) => !$a instanceof \UnitEnum ? var_export($a, true) : '\\'.ltrim(var_export($a, true), '\\'), $node->getValues()))))."\n";
429+
$comment .= \sprintf('@param ParamConfigurator|%s $value', implode('|', array_unique(array_map(fn ($a) => !$a instanceof \UnitEnum ? var_export($a, true) : '\\'.ltrim(var_export($a, true), '\\'), $node->getValues()))))."\n";
430430
} else {
431431
$parameterTypes = $this->getParameterTypes($node);
432432
$comment .= '@param ParamConfigurator|'.implode('|', $parameterTypes).' $value'."\n";
@@ -579,7 +579,7 @@ public function NAME(string $key, mixed $value): static
579579

580580
private function getSubNamespace(ClassBuilder $rootClass): string
581581
{
582-
return sprintf('%s\\%s', $rootClass->getNamespace(), substr($rootClass->getName(), 0, -6));
582+
return \sprintf('%s\\%s', $rootClass->getNamespace(), substr($rootClass->getName(), 0, -6));
583583
}
584584

585585
private function hasNormalizationClosures(NodeInterface $node): bool

Definition/ArrayNode.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function hasDefaultValue(): bool
177177
public function getDefaultValue(): mixed
178178
{
179179
if (!$this->hasDefaultValue()) {
180-
throw new \RuntimeException(sprintf('The node at path "%s" has no default value.', $this->getPath()));
180+
throw new \RuntimeException(\sprintf('The node at path "%s" has no default value.', $this->getPath()));
181181
}
182182

183183
$defaults = [];
@@ -205,7 +205,7 @@ public function addChild(NodeInterface $node)
205205
throw new \InvalidArgumentException('Child nodes must be named.');
206206
}
207207
if (isset($this->children[$name])) {
208-
throw new \InvalidArgumentException(sprintf('A child node named "%s" already exists.', $name));
208+
throw new \InvalidArgumentException(\sprintf('A child node named "%s" already exists.', $name));
209209
}
210210

211211
$this->children[$name] = $node;
@@ -218,15 +218,15 @@ public function addChild(NodeInterface $node)
218218
protected function finalizeValue(mixed $value): mixed
219219
{
220220
if (false === $value) {
221-
throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
221+
throw new UnsetKeyException(\sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
222222
}
223223

224224
foreach ($this->children as $name => $child) {
225225
if (!\array_key_exists($name, $value)) {
226226
if ($child->isRequired()) {
227-
$message = sprintf('The child config "%s" under "%s" must be configured', $name, $this->getPath());
227+
$message = \sprintf('The child config "%s" under "%s" must be configured', $name, $this->getPath());
228228
if ($child->getInfo()) {
229-
$message .= sprintf(': %s', $child->getInfo());
229+
$message .= \sprintf(': %s', $child->getInfo());
230230
} else {
231231
$message .= '.';
232232
}
@@ -264,7 +264,7 @@ protected function finalizeValue(mixed $value): mixed
264264
protected function validateType(mixed $value)
265265
{
266266
if (!\is_array($value) && (!$this->allowFalse || false !== $value)) {
267-
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "array", but got "%s"', $this->getPath(), get_debug_type($value)));
267+
$ex = new InvalidTypeException(\sprintf('Invalid type for path "%s". Expected "array", but got "%s"', $this->getPath(), get_debug_type($value)));
268268
if ($hint = $this->getInfo()) {
269269
$ex->addHint($hint);
270270
}
@@ -315,13 +315,13 @@ protected function normalizeValue(mixed $value): mixed
315315
}
316316
}
317317

318-
$msg = sprintf('Unrecognized option%s "%s" under "%s"', 1 === \count($value) ? '' : 's', implode(', ', array_keys($value)), $this->getPath());
318+
$msg = \sprintf('Unrecognized option%s "%s" under "%s"', 1 === \count($value) ? '' : 's', implode(', ', array_keys($value)), $this->getPath());
319319

320320
if (\count($guesses)) {
321321
asort($guesses);
322-
$msg .= sprintf('. Did you mean "%s"?', implode('", "', array_keys($guesses)));
322+
$msg .= \sprintf('. Did you mean "%s"?', implode('", "', array_keys($guesses)));
323323
} else {
324-
$msg .= sprintf('. Available option%s %s "%s".', 1 === \count($proposals) ? '' : 's', 1 === \count($proposals) ? 'is' : 'are', implode('", "', $proposals));
324+
$msg .= \sprintf('. Available option%s %s "%s".', 1 === \count($proposals) ? '' : 's', 1 === \count($proposals) ? 'is' : 'are', implode('", "', $proposals));
325325
}
326326

327327
$ex = new InvalidConfigurationException($msg);
@@ -370,7 +370,7 @@ protected function mergeValues(mixed $leftSide, mixed $rightSide): mixed
370370
// no conflict
371371
if (!\array_key_exists($k, $leftSide)) {
372372
if (!$this->allowNewKeys) {
373-
$ex = new InvalidConfigurationException(sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file. If you are trying to overwrite an element, make sure you redefine it with the same name.', $this->getPath()));
373+
$ex = new InvalidConfigurationException(\sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file. If you are trying to overwrite an element, make sure you redefine it with the same name.', $this->getPath()));
374374
$ex->setPath($this->getPath());
375375

376376
throw $ex;

Definition/BaseNode.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function getPath(): string
313313
final public function merge(mixed $leftSide, mixed $rightSide): mixed
314314
{
315315
if (!$this->allowOverwrite) {
316-
throw new ForbiddenOverwriteException(sprintf('Configuration path "%s" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one configuration section.', $this->getPath()));
316+
throw new ForbiddenOverwriteException(\sprintf('Configuration path "%s" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one configuration section.', $this->getPath()));
317317
}
318318

319319
if ($leftSide !== $leftPlaceholders = self::resolvePlaceholderValue($leftSide)) {
@@ -432,7 +432,7 @@ final public function finalize(mixed $value): mixed
432432

433433
throw $e;
434434
} catch (\Exception $e) {
435-
throw new InvalidConfigurationException(sprintf('Invalid configuration for path "%s": ', $this->getPath()).$e->getMessage(), $e->getCode(), $e);
435+
throw new InvalidConfigurationException(\sprintf('Invalid configuration for path "%s": ', $this->getPath()).$e->getMessage(), $e->getCode(), $e);
436436
}
437437
}
438438

@@ -507,7 +507,7 @@ private static function resolvePlaceholderValue(mixed $value): mixed
507507
private function doValidateType(mixed $value): void
508508
{
509509
if (null !== $this->handlingPlaceholder && !$this->allowPlaceholders()) {
510-
$e = new InvalidTypeException(sprintf('A dynamic value is not compatible with a "%s" node type at path "%s".', static::class, $this->getPath()));
510+
$e = new InvalidTypeException(\sprintf('A dynamic value is not compatible with a "%s" node type at path "%s".', static::class, $this->getPath()));
511511
$e->setPath($this->getPath());
512512

513513
throw $e;
@@ -523,7 +523,7 @@ private function doValidateType(mixed $value): void
523523
$validTypes = $this->getValidPlaceholderTypes();
524524

525525
if ($validTypes && array_diff($knownTypes, $validTypes)) {
526-
$e = new InvalidTypeException(sprintf(
526+
$e = new InvalidTypeException(\sprintf(
527527
'Invalid type for path "%s". Expected %s, but got %s.',
528528
$this->getPath(),
529529
1 === \count($validTypes) ? '"'.reset($validTypes).'"' : 'one of "'.implode('", "', $validTypes).'"',

Definition/BooleanNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class BooleanNode extends ScalarNode
2626
protected function validateType(mixed $value)
2727
{
2828
if (!\is_bool($value)) {
29-
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "bool", but got "%s".', $this->getPath(), get_debug_type($value)));
29+
$ex = new InvalidTypeException(\sprintf('Invalid type for path "%s". Expected "bool", but got "%s".', $this->getPath(), get_debug_type($value)));
3030
if ($hint = $this->getInfo()) {
3131
$ex->addHint($hint);
3232
}

Definition/Builder/ArrayNodeDefinition.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ protected function createNode(): NodeInterface
374374

375375
if ($this->default) {
376376
if (!\is_array($this->defaultValue)) {
377-
throw new \InvalidArgumentException(sprintf('%s: the default value of an array node has to be an array.', $node->getPath()));
377+
throw new \InvalidArgumentException(\sprintf('%s: the default value of an array node has to be an array.', $node->getPath()));
378378
}
379379

380380
$node->setDefaultValue($this->defaultValue);
@@ -434,23 +434,23 @@ protected function validateConcreteNode(ArrayNode $node)
434434
$path = $node->getPath();
435435

436436
if (null !== $this->key) {
437-
throw new InvalidDefinitionException(sprintf('->useAttributeAsKey() is not applicable to concrete nodes at path "%s".', $path));
437+
throw new InvalidDefinitionException(\sprintf('->useAttributeAsKey() is not applicable to concrete nodes at path "%s".', $path));
438438
}
439439

440440
if (false === $this->allowEmptyValue) {
441-
throw new InvalidDefinitionException(sprintf('->cannotBeEmpty() is not applicable to concrete nodes at path "%s".', $path));
441+
throw new InvalidDefinitionException(\sprintf('->cannotBeEmpty() is not applicable to concrete nodes at path "%s".', $path));
442442
}
443443

444444
if (true === $this->atLeastOne) {
445-
throw new InvalidDefinitionException(sprintf('->requiresAtLeastOneElement() is not applicable to concrete nodes at path "%s".', $path));
445+
throw new InvalidDefinitionException(\sprintf('->requiresAtLeastOneElement() is not applicable to concrete nodes at path "%s".', $path));
446446
}
447447

448448
if ($this->default) {
449-
throw new InvalidDefinitionException(sprintf('->defaultValue() is not applicable to concrete nodes at path "%s".', $path));
449+
throw new InvalidDefinitionException(\sprintf('->defaultValue() is not applicable to concrete nodes at path "%s".', $path));
450450
}
451451

452452
if (false !== $this->addDefaultChildren) {
453-
throw new InvalidDefinitionException(sprintf('->addDefaultChildrenIfNoneSet() is not applicable to concrete nodes at path "%s".', $path));
453+
throw new InvalidDefinitionException(\sprintf('->addDefaultChildrenIfNoneSet() is not applicable to concrete nodes at path "%s".', $path));
454454
}
455455
}
456456

@@ -466,20 +466,20 @@ protected function validatePrototypeNode(PrototypedArrayNode $node)
466466
$path = $node->getPath();
467467

468468
if ($this->addDefaults) {
469-
throw new InvalidDefinitionException(sprintf('->addDefaultsIfNotSet() is not applicable to prototype nodes at path "%s".', $path));
469+
throw new InvalidDefinitionException(\sprintf('->addDefaultsIfNotSet() is not applicable to prototype nodes at path "%s".', $path));
470470
}
471471

472472
if (false !== $this->addDefaultChildren) {
473473
if ($this->default) {
474-
throw new InvalidDefinitionException(sprintf('A default value and default children might not be used together at path "%s".', $path));
474+
throw new InvalidDefinitionException(\sprintf('A default value and default children might not be used together at path "%s".', $path));
475475
}
476476

477477
if (null !== $this->key && (null === $this->addDefaultChildren || \is_int($this->addDefaultChildren) && $this->addDefaultChildren > 0)) {
478-
throw new InvalidDefinitionException(sprintf('->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path "%s".', $path));
478+
throw new InvalidDefinitionException(\sprintf('->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path "%s".', $path));
479479
}
480480

481481
if (null === $this->key && (\is_string($this->addDefaultChildren) || \is_array($this->addDefaultChildren))) {
482-
throw new InvalidDefinitionException(sprintf('->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path "%s".', $path));
482+
throw new InvalidDefinitionException(\sprintf('->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path "%s".', $path));
483483
}
484484
}
485485
}
@@ -504,7 +504,7 @@ public function find(string $nodePath): NodeDefinition
504504
: substr($nodePath, 0, $pathSeparatorPos);
505505

506506
if (null === $node = ($this->children[$firstPathSegment] ?? null)) {
507-
throw new \RuntimeException(sprintf('Node with name "%s" does not exist in the current node "%s".', $firstPathSegment, $this->name));
507+
throw new \RuntimeException(\sprintf('Node with name "%s" does not exist in the current node "%s".', $firstPathSegment, $this->name));
508508
}
509509

510510
if (false === $pathSeparatorPos) {

Definition/Builder/ExprBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function thenEmptyArray(): static
196196
*/
197197
public function thenInvalid(string $message): static
198198
{
199-
$this->thenPart = static fn ($v) => throw new \InvalidArgumentException(sprintf($message, json_encode($v)));
199+
$this->thenPart = static fn ($v) => throw new \InvalidArgumentException(\sprintf($message, json_encode($v)));
200200

201201
return $this;
202202
}

Definition/Builder/NodeBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ protected function getNodeClass(string $type): string
190190
$type = strtolower($type);
191191

192192
if (!isset($this->nodeMapping[$type])) {
193-
throw new \RuntimeException(sprintf('The node type "%s" is not registered.', $type));
193+
throw new \RuntimeException(\sprintf('The node type "%s" is not registered.', $type));
194194
}
195195

196196
$class = $this->nodeMapping[$type];
197197

198198
if (!class_exists($class)) {
199-
throw new \RuntimeException(sprintf('The node class "%s" does not exist.', $class));
199+
throw new \RuntimeException(\sprintf('The node class "%s" does not exist.', $class));
200200
}
201201

202202
return $class;

Definition/Builder/NumericNodeDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class NumericNodeDefinition extends ScalarNodeDefinition
3333
public function max(int|float $max): static
3434
{
3535
if (isset($this->min) && $this->min > $max) {
36-
throw new \InvalidArgumentException(sprintf('You cannot define a max(%s) as you already have a min(%s).', $max, $this->min));
36+
throw new \InvalidArgumentException(\sprintf('You cannot define a max(%s) as you already have a min(%s).', $max, $this->min));
3737
}
3838
$this->max = $max;
3939

@@ -50,7 +50,7 @@ public function max(int|float $max): static
5050
public function min(int|float $min): static
5151
{
5252
if (isset($this->max) && $this->max < $min) {
53-
throw new \InvalidArgumentException(sprintf('You cannot define a min(%s) as you already have a max(%s).', $min, $this->max));
53+
throw new \InvalidArgumentException(\sprintf('You cannot define a min(%s) as you already have a max(%s).', $min, $this->max));
5454
}
5555
$this->min = $min;
5656

0 commit comments

Comments
 (0)