Skip to content

Commit 9f1c637

Browse files
committed
used native PHP 8 functions
1 parent 2985c13 commit 9f1c637

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/Utils/Callback.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static function toReflection($callable): \ReflectionFunctionAbstract
9393
$callable = self::unwrap($callable);
9494
}
9595

96-
if (is_string($callable) && strpos($callable, '::')) {
96+
if (is_string($callable) && str_contains($callable, '::')) {
9797
return new \ReflectionMethod($callable);
9898
} elseif (is_array($callable)) {
9999
return new \ReflectionMethod($callable[0], $callable[1]);
@@ -120,7 +120,7 @@ public static function isStatic(callable $callable): bool
120120
public static function unwrap(\Closure $closure): callable
121121
{
122122
$r = new \ReflectionFunction($closure);
123-
if (substr($r->name, -1) === '}') {
123+
if (str_ends_with($r->name, '}')) {
124124
return $closure;
125125

126126
} elseif ($obj = $r->getClosureThis()) {

src/Utils/Html.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -805,14 +805,14 @@ final public function attributes(): string
805805
$value = (string) $value;
806806
}
807807

808-
$q = strpos($value, '"') === false ? '"' : "'";
808+
$q = str_contains($value, '"') ? "'" : '"';
809809
$s .= ' ' . $key . '=' . $q
810810
. str_replace(
811811
['&', $q, '<'],
812812
['&amp;', $q === '"' ? '&quot;' : '&#39;', self::$xhtml ? '&lt;' : '<'],
813813
$value,
814814
)
815-
. (strpos($value, '`') !== false && strpbrk($value, ' <>"\'') === false ? ' ' : '')
815+
. (str_contains($value, '`') && strpbrk($value, ' <>"\'') === false ? ' ' : '')
816816
. $q;
817817
}
818818

src/Utils/Image.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ public function __clone()
670670

671671
private static function isPercent(int|string &$num): bool
672672
{
673-
if (is_string($num) && substr($num, -1) === '%') {
673+
if (is_string($num) && str_ends_with($num, '%')) {
674674
$num = (float) substr($num, 0, -1);
675675
return true;
676676
} elseif (is_int($num) || $num === (string) (int) $num) {

src/Utils/Strings.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static function chr(int $code): string
6262
*/
6363
public static function startsWith(string $haystack, string $needle): bool
6464
{
65-
return strncmp($haystack, $needle, strlen($needle)) === 0;
65+
return str_starts_with($haystack, $needle);
6666
}
6767

6868

@@ -71,7 +71,7 @@ public static function startsWith(string $haystack, string $needle): bool
7171
*/
7272
public static function endsWith(string $haystack, string $needle): bool
7373
{
74-
return $needle === '' || substr($haystack, -strlen($needle)) === $needle;
74+
return str_ends_with($haystack, $needle);
7575
}
7676

7777

@@ -80,7 +80,7 @@ public static function endsWith(string $haystack, string $needle): bool
8080
*/
8181
public static function contains(string $haystack, string $needle): bool
8282
{
83-
return strpos($haystack, $needle) !== false;
83+
return str_contains($haystack, $needle);
8484
}
8585

8686

src/Utils/Validators.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ public static function assertField(
131131
public static function is(mixed $value, string $expected): bool
132132
{
133133
foreach (explode('|', $expected) as $item) {
134-
if (substr($item, -2) === '[]') {
134+
if (str_ends_with($item, '[]')) {
135135
if (is_iterable($value) && self::everyIs($value, substr($item, 0, -2))) {
136136
return true;
137137
}
138138
continue;
139-
} elseif (substr($item, 0, 1) === '?') {
139+
} elseif (str_starts_with($item, '?')) {
140140
$item = substr($item, 1);
141141
if ($value === null) {
142142
return true;

0 commit comments

Comments
 (0)