Skip to content

Commit 460c1c5

Browse files
committed
breaking: migrate to php 80, for the src/Str
1 parent 3ab4ec3 commit 460c1c5

8 files changed

+79
-71
lines changed

src/Str/HtmlHelper.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ public static function decode(string $text): string
5959
/**
6060
* @form yii1
6161
*
62-
* @param array $data data to be encoded
62+
* @param array $data data to be encoded
6363
* @param string $charset
6464
*
6565
* @return array the encoded data
6666
* @see http://www.php.net/manual/en/function.htmlspecialchars.php
6767
*/
68-
public static function encodeArray($data, string $charset = 'utf-8'): array
68+
public static function encodeArray(array $data, string $charset = 'utf-8'): array
6969
{
7070
$d = [];
7171

@@ -101,7 +101,7 @@ public static function encodeArray($data, string $charset = 'utf-8'): array
101101
*
102102
* @return array|string
103103
*/
104-
public static function escape($data, int $type = 0, string $encoding = 'UTF-8')
104+
public static function escape($data, int $type = 0, string $encoding = 'UTF-8'): array|string
105105
{
106106
if (is_array($data)) {
107107
foreach ($data as $k => $v) {
@@ -129,13 +129,13 @@ public static function escape($data, int $type = 0, string $encoding = 'UTF-8')
129129
/**
130130
* 去掉html转义
131131
*
132-
* @param string|array $data
133-
* @param int $type
132+
* @param array|string $data
133+
* @param int $type
134134
* @param string $encoding
135135
*
136136
* @return array|string
137137
*/
138-
public static function unescap($data, $type = 0, string $encoding = 'UTF-8')
138+
public static function unescap(array|string $data, int $type = 0, string $encoding = 'UTF-8'): array|string
139139
{
140140
if (is_array($data)) {
141141
foreach ($data as $k => $v) {
@@ -245,7 +245,7 @@ public static function minify(string $html): string
245245
* @param mixed $object Object to display
246246
* @param string $type
247247
*/
248-
public static function fd($object, $type = 'log'): void
248+
public static function fd(mixed $object, string $type = 'log'): void
249249
{
250250
$types = ['log', 'debug', 'info', 'warn', 'error', 'assert'];
251251

src/Str/StringHelper.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ abstract class StringHelper
6161
public const TRUE_WORDS = '|on|yes|true|';
6262
public const FALSE_WORDS = '|off|no|false|';
6363

64-
public static $defaultEncoding = 'UTF-8';
64+
public static string $defaultEncoding = 'UTF-8';
6565

6666
use StringCaseHelperTrait;
6767
use StringCheckHelperTrait;
@@ -72,25 +72,25 @@ abstract class StringHelper
7272

7373
/**
7474
* @param string|mixed $str
75-
* @param int|float $padLen
75+
* @param float|int $padLen
7676
* @param string $padStr
7777
* @param int $padType
7878
*
7979
* @return string
8080
*/
81-
public static function pad($str, $padLen, string $padStr = ' ', int $padType = STR_PAD_RIGHT): string
81+
public static function pad(mixed $str, float|int $padLen, string $padStr = ' ', int $padType = STR_PAD_RIGHT): string
8282
{
8383
return $padLen > 0 ? str_pad((string)$str, (int)$padLen, $padStr, $padType) : (string)$str;
8484
}
8585

8686
/**
8787
* @param string|mixed $str
88-
* @param int|float $padLen
88+
* @param float|int $padLen
8989
* @param string $padStr
9090
*
9191
* @return string
9292
*/
93-
public static function padLeft($str, $padLen, string $padStr = ' '): string
93+
public static function padLeft(mixed $str, float|int $padLen, string $padStr = ' '): string
9494
{
9595
return $padLen > 0 ? str_pad((string)$str, (int)$padLen, $padStr, STR_PAD_LEFT) : (string)$str;
9696
}
@@ -228,12 +228,12 @@ public static function genUUID(int $version = 1, $node = null, $ns = null): UUID
228228
/**
229229
* Generate order number
230230
*
231-
* @param string|int $prefix
231+
* @param int|string $prefix
232232
*
233233
* @return string If no prefix, default length is 20
234234
* @throws Exception
235235
*/
236-
public static function genNOV1($prefix = '', array $randomRange = []): string
236+
public static function genNOV1(int|string $prefix = '', array $randomRange = []): string
237237
{
238238
$host = gethostname();
239239
$time = microtime(true) * 10000;
@@ -408,7 +408,7 @@ public static function wrapList(array $list, string $wrapChar): array
408408
*
409409
* @return string
410410
*/
411-
public static function wrap($str, string $wrapChar): string
411+
public static function wrap(mixed $str, string $wrapChar): string
412412
{
413413
$str = (string)$str;
414414
if ($str === '') {

src/Str/Traits/StringCaseHelperTrait.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ trait StringCaseHelperTrait
4444
/**
4545
* Alias of the `strtolower()`
4646
*
47-
* @param string|int $str
47+
* @param int|string $str
4848
*
4949
* @return string
5050
*/
51-
public static function lower($str): string
51+
public static function lower(int|string $str): string
5252
{
5353
return static::strtolower($str);
5454
}
5555

5656
/**
5757
* Alias of the `strtolower()`
5858
*
59-
* @param string|int $str
59+
* @param int|string $str
6060
*
6161
* @return string
6262
*/
63-
public static function toLower($str): string
63+
public static function toLower(int|string $str): string
6464
{
6565
return static::strtolower($str);
6666
}
@@ -86,23 +86,23 @@ public static function strtolower(string $str): string
8686
/**
8787
* Alias of the `strtoupper()`
8888
*
89-
* @param string|int $str
89+
* @param int|string $str
9090
*
9191
* @return string
9292
*/
93-
public static function upper($str): string
93+
public static function upper(int|string $str): string
9494
{
9595
return static::toUpper($str);
9696
}
9797

9898
/**
9999
* Alias of the `strtoupper()`
100100
*
101-
* @param string|int $str
101+
* @param int|string $str
102102
*
103103
* @return string
104104
*/
105-
public static function toUpper($str): string
105+
public static function toUpper(int|string $str): string
106106
{
107107
if (!$str || !is_scalar($str)) {
108108
return '';
@@ -116,21 +116,21 @@ public static function toUpper($str): string
116116
}
117117

118118
/**
119-
* @param string|int $str
119+
* @param int|string $str
120120
*
121121
* @return string
122122
*/
123-
public static function strtoupper($str): string
123+
public static function strtoupper(int|string $str): string
124124
{
125125
return self::toUpper($str);
126126
}
127127

128128
/**
129-
* @param string|int $str
129+
* @param int|string $str
130130
*
131131
* @return string
132132
*/
133-
public static function upFirst($str): string
133+
public static function upFirst(int|string $str): string
134134
{
135135
if (!$str || !is_scalar($str)) {
136136
return '';

0 commit comments

Comments
 (0)