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 7, 2022
1 parent d42a161 commit cbd3485
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 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 null;
}

$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 @@ -63,12 +72,16 @@ public static function symmetricSplit($subject, $delimiter, $limit, $default = n
*
* @param string $subject
* @param string $delimiter
* @param int $limit
* @param ?int $limit
*
* @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 cbd3485

Please sign in to comment.