Skip to content

Commit 316ad33

Browse files
Merge branch '5.2' into 5.3
* 5.2: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents 2b617da + 628cded commit 316ad33

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

AbstractUriElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function canonicalizePath(string $path)
103103
return $path;
104104
}
105105

106-
if ('.' === substr($path, -1)) {
106+
if (str_ends_with($path, '.')) {
107107
$path .= '/';
108108
}
109109

Crawler.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function add($node)
152152
public function addContent(string $content, string $type = null)
153153
{
154154
if (empty($type)) {
155-
$type = 0 === strpos($content, '<?xml') ? 'application/xml' : 'text/html';
155+
$type = str_starts_with($content, '<?xml') ? 'application/xml' : 'text/html';
156156
}
157157

158158
// DOM only for HTML/XML content
@@ -964,11 +964,11 @@ public function registerNamespace(string $prefix, string $namespace)
964964
*/
965965
public static function xpathLiteral(string $s)
966966
{
967-
if (false === strpos($s, "'")) {
967+
if (!str_contains($s, "'")) {
968968
return sprintf("'%s'", $s);
969969
}
970970

971-
if (false === strpos($s, '"')) {
971+
if (!str_contains($s, '"')) {
972972
return sprintf('"%s"', $s);
973973
}
974974

@@ -1063,29 +1063,29 @@ private function relativize(string $xpath): string
10631063
}
10641064
$expression = rtrim(substr($xpath, $startPosition, $i - $startPosition));
10651065

1066-
if (0 === strpos($expression, 'self::*/')) {
1066+
if (str_starts_with($expression, 'self::*/')) {
10671067
$expression = './'.substr($expression, 8);
10681068
}
10691069

10701070
// add prefix before absolute element selector
10711071
if ('' === $expression) {
10721072
$expression = $nonMatchingExpression;
1073-
} elseif (0 === strpos($expression, '//')) {
1073+
} elseif (str_starts_with($expression, '//')) {
10741074
$expression = 'descendant-or-self::'.substr($expression, 2);
1075-
} elseif (0 === strpos($expression, './/')) {
1075+
} elseif (str_starts_with($expression, './/')) {
10761076
$expression = 'descendant-or-self::'.substr($expression, 3);
1077-
} elseif (0 === strpos($expression, './')) {
1077+
} elseif (str_starts_with($expression, './')) {
10781078
$expression = 'self::'.substr($expression, 2);
1079-
} elseif (0 === strpos($expression, 'child::')) {
1079+
} elseif (str_starts_with($expression, 'child::')) {
10801080
$expression = 'self::'.substr($expression, 7);
1081-
} elseif ('/' === $expression[0] || '.' === $expression[0] || 0 === strpos($expression, 'self::')) {
1081+
} elseif ('/' === $expression[0] || '.' === $expression[0] || str_starts_with($expression, 'self::')) {
10821082
$expression = $nonMatchingExpression;
1083-
} elseif (0 === strpos($expression, 'descendant::')) {
1083+
} elseif (str_starts_with($expression, 'descendant::')) {
10841084
$expression = 'descendant-or-self::'.substr($expression, 12);
10851085
} elseif (preg_match('/^(ancestor|ancestor-or-self|attribute|following|following-sibling|namespace|parent|preceding|preceding-sibling)::/', $expression)) {
10861086
// the fake root has no parent, preceding or following nodes and also no attributes (even no namespace attributes)
10871087
$expression = $nonMatchingExpression;
1088-
} elseif (0 !== strpos($expression, 'descendant-or-self::')) {
1088+
} elseif (!str_starts_with($expression, 'descendant-or-self::')) {
10891089
$expression = 'self::'.$expression;
10901090
}
10911091
$expressions[] = $parenthesis.$expression;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/deprecation-contracts": "^2.1",
2121
"symfony/polyfill-ctype": "~1.8",
2222
"symfony/polyfill-mbstring": "~1.0",
23-
"symfony/polyfill-php80": "^1.15"
23+
"symfony/polyfill-php80": "^1.16"
2424
},
2525
"require-dev": {
2626
"symfony/css-selector": "^4.4|^5.0",

0 commit comments

Comments
 (0)