Skip to content

Commit

Permalink
Deprecates String and Array Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jcc committed Mar 5, 2019
1 parent 9dbb082 commit f98b7c6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Tools\Markdowner;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;

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

if (!config('services.youdao.appKey') || !config('services.youdao.appSecret')) {
$this->setUniqueSlug($value, str_random(5));
$this->setUniqueSlug($value, Str::random(5));
} else {
$this->setUniqueSlug(translug($value), '');
}
Expand All @@ -138,7 +139,7 @@ public function setTitleAttribute($value)
*/
public function setUniqueSlug($value, $extra)
{
$slug = str_slug($value.'-'.$extra);
$slug = Str::slug($value.'-'.$extra);

if (static::whereSlug($slug)->exists()) {
$this->setUniqueSlug($slug, (int) $extra + 1);
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use App\Http\Requests\ImageRequest;
use Illuminate\Support\Str;

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

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

if ($this->manager->checkFile($path.$fileName)) {
return $this->response->withBadRequest('This File exists.');
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Scopes\StatusScope;
use App\User;
use Illuminate\Support\Str;
use Image;
use Illuminate\Http\Request;
use App\Http\Requests\UserRequest;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function store(UserRequest $request)
{
$data = array_merge($request->all(), [
'password' => bcrypt($request->get('password')),
'confirm_code' => str_random(64),
'confirm_code' => Str::random(64),
]);

\DB::transaction(function () use ($request, $data) {
Expand Down
7 changes: 4 additions & 3 deletions app/Support/Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Support;

use Illuminate\Support\Arr;
use League\Fractal\Manager;
use App\Transformers\EmptyTransformer;
use League\Fractal\TransformerAbstract;
Expand Down Expand Up @@ -42,8 +43,8 @@ public function __construct(Manager $fractal)
*
* @param $data
* @param TransformerAbstract|null $transformer
*
* @return array
* @throws \Exception
*/
public function collection($data, TransformerAbstract $transformer = null)
{
Expand All @@ -63,8 +64,8 @@ public function collection($data, TransformerAbstract $transformer = null)
*
* @param $data
* @param TransformerAbstract|null $transformer
*
* @return array
* @throws \Exception
*/
public function item($data, TransformerAbstract $transformer = null)
{
Expand Down Expand Up @@ -127,7 +128,7 @@ protected function hasDefaultTransformer($className)
protected function getClassName($object)
{
if ($object instanceof LengthAwarePaginator || $object instanceof Collection) {
return get_class(array_first($object));
return get_class(Arr::first($object));
}

if (!is_string($object) && !is_object($object)) {
Expand Down

0 comments on commit f98b7c6

Please sign in to comment.