Skip to content

Commit 202a37e

Browse files
CS fixes
1 parent 22210aa commit 202a37e

21 files changed

+67
-67
lines changed

AbstractUriElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(\DOMElement $node, ?string $currentUri = null, ?stri
4949
$elementUriIsRelative = !parse_url(trim($this->getRawUri()), \PHP_URL_SCHEME);
5050
$baseUriIsAbsolute = null !== $this->currentUri && \in_array(strtolower(substr($this->currentUri, 0, 4)), ['http', 'file']);
5151
if ($elementUriIsRelative && !$baseUriIsAbsolute) {
52-
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));
52+
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));
5353
}
5454
}
5555

Crawler.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function add(\DOMNodeList|\DOMNode|array|string|null $node)
124124
} elseif (\is_string($node)) {
125125
$this->addContent($node);
126126
} elseif (null !== $node) {
127-
throw new \InvalidArgumentException(sprintf('Expecting a DOMNodeList or DOMNode instance, an array, a string, or null, but got "%s".', get_debug_type($node)));
127+
throw new \InvalidArgumentException(\sprintf('Expecting a DOMNodeList or DOMNode instance, an array, a string, or null, but got "%s".', get_debug_type($node)));
128128
}
129129
}
130130

@@ -755,7 +755,7 @@ public function filter(string $selector): static
755755
public function selectLink(string $value): static
756756
{
757757
return $this->filterRelativeXPath(
758-
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.' '))
758+
\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.' '))
759759
);
760760
}
761761

@@ -764,7 +764,7 @@ public function selectLink(string $value): static
764764
*/
765765
public function selectImage(string $value): static
766766
{
767-
$xpath = sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', static::xpathLiteral($value));
767+
$xpath = \sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', static::xpathLiteral($value));
768768

769769
return $this->filterRelativeXPath($xpath);
770770
}
@@ -775,7 +775,7 @@ public function selectImage(string $value): static
775775
public function selectButton(string $value): static
776776
{
777777
return $this->filterRelativeXPath(
778-
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 contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s) or @id=%3$s or @name=%3$s]', 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")', static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value))
778+
\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 contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s) or @id=%3$s or @name=%3$s]', 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")', static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value))
779779
);
780780
}
781781

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

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

799799
return new Link($node, $this->baseHref, $method);
@@ -811,7 +811,7 @@ public function links(): array
811811
$links = [];
812812
foreach ($this->nodes as $node) {
813813
if (!$node instanceof \DOMElement) {
814-
throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
814+
throw new \InvalidArgumentException(\sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
815815
}
816816

817817
$links[] = new Link($node, $this->baseHref, 'get');
@@ -834,7 +834,7 @@ public function image(): Image
834834
$node = $this->getNode(0);
835835

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

840840
return new Image($node, $this->baseHref);
@@ -850,7 +850,7 @@ public function images(): array
850850
$images = [];
851851
foreach ($this as $node) {
852852
if (!$node instanceof \DOMElement) {
853-
throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
853+
throw new \InvalidArgumentException(\sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
854854
}
855855

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

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

879879
$form = new Form($node, $this->uri, $method, $this->baseHref);
@@ -922,18 +922,18 @@ public function registerNamespace(string $prefix, string $namespace)
922922
public static function xpathLiteral(string $s): string
923923
{
924924
if (!str_contains($s, "'")) {
925-
return sprintf("'%s'", $s);
925+
return \sprintf("'%s'", $s);
926926
}
927927

928928
if (!str_contains($s, '"')) {
929-
return sprintf('"%s"', $s);
929+
return \sprintf('"%s"', $s);
930930
}
931931

932932
$string = $s;
933933
$parts = [];
934934
while (true) {
935935
if (false !== $pos = strpos($string, "'")) {
936-
$parts[] = sprintf("'%s'", substr($string, 0, $pos));
936+
$parts[] = \sprintf("'%s'", substr($string, 0, $pos));
937937
$parts[] = "\"'\"";
938938
$string = substr($string, $pos + 1);
939939
} else {
@@ -942,7 +942,7 @@ public static function xpathLiteral(string $s): string
942942
}
943943
}
944944

945-
return sprintf('concat(%s)', implode(', ', $parts));
945+
return \sprintf('concat(%s)', implode(', ', $parts));
946946
}
947947

948948
/**
@@ -1182,7 +1182,7 @@ private function discoverNamespace(\DOMXPath $domxpath, string $prefix): ?string
11821182
}
11831183

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

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

Field/ChoiceFormField.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function select(string|array|bool $value)
8282
public function tick()
8383
{
8484
if ('checkbox' !== $this->type) {
85-
throw new \LogicException(sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
85+
throw new \LogicException(\sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
8686
}
8787

8888
$this->setValue(true);
@@ -98,7 +98,7 @@ public function tick()
9898
public function untick()
9999
{
100100
if ('checkbox' !== $this->type) {
101-
throw new \LogicException(sprintf('You cannot untick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
101+
throw new \LogicException(\sprintf('You cannot untick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
102102
}
103103

104104
$this->setValue(false);
@@ -122,16 +122,16 @@ public function setValue(string|array|bool|null $value)
122122
} else {
123123
if (\is_array($value)) {
124124
if (!$this->multiple) {
125-
throw new \InvalidArgumentException(sprintf('The value for "%s" cannot be an array.', $this->name));
125+
throw new \InvalidArgumentException(\sprintf('The value for "%s" cannot be an array.', $this->name));
126126
}
127127

128128
foreach ($value as $v) {
129129
if (!$this->containsOption($v, $this->options)) {
130-
throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $v, implode('", "', $this->availableOptionValues())));
130+
throw new \InvalidArgumentException(\sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $v, implode('", "', $this->availableOptionValues())));
131131
}
132132
}
133133
} elseif (!$this->containsOption($value, $this->options)) {
134-
throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $value, implode('", "', $this->availableOptionValues())));
134+
throw new \InvalidArgumentException(\sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $value, implode('", "', $this->availableOptionValues())));
135135
}
136136

137137
if ($this->multiple) {
@@ -156,7 +156,7 @@ public function setValue(string|array|bool|null $value)
156156
public function addChoice(\DOMElement $node): void
157157
{
158158
if (!$this->multiple && 'radio' !== $this->type) {
159-
throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
159+
throw new \LogicException(\sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
160160
}
161161

162162
$option = $this->buildOptionValue($node);
@@ -193,11 +193,11 @@ public function isMultiple(): bool
193193
protected function initialize()
194194
{
195195
if ('input' !== $this->node->nodeName && 'select' !== $this->node->nodeName) {
196-
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $this->node->nodeName));
196+
throw new \LogicException(\sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $this->node->nodeName));
197197
}
198198

199199
if ('input' === $this->node->nodeName && 'checkbox' !== strtolower($this->node->getAttribute('type')) && 'radio' !== strtolower($this->node->getAttribute('type'))) {
200-
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')));
200+
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')));
201201
}
202202

203203
$this->value = null;

Field/FileFormField.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function setErrorCode(int $error)
3131
{
3232
$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];
3333
if (!\in_array($error, $codes)) {
34-
throw new \InvalidArgumentException(sprintf('The error code "%s" is not valid.', $error));
34+
throw new \InvalidArgumentException(\sprintf('The error code "%s" is not valid.', $error));
3535
}
3636

3737
$this->value = ['name' => '', 'type' => '', 'tmp_name' => '', 'error' => $error, 'size' => 0];
@@ -100,11 +100,11 @@ public function setFilePath(string $path)
100100
protected function initialize()
101101
{
102102
if ('input' !== $this->node->nodeName) {
103-
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $this->node->nodeName));
103+
throw new \LogicException(\sprintf('A FileFormField can only be created from an input tag (%s given).', $this->node->nodeName));
104104
}
105105

106106
if ('file' !== strtolower($this->node->getAttribute('type'))) {
107-
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')));
107+
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')));
108108
}
109109

110110
$this->setValue(null);

Field/FormField.php

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

6565
if ($this->node->hasAttribute('id')) {
66-
$labels = $xpath->query(sprintf('descendant::label[@for="%s"]', $this->node->getAttribute('id')));
66+
$labels = $xpath->query(\sprintf('descendant::label[@for="%s"]', $this->node->getAttribute('id')));
6767
if ($labels->length > 0) {
6868
return $labels->item(0);
6969
}

Field/InputFormField.php

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

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

Field/TextareaFormField.php

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

3434
$this->value = '';

Form.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function offsetUnset(mixed $name): void
339339
public function disableValidation(): static
340340
{
341341
foreach ($this->fields->all() as $field) {
342-
if ($field instanceof Field\ChoiceFormField) {
342+
if ($field instanceof ChoiceFormField) {
343343
$field->disableValidation();
344344
}
345345
}
@@ -365,7 +365,7 @@ protected function setNode(\DOMElement $node)
365365
$formId = $node->getAttribute('form');
366366
$form = $node->ownerDocument->getElementById($formId);
367367
if (null === $form) {
368-
throw new \LogicException(sprintf('The selected node has an invalid form attribute (%s).', $formId));
368+
throw new \LogicException(\sprintf('The selected node has an invalid form attribute (%s).', $formId));
369369
}
370370
$this->node = $form;
371371

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

384384
$this->node = $node;
@@ -423,7 +423,7 @@ private function initialize(): void
423423
// corresponding elements are either descendants or have a matching HTML5 form attribute
424424
$formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
425425

426-
$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));
426+
$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));
427427
foreach ($fieldNodes as $node) {
428428
$this->addField($node);
429429
}
@@ -449,14 +449,14 @@ private function addField(\DOMElement $node): void
449449

450450
$nodeName = $node->nodeName;
451451
if ('select' == $nodeName || 'input' == $nodeName && 'checkbox' == strtolower($node->getAttribute('type'))) {
452-
$this->set(new Field\ChoiceFormField($node));
452+
$this->set(new ChoiceFormField($node));
453453
} elseif ('input' == $nodeName && 'radio' == strtolower($node->getAttribute('type'))) {
454454
// there may be other fields with the same name that are no choice
455455
// fields already registered (see https://github.com/symfony/symfony/issues/11689)
456456
if ($this->has($node->getAttribute('name')) && $this->get($node->getAttribute('name')) instanceof ChoiceFormField) {
457457
$this->get($node->getAttribute('name'))->addChoice($node);
458458
} else {
459-
$this->set(new Field\ChoiceFormField($node));
459+
$this->set(new ChoiceFormField($node));
460460
}
461461
} elseif ('input' == $nodeName && 'file' == strtolower($node->getAttribute('type'))) {
462462
$this->set(new Field\FileFormField($node));

0 commit comments

Comments
 (0)