Fix multiple issues detected by static analysis

This commit is contained in:
Bubka 2022-11-17 16:46:29 +01:00
parent 017bbc6304
commit b6a0e5055c
10 changed files with 21 additions and 24 deletions

View File

@ -18,7 +18,7 @@ class TwoFAccountCollection extends ResourceCollection
* Transform the resource collection into an array. * Transform the resource collection into an array.
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @return \Illuminate\Support\Collection * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/ */
public function toArray($request) public function toArray($request)
{ {

View File

@ -20,9 +20,9 @@ class UserResource extends JsonResource
public function toArray($request) public function toArray($request)
{ {
return [ return [
'id' => $this->when($request->user(), $this->id), 'id' => $this->when(!is_null($request->user()), $this->id),
'name' => $this->name, 'name' => $this->name,
'email' => $this->when($request->user(), $this->email), 'email' => $this->when(!is_null($request->user()), $this->email),
]; ];
} }
} }

View File

@ -18,7 +18,7 @@ class Handler extends ExceptionHandler
/** /**
* A list of the exception types that are not reported. * A list of the exception types that are not reported.
* *
* @var string[] * @var array<int, class-string<\Throwable>>
*/ */
protected $dontReport = [ protected $dontReport = [
// //
@ -27,7 +27,7 @@ class Handler extends ExceptionHandler
/** /**
* A list of the inputs that are never flashed for validation exceptions. * A list of the inputs that are never flashed for validation exceptions.
* *
* @var string[] * @var array<int, string>
*/ */
protected $dontFlash = [ protected $dontFlash = [
'current_password', 'current_password',

View File

@ -15,6 +15,6 @@ class CustomCreateFreshApiToken extends CreateFreshApiToken
*/ */
protected function requestShouldReceiveFreshToken($request) protected function requestShouldReceiveFreshToken($request)
{ {
return $request->user($this->guard); return !is_null($request->user($this->guard));
} }
} }

View File

@ -28,12 +28,11 @@ public function handle($request, Closure $next)
if($lang === 'browser') { if($lang === 'browser') {
$lang = config('app.fallback_locale'); $lang = config('app.fallback_locale');
$accepted = $request->header("Accept-Language"); $accepted = str_replace(' ', '', $request->header("Accept-Language"));
if ($accepted) { if ($accepted && $accepted !== '*') {
$accepted = is_array($accepted) ? implode(',', $accepted) : $accepted;
$prefLocales = array_reduce( $prefLocales = array_reduce(
explode(',', $accepted), array_diff(explode(',', $accepted), ['*']),
function ($res, $el) { function ($res, $el) {
list($l, $q) = array_merge(explode(';q=', $el), [1]); list($l, $q) = array_merge(explode(';q=', $el), [1]);
$res[$l] = (float) $q; $res[$l] = (float) $q;

View File

@ -34,7 +34,7 @@ class Group extends Model
/** /**
* The attributes that should be hidden for arrays. * The attributes that should be hidden for arrays.
* *
* @var array * @var array<int, string>
*/ */
protected $hidden = ['created_at', 'updated_at']; protected $hidden = ['created_at', 'updated_at'];
@ -42,7 +42,7 @@ class Group extends Model
/** /**
* The attributes that should be cast. * The attributes that should be cast.
* *
* @var array * @var array<string, string>
*/ */
protected $casts = [ protected $casts = [
'twofaccounts_count' => 'integer', 'twofaccounts_count' => 'integer',

View File

@ -29,7 +29,7 @@ class Option extends Model
/** /**
* Casts. * Casts.
* *
* @var array * @var array<string, string>
*/ */
protected $casts = []; protected $casts = [];

View File

@ -111,7 +111,7 @@ class TwoFAccount extends Model implements Sortable
/** /**
* The attributes that should be hidden for arrays. * The attributes that should be hidden for arrays.
* *
* @var array * @var array<int, string>
*/ */
protected $hidden = []; protected $hidden = [];
@ -119,7 +119,7 @@ class TwoFAccount extends Model implements Sortable
/** /**
* The attributes that should be cast. * The attributes that should be cast.
* *
* @var array * @var array<string, string>
*/ */
protected $casts = []; protected $casts = [];

View File

@ -16,11 +16,9 @@ public function up()
Schema::table('twofaccounts', function (Blueprint $table) { Schema::table('twofaccounts', function (Blueprint $table) {
$table->unsignedInteger('group_id') $table->unsignedInteger('group_id')
->after('id') ->after('id')
->nullable() ->nullable();
->constrained()
->onDelete('set null');
$table->foreign('group_id')->references('id')->on('groups'); $table->foreign('group_id')->references('id')->on('groups')->onDelete('set null');
}); });
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Illuminate\Foundation\Inspiring; // use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan; // use Illuminate\Support\Facades\Artisan;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -14,6 +14,6 @@
| |
*/ */
Artisan::command('inspire', function () { // Artisan::command('inspire', function () {
$this->comment(Inspiring::quote()); // $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote'); // })->purpose('Display an inspiring quote');