From b6a0e5055c22344b87c440c3c910b86f03e05776 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Thu, 17 Nov 2022 16:46:29 +0100 Subject: [PATCH] Fix multiple issues detected by static analysis --- app/Api/v1/Resources/TwoFAccountCollection.php | 2 +- app/Api/v1/Resources/UserResource.php | 4 ++-- app/Exceptions/Handler.php | 4 ++-- app/Http/Middleware/CustomCreateFreshApiToken.php | 2 +- app/Http/Middleware/SetLanguage.php | 7 +++---- app/Models/Group.php | 4 ++-- app/Models/Option.php | 2 +- app/Models/TwoFAccount.php | 4 ++-- ...11115_add_group_id_column_to_twofaccounts_table.php | 6 ++---- routes/console.php | 10 +++++----- 10 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app/Api/v1/Resources/TwoFAccountCollection.php b/app/Api/v1/Resources/TwoFAccountCollection.php index 8677573e..4da5cf19 100644 --- a/app/Api/v1/Resources/TwoFAccountCollection.php +++ b/app/Api/v1/Resources/TwoFAccountCollection.php @@ -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) { diff --git a/app/Api/v1/Resources/UserResource.php b/app/Api/v1/Resources/UserResource.php index cbc2938d..b943ec2a 100644 --- a/app/Api/v1/Resources/UserResource.php +++ b/app/Api/v1/Resources/UserResource.php @@ -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), ]; } } \ No newline at end of file diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index cf052a00..52fb0f7b 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -18,7 +18,7 @@ class Handler extends ExceptionHandler /** * A list of the exception types that are not reported. * - * @var string[] + * @var array> */ 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 */ protected $dontFlash = [ 'current_password', diff --git a/app/Http/Middleware/CustomCreateFreshApiToken.php b/app/Http/Middleware/CustomCreateFreshApiToken.php index fd88b287..2a80f624 100644 --- a/app/Http/Middleware/CustomCreateFreshApiToken.php +++ b/app/Http/Middleware/CustomCreateFreshApiToken.php @@ -15,6 +15,6 @@ class CustomCreateFreshApiToken extends CreateFreshApiToken */ protected function requestShouldReceiveFreshToken($request) { - return $request->user($this->guard); + return !is_null($request->user($this->guard)); } } \ No newline at end of file diff --git a/app/Http/Middleware/SetLanguage.php b/app/Http/Middleware/SetLanguage.php index fa56adb0..4db2634b 100644 --- a/app/Http/Middleware/SetLanguage.php +++ b/app/Http/Middleware/SetLanguage.php @@ -28,12 +28,11 @@ public function handle($request, Closure $next) 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; diff --git a/app/Models/Group.php b/app/Models/Group.php index 1c41425b..c7b92fac 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -34,7 +34,7 @@ class Group extends Model /** * The attributes that should be hidden for arrays. * - * @var array + * @var array */ protected $hidden = ['created_at', 'updated_at']; @@ -42,7 +42,7 @@ class Group extends Model /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'twofaccounts_count' => 'integer', diff --git a/app/Models/Option.php b/app/Models/Option.php index 3e7307e2..2d335f78 100644 --- a/app/Models/Option.php +++ b/app/Models/Option.php @@ -29,7 +29,7 @@ class Option extends Model /** * Casts. * - * @var array + * @var array */ protected $casts = []; diff --git a/app/Models/TwoFAccount.php b/app/Models/TwoFAccount.php index 07e6c6bb..1ed2d566 100644 --- a/app/Models/TwoFAccount.php +++ b/app/Models/TwoFAccount.php @@ -111,7 +111,7 @@ class TwoFAccount extends Model implements Sortable /** * The attributes that should be hidden for arrays. * - * @var array + * @var array */ protected $hidden = []; @@ -119,7 +119,7 @@ class TwoFAccount extends Model implements Sortable /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = []; diff --git a/database/migrations/2020_10_20_211115_add_group_id_column_to_twofaccounts_table.php b/database/migrations/2020_10_20_211115_add_group_id_column_to_twofaccounts_table.php index 211fbbf6..3ed6464e 100644 --- a/database/migrations/2020_10_20_211115_add_group_id_column_to_twofaccounts_table.php +++ b/database/migrations/2020_10_20_211115_add_group_id_column_to_twofaccounts_table.php @@ -16,11 +16,9 @@ public function up() 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'); }); } diff --git a/routes/console.php b/routes/console.php index e05f4c9a..9354e741 100644 --- a/routes/console.php +++ b/routes/console.php @@ -1,7 +1,7 @@ comment(Inspiring::quote()); -})->purpose('Display an inspiring quote'); +// Artisan::command('inspire', function () { +// $this->comment(Inspiring::quote()); +// })->purpose('Display an inspiring quote');