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.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Support\Collection
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{

View File

@ -20,9 +20,9 @@ class UserResource extends JsonResource
public function toArray($request)
{
return [
'id' => $this->when($request->user(), $this->id),
'id' => $this->when(!is_null($request->user()), $this->id),
'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.
*
* @var string[]
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [
//
@ -27,7 +27,7 @@ class Handler extends ExceptionHandler
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var string[]
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,11 +16,9 @@ class AddGroupIdColumnToTwofaccountsTable extends Migration
Schema::table('twofaccounts', function (Blueprint $table) {
$table->unsignedInteger('group_id')
->after('id')
->nullable()
->constrained()
->onDelete('set null');
->nullable();
$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
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
// use Illuminate\Foundation\Inspiring;
// use Illuminate\Support\Facades\Artisan;
/*
|--------------------------------------------------------------------------
@ -14,6 +14,6 @@ use Illuminate\Support\Facades\Artisan;
|
*/
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
// Artisan::command('inspire', function () {
// $this->comment(Inspiring::quote());
// })->purpose('Display an inspiring quote');