tagName) !== 'label') { return null; } if ($element->hasAttribute('for')) { $forId = trim($element->getAttribute('for')); if ($forId === '') { return $this->createViolation( $element, $this->getDescription(), 'Provide a valid element ID in the for attribute.' ); } $doc = $element->ownerDocument; if ($doc !== null) { $xpath = new \DOMXPath($doc); $elements = $xpath->query('//*[@id="' . $forId . '"]'); if ($elements === false || $elements->length === 0) { return $this->createViolation( $element, $this->getDescription(), "Ensure the 'for' attribute value (\"$forId\") matches the ID of a form input element." ); } } } return null; } }