minor #26485 [DomCrawler] Improve the sprintf() call in selectLink() (dunglas)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[DomCrawler] Improve the sprintf() call in selectLink()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  |no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? |no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | n/a

Code cleanup and minor performance improvement.

Commits
-------

e2ab1a47d2 [DomCrawler] Improve the sprintf() call in selectLink()
This commit is contained in:
Fabien Potencier 2018-03-11 13:17:53 -05:00
commit b486fdaffd

View File

@ -710,10 +710,9 @@ class Crawler implements \Countable, \IteratorAggregate
*/
public function selectLink($value)
{
$xpath = sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %s) ', static::xpathLiteral(' '.$value.' ')).
sprintf('or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %s)]]', static::xpathLiteral(' '.$value.' '));
return $this->filterRelativeXPath($xpath);
return $this->filterRelativeXPath(
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.' '))
);
}
/**