$this->addNodeList($node);
} elseif ($node instanceof \DOMNode) {
$this->addNode($node);
- } elseif (is_array($node)) {
+ } elseif (\is_array($node)) {
$this->addNodes($node);
- } elseif (is_string($node)) {
+ } elseif (\is_string($node)) {
$this->addContent($node);
} elseif (null !== $node) {
- throw new \InvalidArgumentException(sprintf('Expecting a DOMNodeList or DOMNode instance, an array, a string, or null, but got "%s".', is_object($node) ? get_class($node) : gettype($node)));
+ throw new \InvalidArgumentException(sprintf('Expecting a DOMNodeList or DOMNode instance, an array, a string, or null, but got "%s".', \is_object($node) ? \get_class($node) : \gettype($node)));
}
}
* HTTP 1.1 specification.
*
* @param string $content A string to parse as HTML/XML
- * @param null|string $type The content type of the string
+ * @param string|null $type The content type of the string
*/
public function addContent($content, $type = null)
{
$base = $this->filterRelativeXPath('descendant-or-self::base')->extract(array('href'));
$baseHref = current($base);
- if (count($base) && !empty($baseHref)) {
+ if (\count($base) && !empty($baseHref)) {
if ($this->baseHref) {
$linkNode = $dom->createElement('a');
$linkNode->setAttribute('href', $baseHref);
}
// Don't add duplicate nodes in the Crawler
- if (in_array($node, $this->nodes, true)) {
+ if (\in_array($node, $this->nodes, true)) {
return;
}
*/
public function slice($offset = 0, $length = null)
{
- return $this->createSubCrawler(array_slice($this->nodes, $offset, $length));
+ return $this->createSubCrawler(\array_slice($this->nodes, $offset, $length));
}
/**
*/
public function last()
{
- return $this->eq(count($this->nodes) - 1);
+ return $this->eq(\count($this->nodes) - 1);
}
/**
*
* Example:
*
- * $crawler->filter('h1 a')->extract(array('_text', 'href'));
+ * $crawler->filter('h1 a')->extract(array('_text', 'href'));
*
* @param array $attributes An array of attributes
*
public function extract($attributes)
{
$attributes = (array) $attributes;
- $count = count($attributes);
+ $count = \count($attributes);
$data = array();
foreach ($this->nodes as $node) {
}
}
- $data[] = $count > 1 ? $elements : $elements[0];
+ $data[] = 1 === $count ? $elements[0] : $elements;
}
return $data;
$node = $this->getNode(0);
if (!$node instanceof \DOMElement) {
- throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_class($node)));
+ throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', \get_class($node)));
}
return new Link($node, $this->baseHref, $method);
$links = array();
foreach ($this->nodes as $node) {
if (!$node instanceof \DOMElement) {
- throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_class($node)));
+ throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', \get_class($node)));
}
$links[] = new Link($node, $this->baseHref, 'get');
*/
public function image()
{
- if (!count($this)) {
+ if (!\count($this)) {
throw new \InvalidArgumentException('The current node list is empty.');
}
$node = $this->getNode(0);
if (!$node instanceof \DOMElement) {
- throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_class($node)));
+ throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', \get_class($node)));
}
return new Image($node, $this->baseHref);
$images = array();
foreach ($this as $node) {
if (!$node instanceof \DOMElement) {
- throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_class($node)));
+ throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', \get_class($node)));
}
$images[] = new Image($node, $this->baseHref);
$node = $this->getNode(0);
if (!$node instanceof \DOMElement) {
- throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_class($node)));
+ throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', \get_class($node)));
}
$form = new Form($node, $this->uri, $method, $this->baseHref);
* Escaped characters are: quotes (") and apostrophe (').
*
* Examples:
- * <code>
+ *
* echo Crawler::xpathLiteral('foo " bar');
* //prints 'foo " bar'
*
*
* echo Crawler::xpathLiteral('a\'b"c');
* //prints concat('a', "'", 'b"c')
- * </code>
+ *
*
* @param string $s String to be escaped
*
// We cannot simply drop
$nonMatchingExpression = 'a[name() = "b"]';
- $xpathLen = strlen($xpath);
+ $xpathLen = \strlen($xpath);
$openedBrackets = 0;
$startPosition = strspn($xpath, " \t\n\r\0\x0B");
*/
public function count()
{
- return count($this->nodes);
+ return \count($this->nodes);
}
/**