Fix some issues detected by static analysis

This commit is contained in:
Bubka 2022-08-26 15:57:18 +02:00
parent 808d5a0d10
commit 70c4c271cd
34 changed files with 68 additions and 50 deletions

View File

@ -17,7 +17,7 @@ class GroupController extends Controller
/**
* Display a listing of the resource.
*
* @return \App\Api\v1\Resources\GroupResource
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
*/
public function index()
{

View File

@ -24,7 +24,7 @@ public function upload(Request $request)
]);
$path = $request->file('icon')->store('', 'icons');
$response['filename'] = pathinfo($path)['basename'];
$response = array( "filename" => pathinfo($path)['basename']);
return response()->json($response, 201);
}
@ -54,10 +54,10 @@ public function fetch(Request $request)
/**
* delete an icon
*
* @param \Illuminate\Http\Request $request
* @param string $icon
* @return \Illuminate\Http\JsonResponse
*/
public function delete($icon)
public function delete(string $icon)
{
Storage::disk('icons')->delete($icon);

View File

@ -14,7 +14,7 @@ class QrCodeController extends Controller
/**
* Show a QR code image
*
* @param App\Models\TwoFAccount $twofaccount
* @param \App\Models\TwoFAccount $twofaccount
* @return \Illuminate\Http\JsonResponse
*/
public function show(TwoFAccount $twofaccount)

View File

@ -77,7 +77,7 @@ public function store(SettingStoreRequest $request)
* @param \App\Api\v1\Requests\SettingUpdateRequest $request
* @return \Illuminate\Http\JsonResponse
*/
public function update(SettingUpdateRequest $request, $settingName)
public function update(SettingUpdateRequest $request, string $settingName)
{
$validated = $request->validated();
@ -94,10 +94,10 @@ public function update(SettingUpdateRequest $request, $settingName)
/**
* Delete a setting
*
* @param \App\Api\v1\Requests\SettingUpdateRequest $request
* @param string $settingName
* @return \Illuminate\Http\JsonResponse
*/
public function destroy($settingName)
public function destroy(string $settingName)
{
$setting = Settings::get($settingName);

View File

@ -152,7 +152,7 @@ public function preview(TwoFAccountUriRequest $request)
* Get a One-Time Password
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @param string|null $id
* @return \Illuminate\Http\JsonResponse
*/
public function otp(Request $request, $id = null)

View File

@ -12,7 +12,7 @@ class UserController extends Controller
/**
* Get detailed information about a user
*
* @return \App\Api\v1\Resources\UserResource
* @return \App\Api\v1\Resources\UserResource|\Illuminate\Http\JsonResponse
*/
public function show(Request $request)
{

View File

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

View File

@ -6,7 +6,8 @@
class IconGenerator
{
public static function generateIcon($serviceName, $base64icon) {
public static function generateIcon(string $serviceName, string $base64icon) : void
{
Storage::disk('icons')->put($serviceName . '.png', base64_decode($base64icon));
}

View File

@ -11,6 +11,9 @@ class GroupDeleting
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @var \App\Models\Group
*/
public $group;
/**

View File

@ -12,6 +12,9 @@ class TwoFAccountDeleted
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @var \App\Models\TwoFAccount
*/
public $twofaccount;
/**

View File

@ -85,13 +85,13 @@ protected function sendLoginResponse(Request $request)
{
$this->clearLoginAttempts($request);
$success['name'] = $this->guard()->user()->name;
$name = $this->guard()->user()?->name;
$this->authenticated($request, $this->guard()->user());
return response()->json([
'message' => 'authenticated',
'name' => $success['name']
'name' => $name
], Response::HTTP_OK);
}
@ -146,7 +146,7 @@ protected function credentials(Request $request)
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @return mixed
* @return void
*/
protected function authenticated(Request $request, $user)
{

View File

@ -12,7 +12,7 @@ class PasswordController extends Controller
/**
* Update the user's password.
*
* @param \App\Api\v1\Requests\UserPatchPwdRequest $request
* @param \App\Http\Requests\UserPatchPwdRequest $request
* @return \Illuminate\Http\JsonResponse
*/
public function update(UserPatchPwdRequest $request)

View File

@ -28,7 +28,7 @@ class RegisterController extends Controller
/**
* Handle a registration request for the application.
*
* @param \App\Api\v1\Requests\UserStoreRequest $request
* @param \App\Http\Requests\UserStoreRequest $request
* @return \Illuminate\Http\JsonResponse
*/
public function register(UserStoreRequest $request)

View File

@ -17,7 +17,7 @@ class UserController extends Controller
* Update the user's profile information.
*
* @param \App\Http\Requests\UserUpdateRequest $request
* @return \App\Api\v1\Resources\UserResource
* @return \App\Api\v1\Resources\UserResource|\Illuminate\Http\JsonResponse
*/
public function update(UserUpdateRequest $request)
{

View File

@ -27,7 +27,9 @@ class WebAuthnLoginController extends Controller
|
*/
/**
* @return \Illuminate\Http\JsonResponse|\Webauthn\PublicKeyCredentialRequestOptions
*/
public function options(Request $request)
{
// Since 2FAuth is single user designed we fetch the user instance

View File

@ -28,6 +28,8 @@ public function __construct()
/**
* List all WebAuthn registered credentials
*
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
{

View File

@ -73,7 +73,7 @@ protected function sendRecoveryResponse(Request $request, string $response): Jso
* @param \Illuminate\Http\Request $request
* @param string $response
*
* @return \Illuminate\Http\JsonResponse|void
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
*
* @codeCoverageIgnore - already covered by larapass test

View File

@ -11,7 +11,7 @@ class SinglePageController extends Controller
/**
* return the main view
* @return view
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
public function index()
{

View File

@ -16,6 +16,7 @@ class SystemController extends Controller
*/
public function infos(Request $request)
{
$infos = array();
$infos['Date'] = date(DATE_RFC2822);
$infos['userAgent'] = $request->header('user-agent');
// App info

View File

@ -83,7 +83,7 @@ class Kernel extends HttpKernel
*
* This forces non-global middleware to always be in the given order.
*
* @var array
* @var string[]
*/
protected $middlewarePriority = [
\Illuminate\Session\Middleware\StartSession::class,

View File

@ -13,7 +13,7 @@ class LogUserLastSeen
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @param string|null $guards
* @return mixed
*/
public function handle($request, Closure $next, ...$guards)

View File

@ -15,7 +15,7 @@ class Group extends Model
/**
* model's array form.
*
* @var array
* @var string[]
*/
protected $fillable = ['name'];
@ -65,7 +65,7 @@ protected static function boot()
{
parent::boot();
static::deleted(function ($model) {
static::deleted(function (object $model) {
// @codeCoverageIgnoreStart
Log::info(sprintf('Group %s deleted', var_export($model->name, true)));
// @codeCoverageIgnoreEnd
@ -75,9 +75,11 @@ protected static function boot()
/**
* Get the TwoFAccounts of the group.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function twofaccounts()
{
return $this->hasMany('App\Models\TwoFAccount');
return $this->hasMany(\App\Models\TwoFAccount::class);
}
}

View File

@ -10,7 +10,7 @@ class Option extends Model
/**
* The attributes that are mass assignable.
*
* @var [type]
* @var string[]
*/
protected $fillable = [
'key',

View File

@ -64,7 +64,7 @@ class TwoFAccount extends Model implements Sortable
/**
* model's array form.
*
* @var array
* @var string[]
*/
protected $fillable = [
// 'service',
@ -141,7 +141,7 @@ protected static function boot()
{
parent::boot();
static::saving(function ($twofaccount) {
static::saving(function (TwoFAccount $twofaccount) {
if (!$twofaccount->legacy_uri) $twofaccount->legacy_uri = $twofaccount->getURI();
if ($twofaccount->otp_type == TwoFAccount::TOTP && !$twofaccount->period) $twofaccount->period = TwoFAccount::DEFAULT_PERIOD;
if ($twofaccount->otp_type == TwoFAccount::HOTP && !$twofaccount->counter) $twofaccount->counter = TwoFAccount::DEFAULT_COUNTER;
@ -186,7 +186,7 @@ protected static function boot()
* The OTP generator.
* Instanciated as null to keep the model light
*
* @var
* @var \OTPHP\OTPInterface|null
*/
protected $generator = null;
@ -462,7 +462,7 @@ public function fillWithURI(string $uri, bool $isSteamTotp = false, bool $skipIc
/**
* Sets model attributes to STEAM values
*/
private function enforceAsSteam()
private function enforceAsSteam() : void
{
$this->otp_type = self::STEAM_TOTP;
$this->digits = 5;
@ -495,7 +495,7 @@ public function getURI() : string
/**
* Instanciates the OTP generator with model attribute values
*/
private function initGenerator()
private function initGenerator() : void
{
try {
switch ($this->otp_type) {

View File

@ -62,7 +62,7 @@ public function sendPasswordResetNotification($token)
* set Email attribute
* @param string $value
*/
public function setEmailAttribute($value)
public function setEmailAttribute($value) : void
{
$this->attributes['email'] = strtolower($value);
}
@ -79,7 +79,7 @@ public function sendCredentialRecoveryNotification(string $token): void
$accountRecoveryNotification = new AccountRecoveryNotification($token);
$accountRecoveryNotification->toMailUsing(null);
$accountRecoveryNotification->createUrlUsing(function($notifiable, $token) {
$accountRecoveryNotification->createUrlUsing(function(mixed $notifiable, string $token) {
$url = url(
route(
'webauthn.recover',

View File

@ -2,7 +2,6 @@
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

View File

@ -60,7 +60,7 @@ public function boot()
*
* @return string The Api namespace
*/
private function getApiNamespace($version)
private function getApiNamespace(string $version)
{
return 'App\Api\v' . $version . '\Controllers';
}

View File

@ -36,7 +36,7 @@ public function passes($attribute, $value)
/**
* Get the validation error message.
* @codeCoverageIgnore
* @return string
* @return array|string
*/
public function message()
{

View File

@ -32,7 +32,7 @@ public function passes($attribute, $value)
/**
* Get the validation error message.
*
* @return string
* @return array|string
*/
public function message()
{

View File

@ -38,7 +38,7 @@ public function passes($attribute, $value)
/**
* Get the validation error message.
*
* @return string
* @return array|string
*/
public function message()
{

View File

@ -30,7 +30,7 @@ class ReverseProxyGuard implements Guard
/**
* Create a new authentication guard.
*
* @param Illuminate\Contracts\Auth\UserProvider $provider
* @param \Illuminate\Contracts\Auth\UserProvider $provider
* @return void
*/
public function __construct(UserProvider $provider)
@ -71,6 +71,7 @@ public function user()
// Get the user identifier from $_SERVER or apache filtered headers
$remoteUserHeader = config('auth.auth_proxy_headers.user');
$remoteUserHeader = $remoteUserHeader ?: 'REMOTE_USER';
$identifier = array();
try {
$identifier['user'] = request()->server($remoteUserHeader) ?? apache_request_headers()[$remoteUserHeader] ?? null;

View File

@ -34,6 +34,7 @@ public static function encode(string $data)
* Decode an uploaded QR code image
*
* @param \Illuminate\Http\UploadedFile $file
* @return string
*/
public static function decode(\Illuminate\Http\UploadedFile $file)
{

View File

@ -39,7 +39,7 @@ public function __construct()
* @param string|array $setting A single setting name or an associative array of name:value settings
* @return mixed string|int|boolean|null
*/
public function get(string $setting)
public function get($setting)
{
return $this->settings->get($setting);
}
@ -110,6 +110,8 @@ public function isUserDefined($key) : bool
/**
* Set the settings collection
*
* @return void
*/
private function build()
{
@ -133,10 +135,10 @@ private function build()
/**
* Replaces boolean by a patterned string as appstrack/laravel-options package does not support var type
*
* @param \Illuminate\Support\Collection $settings
* @return \Illuminate\Support\Collection
* @param mixed $settings
* @return string
*/
private function replaceBoolean($value)
private function replaceBoolean(mixed $value)
{
return is_bool($value) ? '{{' . $value . '}}' : $value;
}
@ -145,10 +147,10 @@ private function replaceBoolean($value)
/**
* Replaces patterned string that represent booleans with real booleans
*
* @param \Illuminate\Support\Collection $settings
* @return \Illuminate\Support\Collection
* @param mixed $settings
* @return mixed
*/
private function restoreType($value)
private function restoreType(mixed $value)
{
$value = is_numeric($value) ? (int) $value : $value;

View File

@ -85,6 +85,7 @@ public static function convertMigrationFromGA($migrationUri) : Collection
foreach ($otpParameters->getIterator() as $key => $otp_parameters) {
try {
$parameters = array();
$parameters['otp_type'] = GAuthValueMapping::OTP_TYPE[OtpType::name($otp_parameters->getType())];
$parameters['service'] = $otp_parameters->getIssuer();
$parameters['account'] = str_replace($parameters['service'].':', '', $otp_parameters->getName());