Skip to content

Commit

Permalink
Str: Fix PHP 8.1 deprecated warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Nov 25, 2022
1 parent d42a161 commit feed14b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Expand All @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -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 {
Expand Down

0 comments on commit feed14b

Please sign in to comment.