Skip to content

Commit 309046a

Browse files
committed
minor #10928 [DomCrawler] Fixed the coding standards to use strict comparisons (stof)
This PR was merged into the 2.3 branch. Discussion ---------- [DomCrawler] Fixed the coding standards to use strict comparisons | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Many places in DomCrawler are using loose comparison instead of strict comparison. I saw them while checking the whole component for DOMNode vs DOMElement usage whe working on #10927. However, I submitted this change to 2.3 instead, to ease merging between branches (applying the change only in master would likely create conflicts regularly when merging changes in DomCrawler between branches later) Commits ------- 77b446c [DomCrawler] Fixed the coding standards to use strict comparisons
2 parents 8c71454 + 77b446c commit 309046a

File tree

8 files changed

+19
-21
lines changed

8 files changed

+19
-21
lines changed

src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ public function untick()
119119
*/
120120
public function setValue($value)
121121
{
122-
if ('checkbox' == $this->type && false === $value) {
122+
if ('checkbox' === $this->type && false === $value) {
123123
// uncheck
124124
$this->value = null;
125-
} elseif ('checkbox' == $this->type && true === $value) {
125+
} elseif ('checkbox' === $this->type && true === $value) {
126126
// check
127127
$this->value = $this->options[0]['value'];
128128
} else {
@@ -163,7 +163,7 @@ public function setValue($value)
163163
*/
164164
public function addChoice(\DOMNode $node)
165165
{
166-
if (!$this->multiple && 'radio' != $this->type) {
166+
if (!$this->multiple && 'radio' !== $this->type) {
167167
throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
168168
}
169169

@@ -202,11 +202,11 @@ public function isMultiple()
202202
*/
203203
protected function initialize()
204204
{
205-
if ('input' != $this->node->nodeName && 'select' != $this->node->nodeName) {
205+
if ('input' !== $this->node->nodeName && 'select' !== $this->node->nodeName) {
206206
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $this->node->nodeName));
207207
}
208208

209-
if ('input' == $this->node->nodeName && 'checkbox' != strtolower($this->node->getAttribute('type')) && 'radio' != strtolower($this->node->getAttribute('type'))) {
209+
if ('input' === $this->node->nodeName && 'checkbox' !== strtolower($this->node->getAttribute('type')) && 'radio' !== strtolower($this->node->getAttribute('type'))) {
210210
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')));
211211
}
212212

@@ -271,7 +271,7 @@ private function buildOptionValue($node)
271271
}
272272

273273
/**
274-
* Checks whether given vale is in the existing options
274+
* Checks whether given value is in the existing options
275275
*
276276
* @param string $optionValue
277277
* @param array $options

src/Symfony/Component/DomCrawler/Field/FileFormField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ public function setFilePath($path)
9999
*/
100100
protected function initialize()
101101
{
102-
if ('input' != $this->node->nodeName) {
102+
if ('input' !== $this->node->nodeName) {
103103
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $this->node->nodeName));
104104
}
105105

106-
if ('file' != strtolower($this->node->getAttribute('type'))) {
106+
if ('file' !== strtolower($this->node->getAttribute('type'))) {
107107
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

src/Symfony/Component/DomCrawler/Field/InputFormField.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class InputFormField extends FormField
3030
*/
3131
protected function initialize()
3232
{
33-
if ('input' != $this->node->nodeName && 'button' != $this->node->nodeName) {
33+
if ('input' !== $this->node->nodeName && 'button' !== $this->node->nodeName) {
3434
throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
3535
}
3636

37-
if ('checkbox' == strtolower($this->node->getAttribute('type'))) {
37+
if ('checkbox' === strtolower($this->node->getAttribute('type'))) {
3838
throw new \LogicException('Checkboxes should be instances of ChoiceFormField.');
3939
}
4040

41-
if ('file' == strtolower($this->node->getAttribute('type'))) {
41+
if ('file' === strtolower($this->node->getAttribute('type'))) {
4242
throw new \LogicException('File inputs should be instances of FileFormField.');
4343
}
4444

src/Symfony/Component/DomCrawler/Field/TextareaFormField.php

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

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Form extends Link implements \ArrayAccess
2828
private $button;
2929

3030
/**
31-
* @var Field\FormField[]
31+
* @var FormFieldRegistry
3232
*/
3333
private $fields;
3434

@@ -352,7 +352,7 @@ public function offsetUnset($name)
352352
protected function setNode(\DOMNode $node)
353353
{
354354
$this->button = $node;
355-
if ('button' == $node->nodeName || ('input' == $node->nodeName && in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image')))) {
355+
if ('button' === $node->nodeName || ('input' === $node->nodeName && in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image')))) {
356356
if ($node->hasAttribute('form')) {
357357
// if the node has the HTML5-compliant 'form' attribute, use it
358358
$formId = $node->getAttribute('form');
@@ -369,8 +369,8 @@ protected function setNode(\DOMNode $node)
369369
if (null === $node = $node->parentNode) {
370370
throw new \LogicException('The selected node does not have a form ancestor.');
371371
}
372-
} while ('form' != $node->nodeName);
373-
} elseif ('form' != $node->nodeName) {
372+
} while ('form' !== $node->nodeName);
373+
} elseif ('form' !== $node->nodeName) {
374374
throw new \LogicException(sprintf('Unable to submit on a "%s" tag.', $node->nodeName));
375375
}
376376

src/Symfony/Component/DomCrawler/FormFieldRegistry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function set($name, $value)
137137
/**
138138
* Returns the list of field with their value.
139139
*
140-
* @return array The list of fields as array((string) Fully qualified name => (mixed) value)
140+
* @return FormField[] The list of fields as array((string) Fully qualified name => (mixed) value)
141141
*/
142142
public function all()
143143
{
@@ -196,7 +196,7 @@ private function walk(array $array, $base = '', array &$output = array())
196196
*
197197
* @param string $name The name of the field
198198
*
199-
* @return array The list of segments
199+
* @return string[] The list of segments
200200
*
201201
* @throws \InvalidArgumentException when the name is malformed
202202
*/

src/Symfony/Component/DomCrawler/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ protected function canonicalizePath($path)
188188
*/
189189
protected function setNode(\DOMNode $node)
190190
{
191-
if ('a' != $node->nodeName && 'area' != $node->nodeName) {
191+
if ('a' !== $node->nodeName && 'area' !== $node->nodeName) {
192192
throw new \LogicException(sprintf('Unable to click on a "%s" tag.', $node->nodeName));
193193
}
194194

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,6 @@ protected function createForm($form, $method = null, $currentUri = null)
793793
$dom = new \DOMDocument();
794794
$dom->loadHTML('<html>'.$form.'</html>');
795795

796-
$nodes = $dom->getElementsByTagName('input');
797796
$xPath = new \DOMXPath($dom);
798797
$nodes = $xPath->query('//input | //button');
799798

@@ -856,5 +855,4 @@ public function testgetPhpValuesWithEmptyTextarea()
856855
$form = new Form($nodes->item(0), 'http://example.com');
857856
$this->assertEquals($form->getPhpValues(), array('example' => ''));
858857
}
859-
860858
}

0 commit comments

Comments
 (0)