Skip to content

Commit a629c42

Browse files
committed
增加PHP7.1依赖
1 parent 92c24d1 commit a629c42

File tree

7 files changed

+25
-21
lines changed

7 files changed

+25
-21
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# thinkphp5 常用的一些扩展类库
1+
# thinkphp6 常用的一些扩展类库
22

3-
> 更新完善中
3+
基于PHP7.1+
44

55
> 以下类库都在`\\think\\helper`命名空间下
66
77
## Str
8+
89
> 字符串操作
910
1011
```

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"email": "448901948@qq.com"
99
}
1010
],
11+
"require": {
12+
"php": ">=7.1.0"
13+
},
1114
"autoload": {
1215
"psr-4": {
1316
"think\\": "src"

src/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ public function jsonSerialize()
623623
* @param integer $options json参数
624624
* @return string
625625
*/
626-
public function toJson($options = JSON_UNESCAPED_UNICODE)
626+
public function toJson(int $options = JSON_UNESCAPED_UNICODE): string
627627
{
628628
return json_encode($this->toArray(), $options);
629629
}

src/contract/Arrayable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
interface Arrayable
66
{
7-
public function toArray();
7+
public function toArray(): array;
88
}

src/contract/Jsonable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
interface Jsonable
66
{
7-
public function toJson($options = 0);
7+
public function toJson(int $options = JSON_UNESCAPED_UNICODE): string;
88
}

src/helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function data_get($target, $key, $default = null)
132132
$key = is_array($key) ? $key : explode('.', $key);
133133

134134
while (!is_null($segment = array_shift($key))) {
135-
if ($segment === '*') {
135+
if ('*' === $segment) {
136136
if ($target instanceof Collection) {
137137
$target = $target->all();
138138
} elseif (!is_array($target)) {

src/helper/Str.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class Str
2525
* @param string|array $needles
2626
* @return bool
2727
*/
28-
public static function contains($haystack, $needles)
28+
public static function contains(string $haystack, $needles): bool
2929
{
3030
foreach ((array) $needles as $needle) {
31-
if ($needle != '' && mb_strpos($haystack, $needle) !== false) {
31+
if ('' != $needle && mb_strpos($haystack, $needle) !== false) {
3232
return true;
3333
}
3434
}
@@ -43,7 +43,7 @@ public static function contains($haystack, $needles)
4343
* @param string|array $needles
4444
* @return bool
4545
*/
46-
public static function endsWith($haystack, $needles)
46+
public static function endsWith(string $haystack, $needles): bool
4747
{
4848
foreach ((array) $needles as $needle) {
4949
if ((string) $needle === static::substr($haystack, -static::length($needle))) {
@@ -61,10 +61,10 @@ public static function endsWith($haystack, $needles)
6161
* @param string|array $needles
6262
* @return bool
6363
*/
64-
public static function startsWith($haystack, $needles)
64+
public static function startsWith(string $haystack, $needles): bool
6565
{
6666
foreach ((array) $needles as $needle) {
67-
if ($needle != '' && mb_strpos($haystack, $needle) === 0) {
67+
if ('' != $needle && mb_strpos($haystack, $needle) === 0) {
6868
return true;
6969
}
7070
}
@@ -78,7 +78,7 @@ public static function startsWith($haystack, $needles)
7878
* @param int $length
7979
* @return string
8080
*/
81-
public static function random($length = 16)
81+
public static function random(int $length = 16): string
8282
{
8383
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
8484

@@ -91,7 +91,7 @@ public static function random($length = 16)
9191
* @param string $value
9292
* @return string
9393
*/
94-
public static function lower($value)
94+
public static function lower(string $value): string
9595
{
9696
return mb_strtolower($value, 'UTF-8');
9797
}
@@ -102,7 +102,7 @@ public static function lower($value)
102102
* @param string $value
103103
* @return string
104104
*/
105-
public static function upper($value)
105+
public static function upper(string $value): string
106106
{
107107
return mb_strtoupper($value, 'UTF-8');
108108
}
@@ -113,7 +113,7 @@ public static function upper($value)
113113
* @param string $value
114114
* @return int
115115
*/
116-
public static function length($value)
116+
public static function length(string $value): string
117117
{
118118
return mb_strlen($value);
119119
}
@@ -126,7 +126,7 @@ public static function length($value)
126126
* @param int|null $length
127127
* @return string
128128
*/
129-
public static function substr($string, $start, $length = null)
129+
public static function substr(string $string, int $start, int $length = null): string
130130
{
131131
return mb_substr($string, $start, $length, 'UTF-8');
132132
}
@@ -138,7 +138,7 @@ public static function substr($string, $start, $length = null)
138138
* @param string $delimiter
139139
* @return string
140140
*/
141-
public static function snake($value, $delimiter = '_')
141+
public static function snake(string $value, string $delimiter = '_'): string
142142
{
143143
$key = $value;
144144

@@ -161,7 +161,7 @@ public static function snake($value, $delimiter = '_')
161161
* @param string $value
162162
* @return string
163163
*/
164-
public static function camel($value)
164+
public static function camel(string $value): string
165165
{
166166
if (isset(static::$camelCache[$value])) {
167167
return static::$camelCache[$value];
@@ -176,7 +176,7 @@ public static function camel($value)
176176
* @param string $value
177177
* @return string
178178
*/
179-
public static function studly($value)
179+
public static function studly(string $value): string
180180
{
181181
$key = $value;
182182

@@ -195,8 +195,8 @@ public static function studly($value)
195195
* @param string $value
196196
* @return string
197197
*/
198-
public static function title($value)
198+
public static function title(string $value): string
199199
{
200200
return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
201201
}
202-
}
202+
}

0 commit comments

Comments
 (0)