Skip to content

Commit 628cded

Browse files
Merge branch '4.4' into 5.2
* 4.4: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents 8ea7fd8 + 15174d8 commit 628cded

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
@@ -145,7 +145,7 @@ public function add($node)
145145
public function addContent(string $content, string $type = null)
146146
{
147147
if (empty($type)) {
148-
$type = 0 === strpos($content, '<?xml') ? 'application/xml' : 'text/html';
148+
$type = str_starts_with($content, '<?xml') ? 'application/xml' : 'text/html';
149149
}
150150

151151
// DOM only for HTML/XML content
@@ -943,11 +943,11 @@ public function registerNamespace(string $prefix, string $namespace)
943943
*/
944944
public static function xpathLiteral(string $s)
945945
{
946-
if (false === strpos($s, "'")) {
946+
if (!str_contains($s, "'")) {
947947
return sprintf("'%s'", $s);
948948
}
949949

950-
if (false === strpos($s, '"')) {
950+
if (!str_contains($s, '"')) {
951951
return sprintf('"%s"', $s);
952952
}
953953

@@ -1040,29 +1040,29 @@ private function relativize(string $xpath): string
10401040
}
10411041
$expression = rtrim(substr($xpath, $startPosition, $i - $startPosition));
10421042

1043-
if (0 === strpos($expression, 'self::*/')) {
1043+
if (str_starts_with($expression, 'self::*/')) {
10441044
$expression = './'.substr($expression, 8);
10451045
}
10461046

10471047
// add prefix before absolute element selector
10481048
if ('' === $expression) {
10491049
$expression = $nonMatchingExpression;
1050-
} elseif (0 === strpos($expression, '//')) {
1050+
} elseif (str_starts_with($expression, '//')) {
10511051
$expression = 'descendant-or-self::'.substr($expression, 2);
1052-
} elseif (0 === strpos($expression, './/')) {
1052+
} elseif (str_starts_with($expression, './/')) {
10531053
$expression = 'descendant-or-self::'.substr($expression, 3);
1054-
} elseif (0 === strpos($expression, './')) {
1054+
} elseif (str_starts_with($expression, './')) {
10551055
$expression = 'self::'.substr($expression, 2);
1056-
} elseif (0 === strpos($expression, 'child::')) {
1056+
} elseif (str_starts_with($expression, 'child::')) {
10571057
$expression = 'self::'.substr($expression, 7);
1058-
} elseif ('/' === $expression[0] || '.' === $expression[0] || 0 === strpos($expression, 'self::')) {
1058+
} elseif ('/' === $expression[0] || '.' === $expression[0] || str_starts_with($expression, 'self::')) {
10591059
$expression = $nonMatchingExpression;
1060-
} elseif (0 === strpos($expression, 'descendant::')) {
1060+
} elseif (str_starts_with($expression, 'descendant::')) {
10611061
$expression = 'descendant-or-self::'.substr($expression, 12);
10621062
} elseif (preg_match('/^(ancestor|ancestor-or-self|attribute|following|following-sibling|namespace|parent|preceding|preceding-sibling)::/', $expression)) {
10631063
// the fake root has no parent, preceding or following nodes and also no attributes (even no namespace attributes)
10641064
$expression = $nonMatchingExpression;
1065-
} elseif (0 !== strpos($expression, 'descendant-or-self::')) {
1065+
} elseif (!str_starts_with($expression, 'descendant-or-self::')) {
10661066
$expression = 'self::'.$expression;
10671067
}
10681068
$expressions[] = $parenthesis.$expression;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=7.2.5",
2020
"symfony/polyfill-ctype": "~1.8",
2121
"symfony/polyfill-mbstring": "~1.0",
22-
"symfony/polyfill-php80": "^1.15"
22+
"symfony/polyfill-php80": "^1.16"
2323
},
2424
"require-dev": {
2525
"symfony/css-selector": "^4.4|^5.0",

0 commit comments

Comments
 (0)