diff --git a/src/Utils/Callback.php b/src/Utils/Callback.php index 735eac57b..98acea615 100644 --- a/src/Utils/Callback.php +++ b/src/Utils/Callback.php @@ -93,7 +93,7 @@ public static function toReflection($callable): \ReflectionFunctionAbstract $callable = self::unwrap($callable); } - if (is_string($callable) && strpos($callable, '::')) { + if (is_string($callable) && str_contains($callable, '::')) { return new \ReflectionMethod($callable); } elseif (is_array($callable)) { return new \ReflectionMethod($callable[0], $callable[1]); @@ -120,7 +120,7 @@ public static function isStatic(callable $callable): bool public static function unwrap(\Closure $closure): callable { $r = new \ReflectionFunction($closure); - if (substr($r->name, -1) === '}') { + if (str_ends_with($r->name, '}')) { return $closure; } elseif ($obj = $r->getClosureThis()) { diff --git a/src/Utils/Html.php b/src/Utils/Html.php index f86c51bf9..ac67e0e74 100644 --- a/src/Utils/Html.php +++ b/src/Utils/Html.php @@ -805,14 +805,14 @@ final public function attributes(): string $value = (string) $value; } - $q = strpos($value, '"') === false ? '"' : "'"; + $q = str_contains($value, '"') ? "'" : '"'; $s .= ' ' . $key . '=' . $q . str_replace( ['&', $q, '<'], ['&', $q === '"' ? '"' : ''', self::$xhtml ? '<' : '<'], $value, ) - . (strpos($value, '`') !== false && strpbrk($value, ' <>"\'') === false ? ' ' : '') + . (str_contains($value, '`') && strpbrk($value, ' <>"\'') === false ? ' ' : '') . $q; } diff --git a/src/Utils/Image.php b/src/Utils/Image.php index 05c052996..bc8c7f01f 100644 --- a/src/Utils/Image.php +++ b/src/Utils/Image.php @@ -670,7 +670,7 @@ public function __clone() private static function isPercent(int|string &$num): bool { - if (is_string($num) && substr($num, -1) === '%') { + if (is_string($num) && str_ends_with($num, '%')) { $num = (float) substr($num, 0, -1); return true; } elseif (is_int($num) || $num === (string) (int) $num) { diff --git a/src/Utils/Strings.php b/src/Utils/Strings.php index f6bfb9f44..6e7b35cf0 100644 --- a/src/Utils/Strings.php +++ b/src/Utils/Strings.php @@ -62,7 +62,7 @@ public static function chr(int $code): string */ public static function startsWith(string $haystack, string $needle): bool { - return strncmp($haystack, $needle, strlen($needle)) === 0; + return str_starts_with($haystack, $needle); } @@ -71,7 +71,7 @@ public static function startsWith(string $haystack, string $needle): bool */ public static function endsWith(string $haystack, string $needle): bool { - return $needle === '' || substr($haystack, -strlen($needle)) === $needle; + return str_ends_with($haystack, $needle); } @@ -80,7 +80,7 @@ public static function endsWith(string $haystack, string $needle): bool */ public static function contains(string $haystack, string $needle): bool { - return strpos($haystack, $needle) !== false; + return str_contains($haystack, $needle); } diff --git a/src/Utils/Validators.php b/src/Utils/Validators.php index 4f7b09a3c..7d1e57779 100644 --- a/src/Utils/Validators.php +++ b/src/Utils/Validators.php @@ -131,12 +131,12 @@ public static function assertField( public static function is(mixed $value, string $expected): bool { foreach (explode('|', $expected) as $item) { - if (substr($item, -2) === '[]') { + if (str_ends_with($item, '[]')) { if (is_iterable($value) && self::everyIs($value, substr($item, 0, -2))) { return true; } continue; - } elseif (substr($item, 0, 1) === '?') { + } elseif (str_starts_with($item, '?')) { $item = substr($item, 1); if ($value === null) { return true;