Skip to content

Commit 15174d8

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent c803dc9 commit 15174d8

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
@@ -104,7 +104,7 @@ public function getUri()
104104
}
105105

106106
// absolute URL with relative schema
107-
if (0 === strpos($uri, '//')) {
107+
if (str_starts_with($uri, '//')) {
108108
return preg_replace('#^([^/]*)//.*$#', '$1', $baseUri).$uri;
109109
}
110110

Crawler.php

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

154154
// DOM only for HTML/XML content
@@ -1001,11 +1001,11 @@ public function registerNamespace($prefix, $namespace)
10011001
*/
10021002
public static function xpathLiteral($s)
10031003
{
1004-
if (false === strpos($s, "'")) {
1004+
if (!str_contains($s, "'")) {
10051005
return sprintf("'%s'", $s);
10061006
}
10071007

1008-
if (false === strpos($s, '"')) {
1008+
if (!str_contains($s, '"')) {
10091009
return sprintf('"%s"', $s);
10101010
}
10111011

@@ -1098,29 +1098,29 @@ private function relativize(string $xpath): string
10981098
}
10991099
$expression = rtrim(substr($xpath, $startPosition, $i - $startPosition));
11001100

1101-
if (0 === strpos($expression, 'self::*/')) {
1101+
if (str_starts_with($expression, 'self::*/')) {
11021102
$expression = './'.substr($expression, 8);
11031103
}
11041104

11051105
// add prefix before absolute element selector
11061106
if ('' === $expression) {
11071107
$expression = $nonMatchingExpression;
1108-
} elseif (0 === strpos($expression, '//')) {
1108+
} elseif (str_starts_with($expression, '//')) {
11091109
$expression = 'descendant-or-self::'.substr($expression, 2);
1110-
} elseif (0 === strpos($expression, './/')) {
1110+
} elseif (str_starts_with($expression, './/')) {
11111111
$expression = 'descendant-or-self::'.substr($expression, 3);
1112-
} elseif (0 === strpos($expression, './')) {
1112+
} elseif (str_starts_with($expression, './')) {
11131113
$expression = 'self::'.substr($expression, 2);
1114-
} elseif (0 === strpos($expression, 'child::')) {
1114+
} elseif (str_starts_with($expression, 'child::')) {
11151115
$expression = 'self::'.substr($expression, 7);
1116-
} elseif ('/' === $expression[0] || '.' === $expression[0] || 0 === strpos($expression, 'self::')) {
1116+
} elseif ('/' === $expression[0] || '.' === $expression[0] || str_starts_with($expression, 'self::')) {
11171117
$expression = $nonMatchingExpression;
1118-
} elseif (0 === strpos($expression, 'descendant::')) {
1118+
} elseif (str_starts_with($expression, 'descendant::')) {
11191119
$expression = 'descendant-or-self::'.substr($expression, 12);
11201120
} elseif (preg_match('/^(ancestor|ancestor-or-self|attribute|following|following-sibling|namespace|parent|preceding|preceding-sibling)::/', $expression)) {
11211121
// the fake root has no parent, preceding or following nodes and also no attributes (even no namespace attributes)
11221122
$expression = $nonMatchingExpression;
1123-
} elseif (0 !== strpos($expression, 'descendant-or-self::')) {
1123+
} elseif (!str_starts_with($expression, 'descendant-or-self::')) {
11241124
$expression = 'self::'.$expression;
11251125
}
11261126
$expressions[] = $parenthesis.$expression;

0 commit comments

Comments
 (0)