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 9f8238f
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace ipl\Stdlib;

use LogicException;

/**
* Collection of string manipulation functions
*/
Expand All @@ -18,6 +20,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 +38,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 +60,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 +74,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 9f8238f

Please sign in to comment.