Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 034c5c3

Browse files
committed
add more return type declare
1 parent a1f378f commit 034c5c3

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

src/HtmlHelper.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HtmlHelper
2121
* @return string the encoded data
2222
* @see http://www.php.net/manual/en/function.htmlspecialchars.php
2323
*/
24-
public static function encode($text, $charset = 'utf-8')
24+
public static function encode($text, $charset = 'utf-8'): string
2525
{
2626
return htmlspecialchars($text, ENT_QUOTES, $charset);
2727
}
@@ -32,7 +32,7 @@ public static function encode($text, $charset = 'utf-8')
3232
* @return string the decoded data
3333
* @see http://www.php.net/manual/en/function.htmlspecialchars-decode.php
3434
*/
35-
public static function decode($text)
35+
public static function decode($text): string
3636
{
3737
return htmlspecialchars_decode($text, ENT_QUOTES);
3838
}
@@ -44,7 +44,7 @@ public static function decode($text)
4444
* @return array the encoded data
4545
* @see http://www.php.net/manual/en/function.htmlspecialchars.php
4646
*/
47-
public static function encodeArray($data, $charset = 'utf-8')
47+
public static function encodeArray($data, $charset = 'utf-8'): array
4848
{
4949
$d = [];
5050

src/Str.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function optional(string $string, string $prefix = ' ', string $su
3535
* @param string|array $needle
3636
* @return bool
3737
*/
38-
public static function contains(string $string, $needle)
38+
public static function contains(string $string, $needle): bool
3939
{
4040
return self::has($string, $needle);
4141
}
@@ -45,7 +45,7 @@ public static function contains(string $string, $needle)
4545
* @param string|array $needle
4646
* @return bool
4747
*/
48-
public static function has(string $string, $needle)
48+
public static function has(string $string, $needle): bool
4949
{
5050
if (\is_string($needle)) {
5151
return stripos($string, $needle) !== false;

src/StringHelper.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class StringHelper
1616
* @param string $rule 验证规则 require email url currency number integer english
1717
* @return boolean
1818
*/
19-
public static function regexVerify($value, $rule)
19+
public static function regexVerify($value, $rule): bool
2020
{
2121
$value = trim($value);
2222
$validate = array(
@@ -84,7 +84,7 @@ public static function length($str)
8484
* @internal param bool $type 计算长度类型,0(默认)表示一个中文算一个字符,1表示一个中文算两个字符
8585
* @return int
8686
*/
87-
public static function absLen($str)
87+
public static function absLen($str): int
8888
{
8989
if (empty($str)) {
9090
return 0;
@@ -111,7 +111,7 @@ public static function absLen($str)
111111
* @param int $end 要进行截取的长度
112112
* @return string
113113
*/
114-
public static function utf8SubStr($str, $start = 0, $end = null)
114+
public static function utf8SubStr($str, $start = 0, $end = null): string
115115
{
116116
if (empty($str)) {
117117
return false;
@@ -153,7 +153,7 @@ public static function utf8SubStr($str, $start = 0, $end = null)
153153
* @param bool $suffix 是否加尾缀
154154
* @return string
155155
*/
156-
public static function zhSubStr($str, $start = 0, $length, $charset = 'utf-8', $suffix = true)
156+
public static function zhSubStr($str, $start = 0, $length, $charset = 'utf-8', $suffix = true): string
157157
{
158158
if (\function_exists('mb_substr')) {
159159
if (mb_strlen($str, $charset) <= $length) {
@@ -190,7 +190,7 @@ public static function zhSubStr($str, $start = 0, $length, $charset = 'utf-8', $
190190
* @internal param string $chars
191191
* @return string
192192
*/
193-
public static function random($length, array $param = [])
193+
public static function random($length, array $param = []): string
194194
{
195195
$param = array_merge([
196196
'prefix' => '',
@@ -253,7 +253,7 @@ public static function genUid($length = 7)
253253
* @param string $str String to transform
254254
* @return string New string
255255
*/
256-
public static function nl2br($str)
256+
public static function nl2br($str): string
257257
{
258258
return str_replace(["\r\n", "\r", "\n"], '<br />', $str);
259259
}
@@ -330,7 +330,7 @@ public static function strrpos($str, $find, $offset = 0, $encoding = 'utf-8')
330330
* @param $str
331331
* @return string
332332
*/
333-
public static function ucfirst($str)
333+
public static function ucfirst($str): string
334334
{
335335
return self::strtoupper(self::substr($str, 0, 1)) . self::substr($str, 1);
336336
}
@@ -339,7 +339,7 @@ public static function ucfirst($str)
339339
* @param $str
340340
* @return string
341341
*/
342-
public static function ucwords($str)
342+
public static function ucwords($str): string
343343
{
344344
return \function_exists('mb_convert_case') ? mb_convert_case($str,
345345
MB_CASE_TITLE) : ucwords(self::strtolower($str));
@@ -350,7 +350,7 @@ public static function ucwords($str)
350350
* @param string $sep
351351
* @return array
352352
*/
353-
public static function toArray($str, $sep = ',')
353+
public static function toArray($str, $sep = ','): array
354354
{
355355
$array = [];
356356

@@ -373,7 +373,7 @@ public static function toArray($str, $sep = ',')
373373
* @param string $sep
374374
* @return array
375375
*/
376-
public static function str2array($str, $sep = ',')
376+
public static function str2array($str, $sep = ','): array
377377
{
378378
$str = trim($str, "$sep ");
379379

@@ -389,7 +389,7 @@ public static function str2array($str, $sep = ',')
389389
* @param string $separator
390390
* @return array
391391
*/
392-
public static function split2Array($path, $separator = '.')
392+
public static function split2Array($path, $separator = '.'): array
393393
{
394394
return array_values(array_filter(explode($separator, $path), '\strlen'));
395395
}
@@ -403,7 +403,7 @@ public static function split2Array($path, $separator = '.')
403403
*/
404404
/* CAUTION : Use it only on module hookEvents.
405405
** For other purposes use the smarty function instead */
406-
public static function truncate($str, $max_length, $suffix = '...')
406+
public static function truncate($str, $max_length, $suffix = '...'): string
407407
{
408408
if (self::strlen($str) <= $max_length) {
409409
return $str;
@@ -421,7 +421,7 @@ public static function truncate($str, $max_length, $suffix = '...')
421421
* @param null|int $length
422422
* @return string
423423
*/
424-
public static function truncate_two($str, $start, $length = null)
424+
public static function truncate_two($str, $start, $length = null): string
425425
{
426426
if (!$length) {
427427
$length = $start;
@@ -600,7 +600,7 @@ public static function toCamelCase($str, $upperFirstChar = false)
600600
}, $str);
601601
}
602602

603-
public static function toSnake($str, $sep = '_')
603+
public static function toSnake($str, $sep = '_'): string
604604
{
605605
return self::toSnakeCase($str, $sep);
606606
}
@@ -611,7 +611,7 @@ public static function toSnake($str, $sep = '_')
611611
* @param string $sep
612612
* @return string
613613
*/
614-
public static function toSnakeCase($str, $sep = '_')
614+
public static function toSnakeCase($str, $sep = '_'): string
615615
{
616616
// 'CMSCategories' => 'cms_categories'
617617
// 'RangePrice' => 'range_price'
@@ -675,7 +675,7 @@ public static function nameChange($str, $toCamelCase = true)
675675
* ]
676676
* @return string [type] [description]
677677
*/
678-
public static function format($str, array $replaceParams = [], array $pregParams = [])
678+
public static function format($str, array $replaceParams = [], array $pregParams = []): string
679679
{
680680
if (!\is_string($str) || !$str || (!$replaceParams && !$pregParams)) {
681681
return $str;
@@ -699,7 +699,7 @@ public static function format($str, array $replaceParams = [], array $pregParams
699699
* @param string $keyword 字符串
700700
* @return string 格式化后的字符串
701701
*/
702-
public static function wordFormat($keyword)
702+
public static function wordFormat($keyword): string
703703
{
704704
// 将全角角逗号换为空格
705705
$keyword = str_replace(['', ','], ' ', $keyword);

src/UrlHelper.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class UrlHelper
1818
* @param string $url the URL to be checked
1919
* @return boolean whether the URL is relative
2020
*/
21-
public static function isRelative($url)
21+
public static function isRelative($url): bool
2222
{
2323
return false === strpos($url, '//') && strpos($url, '://') === false;
2424
}
@@ -27,7 +27,7 @@ public static function isRelative($url)
2727
* @param $str
2828
* @return bool
2929
*/
30-
public static function isUrl($str)
30+
public static function isUrl($str): bool
3131
{
3232
$rule = '/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i';
3333

@@ -38,7 +38,7 @@ public static function isUrl($str)
3838
* @param $url
3939
* @return bool
4040
*/
41-
public static function isFullUrl($url)
41+
public static function isFullUrl($url): bool
4242
{
4343
return 0 === strpos($url, 'http:') || 0 === strpos($url, 'https:') || 0 === strpos($url, '//');
4444
}
@@ -48,7 +48,7 @@ public static function isFullUrl($url)
4848
* @param mixed $data
4949
* @return string
5050
*/
51-
public static function build($url, $data = null)
51+
public static function build($url, $data = null): string
5252
{
5353
if ($data && ($param = http_build_query($data))) {
5454
$url .= (strpos($url, '?') ? '&' : '?') . $param;
@@ -62,7 +62,7 @@ public static function build($url, $data = null)
6262
* @param $url
6363
* @return bool
6464
*/
65-
public static function canAccessed($url)
65+
public static function canAccessed($url): bool
6666
{
6767
$url = trim($url);
6868

@@ -136,7 +136,7 @@ public static function canAccessed($url)
136136
']'
137137
);
138138

139-
public static function parseUrl($url)
139+
public static function parseUrl($url): array
140140
{
141141
$result = [];
142142

0 commit comments

Comments
 (0)