Skip to content

Commit f98b7c6

Browse files
committed
Deprecates String and Array Helpers
1 parent 9dbb082 commit f98b7c6

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

app/Article.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Tools\Markdowner;
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Database\Eloquent\SoftDeletes;
9+
use Illuminate\Support\Str;
910

1011
class Article extends Model
1112
{
@@ -124,7 +125,7 @@ public function setTitleAttribute($value)
124125
$this->attributes['title'] = $value;
125126

126127
if (!config('services.youdao.appKey') || !config('services.youdao.appSecret')) {
127-
$this->setUniqueSlug($value, str_random(5));
128+
$this->setUniqueSlug($value, Str::random(5));
128129
} else {
129130
$this->setUniqueSlug(translug($value), '');
130131
}
@@ -138,7 +139,7 @@ public function setTitleAttribute($value)
138139
*/
139140
public function setUniqueSlug($value, $extra)
140141
{
141-
$slug = str_slug($value.'-'.$extra);
142+
$slug = Str::slug($value.'-'.$extra);
142143

143144
if (static::whereSlug($slug)->exists()) {
144145
$this->setUniqueSlug($slug, (int) $extra + 1);

app/Http/Controllers/Api/UploadController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Http\Request;
66
use App\Http\Requests\ImageRequest;
7+
use Illuminate\Support\Str;
78

89
class UploadController extends ApiController
910
{
@@ -45,7 +46,7 @@ public function uploadForManager(Request $request)
4546
? $request->get('name').'.'.explode('/', $file->getClientMimeType())[1]
4647
: $file->getClientOriginalName();
4748

48-
$path = str_finish($request->get('folder'), '/');
49+
$path = Str::finish($request->get('folder'), '/');
4950

5051
if ($this->manager->checkFile($path.$fileName)) {
5152
return $this->response->withBadRequest('This File exists.');

app/Http/Controllers/Api/UserController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Scopes\StatusScope;
66
use App\User;
7+
use Illuminate\Support\Str;
78
use Image;
89
use Illuminate\Http\Request;
910
use App\Http\Requests\UserRequest;
@@ -61,7 +62,7 @@ public function store(UserRequest $request)
6162
{
6263
$data = array_merge($request->all(), [
6364
'password' => bcrypt($request->get('password')),
64-
'confirm_code' => str_random(64),
65+
'confirm_code' => Str::random(64),
6566
]);
6667

6768
\DB::transaction(function () use ($request, $data) {

app/Support/Transform.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Support;
44

5+
use Illuminate\Support\Arr;
56
use League\Fractal\Manager;
67
use App\Transformers\EmptyTransformer;
78
use League\Fractal\TransformerAbstract;
@@ -42,8 +43,8 @@ public function __construct(Manager $fractal)
4243
*
4344
* @param $data
4445
* @param TransformerAbstract|null $transformer
45-
*
4646
* @return array
47+
* @throws \Exception
4748
*/
4849
public function collection($data, TransformerAbstract $transformer = null)
4950
{
@@ -63,8 +64,8 @@ public function collection($data, TransformerAbstract $transformer = null)
6364
*
6465
* @param $data
6566
* @param TransformerAbstract|null $transformer
66-
*
6767
* @return array
68+
* @throws \Exception
6869
*/
6970
public function item($data, TransformerAbstract $transformer = null)
7071
{
@@ -127,7 +128,7 @@ protected function hasDefaultTransformer($className)
127128
protected function getClassName($object)
128129
{
129130
if ($object instanceof LengthAwarePaginator || $object instanceof Collection) {
130-
return get_class(array_first($object));
131+
return get_class(Arr::first($object));
131132
}
132133

133134
if (!is_string($object) && !is_object($object)) {

0 commit comments

Comments
 (0)