From be75213aa3ba1c73756368f17be20a2bcbdeb835 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 7 Nov 2022 13:09:26 +0100 Subject: [PATCH] Str: Fix PHP 8.1 deprecated warnings --- src/Str.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Str.php b/src/Str.php index b624c77..d46989e 100644 --- a/src/Str.php +++ b/src/Str.php @@ -18,6 +18,10 @@ class Str */ public static function camel($subject) { + if ($subject === null) { + return ''; + } + $normalized = str_replace(['-', '_'], ' ', $subject); return lcfirst(str_replace(' ', '', ucwords(strtolower($normalized)))); @@ -32,8 +36,9 @@ public static function camel($subject) * * @return bool */ - public static function startsWith($subject, $start, $caseSensitive = true) + public static function startsWith($subject, string $start, bool $caseSensitive = true) { + $subject = $subject ?? ''; if (! $caseSensitive) { return strncasecmp($subject, $start, strlen($start)) === 0; } @@ -53,8 +58,12 @@ public static function startsWith($subject, $start, $caseSensitive = true) * * @return array */ - public static function symmetricSplit($subject, $delimiter, $limit, $default = null) + public static function symmetricSplit($subject, string $delimiter, int $limit, $default = null) { + if ($subject === null) { + return []; + } + return array_pad(explode($delimiter, $subject, $limit), $limit, $default); } @@ -67,8 +76,12 @@ public static function symmetricSplit($subject, $delimiter, $limit, $default = n * * @return array */ - public static function trimSplit($subject, $delimiter = ',', $limit = null) + public static function trimSplit($subject, string $delimiter = ',', int $limit = null) { + if ($subject === null) { + return []; + } + if ($limit !== null) { $exploded = explode($delimiter, $subject, $limit); } else {