Skip to content

Commit f3b43be

Browse files
committed
Prefix all sprintf() calls
1 parent dc7ff23 commit f3b43be

20 files changed

+55
-55
lines changed

AbstractUriElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939
$elementUriIsRelative = null === parse_url(trim($this->getRawUri()), \PHP_URL_SCHEME);
4040
$baseUriIsAbsolute = null !== $this->currentUri && \in_array(strtolower(substr($this->currentUri, 0, 4)), ['http', 'file']);
4141
if ($elementUriIsRelative && !$baseUriIsAbsolute) {
42-
throw new \InvalidArgumentException(sprintf('The URL of the element is relative, so you must define its base URI passing an absolute URL to the constructor of the "%s" class ("%s" was passed).', __CLASS__, $this->currentUri));
42+
throw new \InvalidArgumentException(\sprintf('The URL of the element is relative, so you must define its base URI passing an absolute URL to the constructor of the "%s" class ("%s" was passed).', __CLASS__, $this->currentUri));
4343
}
4444
}
4545

Crawler.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function add(\DOMNodeList|\DOMNode|array|string|null $node): void
118118
} elseif (\is_string($node)) {
119119
$this->addContent($node);
120120
} elseif (null !== $node) {
121-
throw new \InvalidArgumentException(sprintf('Expecting a DOMNodeList or DOMNode instance, an array, a string, or null, but got "%s".', get_debug_type($node)));
121+
throw new \InvalidArgumentException(\sprintf('Expecting a DOMNodeList or DOMNode instance, an array, a string, or null, but got "%s".', get_debug_type($node)));
122122
}
123123
}
124124

@@ -732,7 +732,7 @@ public function filter(string $selector): static
732732
public function selectLink(string $value): static
733733
{
734734
return $this->filterRelativeXPath(
735-
sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %1$s) or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %1$s)]]', static::xpathLiteral(' '.$value.' '))
735+
\sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %1$s) or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %1$s)]]', static::xpathLiteral(' '.$value.' '))
736736
);
737737
}
738738

@@ -741,7 +741,7 @@ public function selectLink(string $value): static
741741
*/
742742
public function selectImage(string $value): static
743743
{
744-
$xpath = sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', static::xpathLiteral($value));
744+
$xpath = \sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', static::xpathLiteral($value));
745745

746746
return $this->filterRelativeXPath($xpath);
747747
}
@@ -752,7 +752,7 @@ public function selectImage(string $value): static
752752
public function selectButton(string $value): static
753753
{
754754
return $this->filterRelativeXPath(
755-
sprintf('descendant-or-self::input[((contains(%1$s, "submit") or contains(%1$s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s)) or (contains(%1$s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %2$s)) or @id=%3$s or @name=%3$s] | descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %2$s) or @id=%3$s or @name=%3$s]', 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")', static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value))
755+
\sprintf('descendant-or-self::input[((contains(%1$s, "submit") or contains(%1$s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s)) or (contains(%1$s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %2$s)) or @id=%3$s or @name=%3$s] | descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %2$s) or @id=%3$s or @name=%3$s]', 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")', static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value))
756756
);
757757
}
758758

@@ -770,7 +770,7 @@ public function link(string $method = 'get'): Link
770770
$node = $this->getNode(0);
771771

772772
if (!$node instanceof \DOMElement) {
773-
throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
773+
throw new \InvalidArgumentException(\sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
774774
}
775775

776776
return new Link($node, $this->baseHref, $method);
@@ -788,7 +788,7 @@ public function links(): array
788788
$links = [];
789789
foreach ($this->nodes as $node) {
790790
if (!$node instanceof \DOMElement) {
791-
throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
791+
throw new \InvalidArgumentException(\sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
792792
}
793793

794794
$links[] = new Link($node, $this->baseHref, 'get');
@@ -811,7 +811,7 @@ public function image(): Image
811811
$node = $this->getNode(0);
812812

813813
if (!$node instanceof \DOMElement) {
814-
throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
814+
throw new \InvalidArgumentException(\sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
815815
}
816816

817817
return new Image($node, $this->baseHref);
@@ -827,7 +827,7 @@ public function images(): array
827827
$images = [];
828828
foreach ($this as $node) {
829829
if (!$node instanceof \DOMElement) {
830-
throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
830+
throw new \InvalidArgumentException(\sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
831831
}
832832

833833
$images[] = new Image($node, $this->baseHref);
@@ -850,7 +850,7 @@ public function form(?array $values = null, ?string $method = null): Form
850850
$node = $this->getNode(0);
851851

852852
if (!$node instanceof \DOMElement) {
853-
throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
853+
throw new \InvalidArgumentException(\sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
854854
}
855855

856856
$form = new Form($node, $this->uri, $method, $this->baseHref);
@@ -894,18 +894,18 @@ public function registerNamespace(string $prefix, string $namespace): void
894894
public static function xpathLiteral(string $s): string
895895
{
896896
if (!str_contains($s, "'")) {
897-
return sprintf("'%s'", $s);
897+
return \sprintf("'%s'", $s);
898898
}
899899

900900
if (!str_contains($s, '"')) {
901-
return sprintf('"%s"', $s);
901+
return \sprintf('"%s"', $s);
902902
}
903903

904904
$string = $s;
905905
$parts = [];
906906
while (true) {
907907
if (false !== $pos = strpos($string, "'")) {
908-
$parts[] = sprintf("'%s'", substr($string, 0, $pos));
908+
$parts[] = \sprintf("'%s'", substr($string, 0, $pos));
909909
$parts[] = "\"'\"";
910910
$string = substr($string, $pos + 1);
911911
} else {
@@ -914,7 +914,7 @@ public static function xpathLiteral(string $s): string
914914
}
915915
}
916916

917-
return sprintf('concat(%s)', implode(', ', $parts));
917+
return \sprintf('concat(%s)', implode(', ', $parts));
918918
}
919919

920920
/**
@@ -1154,7 +1154,7 @@ private function discoverNamespace(\DOMXPath $domxpath, string $prefix): ?string
11541154
}
11551155

11561156
// ask for one namespace, otherwise we'd get a collection with an item for each node
1157-
$namespaces = $domxpath->query(sprintf('(//namespace::*[name()="%s"])[last()]', $this->defaultNamespacePrefix === $prefix ? '' : $prefix));
1157+
$namespaces = $domxpath->query(\sprintf('(//namespace::*[name()="%s"])[last()]', $this->defaultNamespacePrefix === $prefix ? '' : $prefix));
11581158

11591159
return $this->cachedNamespaces[$prefix] = ($node = $namespaces->item(0)) ? $node->nodeValue : null;
11601160
}

Field/ChoiceFormField.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function select(string|array|bool $value): void
7474
public function tick(): void
7575
{
7676
if ('checkbox' !== $this->type) {
77-
throw new \LogicException(sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
77+
throw new \LogicException(\sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
7878
}
7979

8080
$this->setValue(true);
@@ -88,7 +88,7 @@ public function tick(): void
8888
public function untick(): void
8989
{
9090
if ('checkbox' !== $this->type) {
91-
throw new \LogicException(sprintf('You cannot untick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
91+
throw new \LogicException(\sprintf('You cannot untick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
9292
}
9393

9494
$this->setValue(false);
@@ -110,16 +110,16 @@ public function setValue(string|array|bool|null $value): void
110110
} else {
111111
if (\is_array($value)) {
112112
if (!$this->multiple) {
113-
throw new \InvalidArgumentException(sprintf('The value for "%s" cannot be an array.', $this->name));
113+
throw new \InvalidArgumentException(\sprintf('The value for "%s" cannot be an array.', $this->name));
114114
}
115115

116116
foreach ($value as $v) {
117117
if (!$this->containsOption($v, $this->options)) {
118-
throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $v, implode('", "', $this->availableOptionValues())));
118+
throw new \InvalidArgumentException(\sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $v, implode('", "', $this->availableOptionValues())));
119119
}
120120
}
121121
} elseif (!$this->containsOption($value, $this->options)) {
122-
throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $value, implode('", "', $this->availableOptionValues())));
122+
throw new \InvalidArgumentException(\sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $value, implode('", "', $this->availableOptionValues())));
123123
}
124124

125125
if ($this->multiple) {
@@ -144,7 +144,7 @@ public function setValue(string|array|bool|null $value): void
144144
public function addChoice(\DOMElement $node): void
145145
{
146146
if (!$this->multiple && 'radio' !== $this->type) {
147-
throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
147+
throw new \LogicException(\sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
148148
}
149149

150150
$option = $this->buildOptionValue($node);
@@ -179,11 +179,11 @@ public function isMultiple(): bool
179179
protected function initialize(): void
180180
{
181181
if ('input' !== $this->node->nodeName && 'select' !== $this->node->nodeName) {
182-
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $this->node->nodeName));
182+
throw new \LogicException(\sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $this->node->nodeName));
183183
}
184184

185185
if ('input' === $this->node->nodeName && 'checkbox' !== strtolower($this->node->getAttribute('type')) && 'radio' !== strtolower($this->node->getAttribute('type'))) {
186-
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is "%s").', $this->node->getAttribute('type')));
186+
throw new \LogicException(\sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is "%s").', $this->node->getAttribute('type')));
187187
}
188188

189189
$this->value = null;

Field/FileFormField.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function setErrorCode(int $error): void
2929
{
3030
$codes = [\UPLOAD_ERR_INI_SIZE, \UPLOAD_ERR_FORM_SIZE, \UPLOAD_ERR_PARTIAL, \UPLOAD_ERR_NO_FILE, \UPLOAD_ERR_NO_TMP_DIR, \UPLOAD_ERR_CANT_WRITE, \UPLOAD_ERR_EXTENSION];
3131
if (!\in_array($error, $codes)) {
32-
throw new \InvalidArgumentException(sprintf('The error code "%s" is not valid.', $error));
32+
throw new \InvalidArgumentException(\sprintf('The error code "%s" is not valid.', $error));
3333
}
3434

3535
$this->value = ['name' => '', 'type' => '', 'tmp_name' => '', 'error' => $error, 'size' => 0];
@@ -90,11 +90,11 @@ public function setFilePath(string $path): void
9090
protected function initialize(): void
9191
{
9292
if ('input' !== $this->node->nodeName) {
93-
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $this->node->nodeName));
93+
throw new \LogicException(\sprintf('A FileFormField can only be created from an input tag (%s given).', $this->node->nodeName));
9494
}
9595

9696
if ('file' !== strtolower($this->node->getAttribute('type'))) {
97-
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is "%s").', $this->node->getAttribute('type')));
97+
throw new \LogicException(\sprintf('A FileFormField can only be created from an input tag with a type of file (given type is "%s").', $this->node->getAttribute('type')));
9898
}
9999

100100
$this->setValue(null);

Field/FormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getLabel(): ?\DOMElement
4444
$xpath = new \DOMXPath($this->node->ownerDocument);
4545

4646
if ($this->node->hasAttribute('id')) {
47-
$labels = $xpath->query(sprintf('descendant::label[@for="%s"]', $this->node->getAttribute('id')));
47+
$labels = $xpath->query(\sprintf('descendant::label[@for="%s"]', $this->node->getAttribute('id')));
4848
if ($labels->length > 0) {
4949
return $labels->item(0);
5050
}

Field/InputFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class InputFormField extends FormField
2929
protected function initialize(): void
3030
{
3131
if ('input' !== $this->node->nodeName && 'button' !== $this->node->nodeName) {
32-
throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
32+
throw new \LogicException(\sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
3333
}
3434

3535
$type = strtolower($this->node->getAttribute('type'));

Field/TextareaFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TextareaFormField extends FormField
2626
protected function initialize(): void
2727
{
2828
if ('textarea' !== $this->node->nodeName) {
29-
throw new \LogicException(sprintf('A TextareaFormField can only be created from a textarea tag (%s given).', $this->node->nodeName));
29+
throw new \LogicException(\sprintf('A TextareaFormField can only be created from a textarea tag (%s given).', $this->node->nodeName));
3030
}
3131

3232
$this->value = '';

Form.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ protected function setNode(\DOMElement $node): void
362362
$formId = $node->getAttribute('form');
363363
$form = $node->ownerDocument->getElementById($formId);
364364
if (null === $form) {
365-
throw new \LogicException(sprintf('The selected node has an invalid form attribute (%s).', $formId));
365+
throw new \LogicException(\sprintf('The selected node has an invalid form attribute (%s).', $formId));
366366
}
367367
$this->node = $form;
368368

@@ -375,7 +375,7 @@ protected function setNode(\DOMElement $node): void
375375
}
376376
} while ('form' !== $node->nodeName);
377377
} elseif ('form' !== $node->nodeName) {
378-
throw new \LogicException(sprintf('Unable to submit on a "%s" tag.', $node->nodeName));
378+
throw new \LogicException(\sprintf('Unable to submit on a "%s" tag.', $node->nodeName));
379379
}
380380

381381
$this->node = $node;
@@ -420,7 +420,7 @@ private function initialize(): void
420420
// corresponding elements are either descendants or have a matching HTML5 form attribute
421421
$formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
422422

423-
$fieldNodes = $xpath->query(sprintf('( descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)] )[( not(ancestor::template) or ancestor::turbo-stream )]', $formId));
423+
$fieldNodes = $xpath->query(\sprintf('( descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)] )[( not(ancestor::template) or ancestor::turbo-stream )]', $formId));
424424
foreach ($fieldNodes as $node) {
425425
$this->addField($node);
426426
}

FormFieldRegistry.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function &get(string $name): FormField|array
7676
while ($segments) {
7777
$path = array_shift($segments);
7878
if (!\is_array($target) || !\array_key_exists($path, $target)) {
79-
throw new \InvalidArgumentException(sprintf('Unreachable field "%s".', $path));
79+
throw new \InvalidArgumentException(\sprintf('Unreachable field "%s".', $path));
8080
}
8181
$target = &$target[$path];
8282
}
@@ -116,7 +116,7 @@ public function set(string $name, mixed $value): void
116116
$this->set($k, $v);
117117
}
118118
} else {
119-
throw new \InvalidArgumentException(sprintf('Cannot set value on a compound field "%s".', $name));
119+
throw new \InvalidArgumentException(\sprintf('Cannot set value on a compound field "%s".', $name));
120120
}
121121
}
122122

@@ -136,7 +136,7 @@ public function all(): array
136136
private function walk(array $array, ?string $base = '', array &$output = []): array
137137
{
138138
foreach ($array as $k => $v) {
139-
$path = $base ? sprintf('%s[%s]', $base, $k) : $k;
139+
$path = $base ? \sprintf('%s[%s]', $base, $k) : $k;
140140
if (\is_array($v)) {
141141
$this->walk($v, $path, $output);
142142
} else {

Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function getRawUri(): string
2929
protected function setNode(\DOMElement $node): void
3030
{
3131
if ('img' !== $node->nodeName) {
32-
throw new \LogicException(sprintf('Unable to visualize a "%s" tag.', $node->nodeName));
32+
throw new \LogicException(\sprintf('Unable to visualize a "%s" tag.', $node->nodeName));
3333
}
3434

3535
$this->node = $node;

0 commit comments

Comments
 (0)