Skip to content

Commit 6838e7c

Browse files
Merge branch '5.4' into 6.0
* 5.4: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents ea5b04f + 200cd8b commit 6838e7c

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
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
@@ -136,7 +136,7 @@ public function add(\DOMNodeList|\DOMNode|array|string|null $node)
136136
public function addContent(string $content, string $type = null)
137137
{
138138
if (empty($type)) {
139-
$type = 0 === strpos($content, '<?xml') ? 'application/xml' : 'text/html';
139+
$type = str_starts_with($content, '<?xml') ? 'application/xml' : 'text/html';
140140
}
141141

142142
// DOM only for HTML/XML content
@@ -928,11 +928,11 @@ public function registerNamespace(string $prefix, string $namespace)
928928
*/
929929
public static function xpathLiteral(string $s)
930930
{
931-
if (false === strpos($s, "'")) {
931+
if (!str_contains($s, "'")) {
932932
return sprintf("'%s'", $s);
933933
}
934934

935-
if (false === strpos($s, '"')) {
935+
if (!str_contains($s, '"')) {
936936
return sprintf('"%s"', $s);
937937
}
938938

@@ -1027,29 +1027,29 @@ private function relativize(string $xpath): string
10271027
}
10281028
$expression = rtrim(substr($xpath, $startPosition, $i - $startPosition));
10291029

1030-
if (0 === strpos($expression, 'self::*/')) {
1030+
if (str_starts_with($expression, 'self::*/')) {
10311031
$expression = './'.substr($expression, 8);
10321032
}
10331033

10341034
// add prefix before absolute element selector
10351035
if ('' === $expression) {
10361036
$expression = $nonMatchingExpression;
1037-
} elseif (0 === strpos($expression, '//')) {
1037+
} elseif (str_starts_with($expression, '//')) {
10381038
$expression = 'descendant-or-self::'.substr($expression, 2);
1039-
} elseif (0 === strpos($expression, './/')) {
1039+
} elseif (str_starts_with($expression, './/')) {
10401040
$expression = 'descendant-or-self::'.substr($expression, 3);
1041-
} elseif (0 === strpos($expression, './')) {
1041+
} elseif (str_starts_with($expression, './')) {
10421042
$expression = 'self::'.substr($expression, 2);
1043-
} elseif (0 === strpos($expression, 'child::')) {
1043+
} elseif (str_starts_with($expression, 'child::')) {
10441044
$expression = 'self::'.substr($expression, 7);
1045-
} elseif ('/' === $expression[0] || '.' === $expression[0] || 0 === strpos($expression, 'self::')) {
1045+
} elseif ('/' === $expression[0] || '.' === $expression[0] || str_starts_with($expression, 'self::')) {
10461046
$expression = $nonMatchingExpression;
1047-
} elseif (0 === strpos($expression, 'descendant::')) {
1047+
} elseif (str_starts_with($expression, 'descendant::')) {
10481048
$expression = 'descendant-or-self::'.substr($expression, 12);
10491049
} elseif (preg_match('/^(ancestor|ancestor-or-self|attribute|following|following-sibling|namespace|parent|preceding|preceding-sibling)::/', $expression)) {
10501050
// the fake root has no parent, preceding or following nodes and also no attributes (even no namespace attributes)
10511051
$expression = $nonMatchingExpression;
1052-
} elseif (0 !== strpos($expression, 'descendant-or-self::')) {
1052+
} elseif (!str_starts_with($expression, 'descendant-or-self::')) {
10531053
$expression = 'self::'.$expression;
10541054
}
10551055
$expressions[] = $parenthesis.$expression;

0 commit comments

Comments
 (0)