From 218a3a78919d58ac01df24370207b563b36769a4 Mon Sep 17 00:00:00 2001 From: "noah.lancien" Date: Wed, 31 Jan 2024 09:03:18 +0000 Subject: [PATCH] phpstan --- app/Auth/CrmUserProvider.php | 12 +- app/Auth/ReactivateCustomerProvider.php | 7 +- app/Casts/AsDiscount.php | 2 - app/Casts/Ip.php | 10 +- app/Console/Commands/UserCreate.php | 14 +- .../ActivityLogs/ActivityLogsEventEnum.php | 2 + app/Enums/StaticPageType.php | 2 + app/Enums/Theme/BootstrapThemeEnum.php | 2 + app/Enums/Users/RoleEnum.php | 2 + .../Controllers/Bo/ActivityLogController.php | 2 +- app/Http/Controllers/Bo/CodeController.php | 7 +- .../Controllers/Bo/InstantWinController.php | 2 +- .../Bo/ParticipationController.php | 2 +- .../Controllers/Bo/StaticPageController.php | 2 +- app/Http/Controllers/Bo/UserController.php | 2 +- app/Http/Controllers/Controller.php | 16 +- .../Fo/Auth/ConfirmPasswordController.php | 5 +- .../Controllers/Fo/Auth/LoginController.php | 1 + .../Fo/Auth/ResetPasswordController.php | 14 +- .../Controllers/Fo/CustomerController.php | 6 +- app/Http/Controllers/Fo/HomeController.php | 16 +- .../Controllers/Fo/ParticipateController.php | 7 +- app/Http/Kernel.php | 6 +- .../Bo/BannedIps/UpdateBannedIpRequest.php | 4 +- .../Bo/Codes/GenerateCodesRequest.php | 1 + .../Bo/Products/UpdateProductRequest.php | 4 +- .../Requests/Bo/UpdateChangeOrderRequest.php | 42 +++ .../Requests/Bo/Users/StoreUserRequest.php | 1 + .../Requests/Bo/Users/UpdateUserRequest.php | 10 +- app/Http/Requests/Fo/ParticipateRequest.php | 4 +- app/Lib/Discount.php | 10 +- app/Lib/Helpers/ExceptionsHelper.php | 2 +- app/Lib/Helpers/FileStorageHelper.php | 3 +- app/Lib/Helpers/ToolboxHelper.php | 63 ++--- app/Models/ActivityLog.php | 27 +- app/Models/BannedIp.php | 4 +- app/Models/Code.php | 17 +- app/Models/Customer.php | 26 +- app/Models/FaqQuestion.php | 2 +- app/Models/FaqTheme.php | 2 +- app/Models/InstantWin.php | 2 +- app/Models/Participation.php | 8 +- app/Models/Prize.php | 4 +- app/Models/Product.php | 6 +- app/Models/Range.php | 6 +- app/Models/Settings.php | 4 +- app/Models/StaticPage.php | 4 +- app/Models/User.php | 4 +- app/Notifications/Customer/ResetPassword.php | 2 +- app/Policies/ParticipationPolicy.php | 19 +- app/Providers/AuthServiceProvider.php | 8 +- app/Providers/TranslationServiceProvider.php | 2 +- app/Rules/IsAdult.php | 2 +- app/Traits/Controllers/ChangesModelOrder.php | 10 +- .../Controllers/UpdateModelPublished.php | 3 +- app/Traits/Enums/BaseEnum.php | 6 +- app/Traits/Models/IsCachedAsCollection.php | 7 +- app/Traits/Requests/HasPicture.php | 4 +- composer.json | 5 +- composer.lock | 253 +++++++++++++++++- phpstan.neon | 13 + 61 files changed, 530 insertions(+), 205 deletions(-) create mode 100644 app/Http/Requests/Bo/UpdateChangeOrderRequest.php create mode 100644 phpstan.neon diff --git a/app/Auth/CrmUserProvider.php b/app/Auth/CrmUserProvider.php index 9eee664..43dabcc 100644 --- a/app/Auth/CrmUserProvider.php +++ b/app/Auth/CrmUserProvider.php @@ -38,7 +38,7 @@ class CrmUserProvider extends EloquentUserProvider implements UserProviderContra { // * Let laravel find a model $model = parent::retrieveByCredentials($credentials) ?? - static::retrieveTrashed($credentials); + self::retrieveTrashed($credentials); try { /** @var \LDC\LDCCRM\CrmApiV2 */ @@ -77,14 +77,14 @@ class CrmUserProvider extends EloquentUserProvider implements UserProviderContra * * @param UserContract $model * @param array $credentials - * @return boolean + * @return boolean|null * @throws \RuntimeException If model provided is not a Customer or connection to server fails. * @throws \LDC\LDCCRM\Exceptions\CrmException On CRM call error. * @throws \Exception On CRM call error. */ - public function validateCredentials(UserContract $model, array $credentials) + public function validateCredentials(UserContract $model, array $credentials): bool|null { - /** @var \Illuminate\Database\Eloquent\Model $model */ + /** @var \App\Models\Customer $model */ if (\get_class($model) !== $this->usedModel) { throw new \RuntimeException('Cannot authenticate any thing else than ' . $this->usedModel); } @@ -137,7 +137,7 @@ class CrmUserProvider extends EloquentUserProvider implements UserProviderContra */ private function createLocalCustomer(\LDC\LDCCRM\Models\Customer $crmCustomer): Model { - /** @var \Illuminate\Database\Eloquent\Model $model */ + /** @var \App\Models\Customer $model */ $model = $this->usedModel::firstOrNew([ 'email' => $crmCustomer->email ]); @@ -173,7 +173,7 @@ class CrmUserProvider extends EloquentUserProvider implements UserProviderContra } } - /** @var \App\Models\Customer|null $customer */ + /** @var \App\Models\Customer|null $query */ return $query->withTrashed()->first(); } } diff --git a/app/Auth/ReactivateCustomerProvider.php b/app/Auth/ReactivateCustomerProvider.php index 4bfa1df..b200b08 100644 --- a/app/Auth/ReactivateCustomerProvider.php +++ b/app/Auth/ReactivateCustomerProvider.php @@ -39,7 +39,7 @@ class ReactivateCustomerProvider extends EloquentUserProvider implements UserPro } } - /** @var \App\Models\Customer|null $customer */ + /** @var \App\Models\Customer|null $query */ return $query->withTrashed()->first(); } @@ -58,10 +58,9 @@ class ReactivateCustomerProvider extends EloquentUserProvider implements UserPro throw new \ErrorException('Cannot authenticate any thing else than ' . Customer::class); } - $plain = $credentials['password']; - /** @var \App\Models\Customer $customer */ - if ($this->hasher->check($plain, $customer->getAuthPassword())) { + // @phpstan-ignore-next-line + if ($this->hasher->check($credentials['password'], $customer->getAuthPassword())) { // * Restore customer return boolval($customer->restore()); } diff --git a/app/Casts/AsDiscount.php b/app/Casts/AsDiscount.php index 3310b58..9ca7789 100644 --- a/app/Casts/AsDiscount.php +++ b/app/Casts/AsDiscount.php @@ -22,8 +22,6 @@ class AsDiscount implements CastsAttributes public function get($model, string $key, $value, array $attributes): Discount { // phpcs:enable - /** @var string $class */ - /** @var array $data */ $inputData = \json_decode($value, true); return Discount::make(...\array_values($inputData)); } diff --git a/app/Casts/Ip.php b/app/Casts/Ip.php index bef7629..19087cb 100644 --- a/app/Casts/Ip.php +++ b/app/Casts/Ip.php @@ -18,7 +18,7 @@ class Ip implements CastsAttributes * @param string $key * @param mixed $value * @param array $attributes - * @return \TGet|null + * @return \IPLib\Address\AddressInterface|null * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed */ @@ -31,10 +31,10 @@ class Ip implements CastsAttributes /** * Transform the attribute to its underlying model values. * - * @param \Illuminate\Database\Eloquent\Model $model - * @param string $key - * @param \TSet|null $value - * @param array $attributes + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @param \IPLib\Address\AddressInterface|string|null $value + * @param array $attributes * @return mixed * @throws \RuntimeException If value is not or instance of \IPLib\Address\AddressInterface. * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed diff --git a/app/Console/Commands/UserCreate.php b/app/Console/Commands/UserCreate.php index 01d6ee9..811e378 100644 --- a/app/Console/Commands/UserCreate.php +++ b/app/Console/Commands/UserCreate.php @@ -21,42 +21,42 @@ class UserCreate extends Command /** * The console command description. * - * @var string + * @var string|null */ protected $description = 'Create a backend admin user'; /** * The first name of the new user. * - * @var string + * @var string|null */ protected $first_name; /** * The last name of the new user. * - * @var string + * @var string|null */ protected $last_name; /** * The email of the new user. * - * @var string + * @var string|null */ protected $email; /** * The password of the new user. * - * @var string + * @var string|null */ protected $password; /** * The role of the new user. * - * @var string + * @var string|null */ protected $role; @@ -221,7 +221,7 @@ class UserCreate extends Command $this->role = $tmp; } catch (ValidationException $e) { $this->error(sprintf( - 'Please choose from the selection', + 'Please choose from the selection %s', \implode(',', collect($e->errors())->flatten()->all()) )); continue; diff --git a/app/Enums/ActivityLogs/ActivityLogsEventEnum.php b/app/Enums/ActivityLogs/ActivityLogsEventEnum.php index ebb098c..df94759 100644 --- a/app/Enums/ActivityLogs/ActivityLogsEventEnum.php +++ b/app/Enums/ActivityLogs/ActivityLogsEventEnum.php @@ -15,6 +15,8 @@ enum ActivityLogsEventEnum: int /** * Optionnal labels definition + * + * @phpstan-ignore-next-line */ private const LABELS = [ self::created->name => 'Création', diff --git a/app/Enums/StaticPageType.php b/app/Enums/StaticPageType.php index 388da85..53add6b 100644 --- a/app/Enums/StaticPageType.php +++ b/app/Enums/StaticPageType.php @@ -14,6 +14,8 @@ enum StaticPageType: int /** * Optionnal labels definition. + * + * @phpstan-ignore-next-line */ private const LABELS = [ self::legals->name => 'Mentions légales', diff --git a/app/Enums/Theme/BootstrapThemeEnum.php b/app/Enums/Theme/BootstrapThemeEnum.php index f1f3725..0df73eb 100644 --- a/app/Enums/Theme/BootstrapThemeEnum.php +++ b/app/Enums/Theme/BootstrapThemeEnum.php @@ -13,6 +13,8 @@ enum BootstrapThemeEnum: int /** * Optionnal labels definition + * + * @phpstan-ignore-next-line */ private const LABELS = [ self::light->name => 'Light', diff --git a/app/Enums/Users/RoleEnum.php b/app/Enums/Users/RoleEnum.php index c6ad62d..48d57f4 100644 --- a/app/Enums/Users/RoleEnum.php +++ b/app/Enums/Users/RoleEnum.php @@ -14,6 +14,8 @@ enum RoleEnum: int /** * Optionnal labels definition + * + * @phpstan-ignore-next-line */ private const LABELS = [ self::conceptor->name => 'Concepteur', diff --git a/app/Http/Controllers/Bo/ActivityLogController.php b/app/Http/Controllers/Bo/ActivityLogController.php index 7f79987..957dc19 100644 --- a/app/Http/Controllers/Bo/ActivityLogController.php +++ b/app/Http/Controllers/Bo/ActivityLogController.php @@ -51,7 +51,7 @@ class ActivityLogController extends Controller /** * Show the form for editing the specified resource. * - * @param App\Models\ActivityLog $activity_log + * @param \App\Models\ActivityLog $activity_log * @return \Illuminate\Contracts\View\View */ public function show(ActivityLog $activity_log): \Illuminate\Contracts\View\View diff --git a/app/Http/Controllers/Bo/CodeController.php b/app/Http/Controllers/Bo/CodeController.php index 6841b1d..5ca1088 100644 --- a/app/Http/Controllers/Bo/CodeController.php +++ b/app/Http/Controllers/Bo/CodeController.php @@ -47,7 +47,7 @@ class CodeController extends Controller /** * Run generate codes action * - * @param \App\Http\Controllers\Bo\Codes\GenerateCodesRequest $request + * @param \App\Http\Requests\Bo\Codes\GenerateCodesRequest $request * @return \Illuminate\Http\RedirectResponse */ public function generate(GenerateCodesRequest $request): \Illuminate\Http\RedirectResponse @@ -92,10 +92,9 @@ class CodeController extends Controller return back()->with( 'success', // phpcs:ignore Generic.Files.LineLength.TooLong - 'L\'export des codes à commencé, un mail de notification sera envoyé à l\'adresse :email lorsque le traitement sera terminé.', - [ + __('L\'export des codes à commencé, un mail de notification sera envoyé à l\'adresse :emaillorsque le traitement sera terminé.', [ 'email' => config('mail.admin') - ] + ]) ); } diff --git a/app/Http/Controllers/Bo/InstantWinController.php b/app/Http/Controllers/Bo/InstantWinController.php index 7270311..5c2bad5 100644 --- a/app/Http/Controllers/Bo/InstantWinController.php +++ b/app/Http/Controllers/Bo/InstantWinController.php @@ -170,7 +170,7 @@ class WinTimeElement extends \stdClass } /** - * @property \Carbon\Carbon $time + * @property \Carbon\Carbon|\Carbon\CarbonInterface $time * Un jour dans le temps. * @property \Illuminate\Support\Collection $lots * Liste des lots tombant ce jour. diff --git a/app/Http/Controllers/Bo/ParticipationController.php b/app/Http/Controllers/Bo/ParticipationController.php index ccaf0bf..a129f8b 100644 --- a/app/Http/Controllers/Bo/ParticipationController.php +++ b/app/Http/Controllers/Bo/ParticipationController.php @@ -26,7 +26,7 @@ class ParticipationController extends Controller { $this->authorize('viewWinnerList', Participation::class); - /** @var \Illuminate\Database\Eloquent\Builder $rangeModels */ + /** @var \Illuminate\Database\Eloquent\Builder $participationModels */ $participationModels = Participation::query()->with(['customer', 'code', 'instantWin'])->whereHas('instantWin'); /** Sort columns with a query */ diff --git a/app/Http/Controllers/Bo/StaticPageController.php b/app/Http/Controllers/Bo/StaticPageController.php index b177201..e390009 100644 --- a/app/Http/Controllers/Bo/StaticPageController.php +++ b/app/Http/Controllers/Bo/StaticPageController.php @@ -56,7 +56,7 @@ class StaticPageController extends Controller /** * Show the form for editing the specified resource. * - * @param App\Models\StaticPage $static_page + * @param \App\Models\StaticPage $static_page * @return \Illuminate\Contracts\View\View */ public function edit(StaticPage $static_page): \Illuminate\Contracts\View\View diff --git a/app/Http/Controllers/Bo/UserController.php b/app/Http/Controllers/Bo/UserController.php index 094cd54..b9f7675 100644 --- a/app/Http/Controllers/Bo/UserController.php +++ b/app/Http/Controllers/Bo/UserController.php @@ -103,7 +103,7 @@ class UserController extends Controller /** * Show the form for editing the specified resource. * - * @param App\Models\User $user + * @param \App\Models\User $user * @return \Illuminate\Contracts\View\View */ public function edit(User $user): \Illuminate\Contracts\View\View diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 6284b83..133454c 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -45,6 +45,7 @@ class Controller extends BaseController return $key; } } + return $rand; } /** @@ -131,7 +132,7 @@ class Controller extends BaseController return $query; } // Get models with relation's name/label. - if (Str::endsWith($field, '_id') && $query->getModel()->has(Str::remove('_id', $field))) { + if (Str::endsWith($field, '_id')) { $query->orWhereHas(Str::remove('_id', $field), function ($queryRelation) use ($field, $search) { if (Schema::hasColumn(Str::remove('_id', $field) . 's', 'name')) { $queryRelation->where('name', 'like', '%' . $search . '%'); @@ -159,12 +160,14 @@ class Controller extends BaseController */ protected function getSearchValue(Builder $query, string $search, string $field): string|array { + $cast = $query->getModel()->getCasts()[$field] ?? null; if ( count($query->getModel()->getCasts()) and // Check if the model has casts. - isset($query->getModel()->getCasts()[$field]) and // Check if there is cast about specific field. - enum_exists($query->getModel()->getCasts()[$field]) // Check if the cast is an enum. + $cast and // Check if there is cast about specific field. + enum_exists($cast) // Check if the cast is an enum. ) { - $cases = collect($query->getModel()->getCasts()[$field]::toArray()); + // @phpstan-ignore-next-line + $cases = collect($cast::toArray()); $enum = $cases->filter(function ($item) use ($search) { return preg_match('/' . Str::lower($search) . '/', Str::lower($item->label)); }); @@ -199,10 +202,7 @@ class Controller extends BaseController Session::remove("$rName.sort_way"); } if (request()->sort_col and request()->sort_way and Schema::hasColumn($table, request()->sort_col)) { - if ( - !isset($ignore) or - (isset($ignore) and !in_array(request()->sort_col, $ignore)) - ) { + if (!in_array(request()->sort_col, $ignore)) { $query = $query->orderBy(\sprintf("$table.%s", request()->sort_col), request()->sort_way); } } elseif (Schema::hasColumn($table, 'order')) { diff --git a/app/Http/Controllers/Fo/Auth/ConfirmPasswordController.php b/app/Http/Controllers/Fo/Auth/ConfirmPasswordController.php index b55a142..f5b2138 100644 --- a/app/Http/Controllers/Fo/Auth/ConfirmPasswordController.php +++ b/app/Http/Controllers/Fo/Auth/ConfirmPasswordController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers\Fo\Auth; use App\Http\Controllers\Controller; -use Illuminate\Contracts\View\View; use Illuminate\Foundation\Auth\ConfirmsPasswords; use Illuminate\Support\Facades\Auth; @@ -25,9 +24,9 @@ class ConfirmPasswordController extends Controller /** * Display the password confirmation view. * - * @return \Illuminate\View\View + * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse */ - public function showConfirmForm(): View + public function showConfirmForm(): \Illuminate\View\View|\Illuminate\Http\RedirectResponse { if (Auth::guard('frontend')->check()) { return \response()->redirectToRoute('home'); diff --git a/app/Http/Controllers/Fo/Auth/LoginController.php b/app/Http/Controllers/Fo/Auth/LoginController.php index eb5a44e..01d94eb 100644 --- a/app/Http/Controllers/Fo/Auth/LoginController.php +++ b/app/Http/Controllers/Fo/Auth/LoginController.php @@ -65,6 +65,7 @@ class LoginController extends Controller */ protected function authenticated(Request $request, Model $user): void { + /** @var \App\Models\Customer $user */ $user->last_connection = \now(); $user->saveOrFail(); Session::flash('info', trans('Vous êtes à présent connecté')); diff --git a/app/Http/Controllers/Fo/Auth/ResetPasswordController.php b/app/Http/Controllers/Fo/Auth/ResetPasswordController.php index 56acdc2..fde2ab7 100644 --- a/app/Http/Controllers/Fo/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Fo/Auth/ResetPasswordController.php @@ -6,7 +6,6 @@ use App\Http\Controllers\Controller; use Illuminate\Auth\Events\PasswordReset; use Illuminate\Contracts\Auth\PasswordBroker; use Illuminate\Contracts\Auth\StatefulGuard; -use Illuminate\Contracts\View\View; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -49,9 +48,9 @@ class ResetPasswordController extends Controller * If no token is present, display the link request form. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return \Illuminate\Contracts\View\View */ - public function showResetForm(Request $request): View + public function showResetForm(Request $request): \Illuminate\Contracts\View\View { $token = $request->route()->parameter('token'); @@ -63,16 +62,13 @@ class ResetPasswordController extends Controller /** * Reset the given user's password. * - * @param mixed $customer - * @param mixed $password + * @param \App\Models\Customer $customer + * @param string $password * @return void * @throws \Illuminate\Validation\ValidationException If something goes wrong. */ - protected function resetPassword(mixed $customer, mixed $password): void + protected function resetPassword(\App\Models\Customer $customer, string $password): void { - /** @var \App\Models\Customer $customer */ - /** @var string $password */ - /** @var \LDC\LDCCRM\CrmApiV2 */ $crm = app('crmAPI'); diff --git a/app/Http/Controllers/Fo/CustomerController.php b/app/Http/Controllers/Fo/CustomerController.php index d103b11..1cd78ab 100644 --- a/app/Http/Controllers/Fo/CustomerController.php +++ b/app/Http/Controllers/Fo/CustomerController.php @@ -85,6 +85,7 @@ class CustomerController extends Controller 'error' => trans('Une erreur est survenue, veuillez réssayer plus tard') ]); } //end try + return back()->withInput()->withErrors(trans('Une erreur est survenue, merci de réessayer ultérieurement.')); } /** @@ -100,8 +101,9 @@ class CustomerController extends Controller $customer = auth('frontend')->user(); $winningList = $customer->participations() - ->with(['instantWin', 'discount'])->where(fn (Builder $q) => - $q->whereHas('instantWin')->orWhereHas('discount'))->get(); + ->with(['instantWin', 'discount'])->where(function (Builder $q) { + $q->whereHas('instantWin')->orWhereHas('discount'); + })->get(); return view('theme::pages.participation.winning-participations', compact('winningList')); } diff --git a/app/Http/Controllers/Fo/HomeController.php b/app/Http/Controllers/Fo/HomeController.php index 32b074e..6f3037f 100644 --- a/app/Http/Controllers/Fo/HomeController.php +++ b/app/Http/Controllers/Fo/HomeController.php @@ -7,8 +7,6 @@ use App\Models\FaqQuestion; use App\Models\FaqTheme; use App\Models\Range; use App\Models\Settings; -use Illuminate\Contracts\View\View; -use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Gate; class HomeController extends Controller @@ -18,7 +16,7 @@ class HomeController extends Controller * * @return \Illuminate\Contracts\View\View */ - public function home(): View + public function home(): \Illuminate\Contracts\View\View { if (!Gate::check('fo.gameEnabled')) { \session()->flash('warning', trans('Il manque des éléments pour que le jeu soit jouable')); @@ -33,7 +31,7 @@ class HomeController extends Controller * @phpcs:ignore Squiz.Commenting.FunctionComment.EmptyThrows * @throws \Illuminate\Http\Exceptions\HttpResponseException */ - public function showProducts(): View + public function showProducts(): \Illuminate\Contracts\View\View { // ? Show product list authorized ? if (!Gate::allows('fo.showProducts')) { @@ -49,7 +47,7 @@ class HomeController extends Controller * * @return \Illuminate\Contracts\View\View */ - public function showFaq(): View + public function showFaq(): \Illuminate\Contracts\View\View { // ? Show QA authorized ? if (!Gate::allows('fo.showFaq')) { @@ -68,9 +66,9 @@ class HomeController extends Controller /** * Show the teaser page if it is activated * - * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse + * @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse */ - public function teaser(): View | RedirectResponse + public function teaser(): \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse { /** @var \App\Models\Settings */ $settings = app(Settings::class); @@ -83,9 +81,9 @@ class HomeController extends Controller /** * Show the end game page if it is activated * - * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory|Illuminate\Http\RedirectResponse + * @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse */ - public function endGame(): View | RedirectResponse + public function endGame(): \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse { /** @var \App\Models\Settings */ $settings = app(Settings::class); diff --git a/app/Http/Controllers/Fo/ParticipateController.php b/app/Http/Controllers/Fo/ParticipateController.php index 6d88074..d4cfe27 100644 --- a/app/Http/Controllers/Fo/ParticipateController.php +++ b/app/Http/Controllers/Fo/ParticipateController.php @@ -224,7 +224,7 @@ class ParticipateController extends Controller $crmUser, $crm_customer_id, $settings->discounts_site, - $discount->web_coupon_identifiant + strval($discount->web_coupon_identifiant) ); if (Arr::get($result, 'status') === "OK") { @@ -268,10 +268,10 @@ class ParticipateController extends Controller * Fetch Crm Customer * * @param \App\Models\Customer $customer - * @return \LDC\LDCCRM\Models\Customer + * @return \LDC\LDCCRM\Models\Customer|\Illuminate\Http\RedirectResponse * @throws \Illuminate\Http\Exceptions\HttpResponseException In case of failure or customer not activated. */ - private function fetchCrmCustomer(Customer $customer): \LDC\LDCCRM\Models\Customer + private function fetchCrmCustomer(Customer $customer): \LDC\LDCCRM\Models\Customer|\Illuminate\Http\RedirectResponse { try { $crmUser = $customer->api_data; @@ -305,6 +305,7 @@ class ParticipateController extends Controller // * Retenter ? back()->with('error', trans('Une erreur est survenue, veuillez réssayer.'))->throwResponse(); } //end try + return back()->withErrors(trans('Une erreur est survenue, merci de réessayer ultérieurement.')); } /** diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index ddbaac7..245b5c6 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -11,7 +11,7 @@ class Kernel extends HttpKernel * * These middleware are run during every request to your application. * - * @var array + * @var array */ protected $middleware = [ \App\Http\Middleware\TrustHosts::class, @@ -26,7 +26,7 @@ class Kernel extends HttpKernel /** * The application's route middleware groups. * - * @var array + * @var array> */ protected $middlewareGroups = [ 'web' => [ @@ -52,7 +52,7 @@ class Kernel extends HttpKernel * * These middleware may be assigned to groups or used individually. * - * @var array + * @var array */ protected $routeMiddleware = [ 'auth' => \App\Http\Middleware\Authenticate::class, diff --git a/app/Http/Requests/Bo/BannedIps/UpdateBannedIpRequest.php b/app/Http/Requests/Bo/BannedIps/UpdateBannedIpRequest.php index 1ec9b44..fe67771 100644 --- a/app/Http/Requests/Bo/BannedIps/UpdateBannedIpRequest.php +++ b/app/Http/Requests/Bo/BannedIps/UpdateBannedIpRequest.php @@ -24,11 +24,13 @@ class UpdateBannedIpRequest extends StoreBannedIpRequest */ public function rules() { + /** @var \App\Models\BannedIp */ + $ipToBanModel = $this->route('banned_ip'); return [ 'ip' => [ 'required', 'ip', Rule::unique('banned_ips', 'ip') - ->ignore($this->route('banned_ip')->ip, 'ip') + ->ignore($ipToBanModel->ip, 'ip') ], ]; } diff --git a/app/Http/Requests/Bo/Codes/GenerateCodesRequest.php b/app/Http/Requests/Bo/Codes/GenerateCodesRequest.php index fbec424..25d76a4 100644 --- a/app/Http/Requests/Bo/Codes/GenerateCodesRequest.php +++ b/app/Http/Requests/Bo/Codes/GenerateCodesRequest.php @@ -2,6 +2,7 @@ namespace App\Http\Requests\Bo\Codes; +use App\Models\Code; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Gate; diff --git a/app/Http/Requests/Bo/Products/UpdateProductRequest.php b/app/Http/Requests/Bo/Products/UpdateProductRequest.php index b33e69c..2076dfa 100644 --- a/app/Http/Requests/Bo/Products/UpdateProductRequest.php +++ b/app/Http/Requests/Bo/Products/UpdateProductRequest.php @@ -24,11 +24,13 @@ class UpdateProductRequest extends StoreProductRequest */ public function rules() { + /** @var \App\Models\Product */ + $productModel = $this->route('product'); return array_merge(parent::rules(), [ 'ean_code' => [ 'required', 'numeric', - Rule::unique('products', 'ean_code')->ignore($this->route('product')->id), + Rule::unique('products', 'ean_code')->ignore($productModel->id), 'regex:/^[0-9]{7}$|^[0-9]{8}$|^[0-9]{13}$/', ], ]); diff --git a/app/Http/Requests/Bo/UpdateChangeOrderRequest.php b/app/Http/Requests/Bo/UpdateChangeOrderRequest.php new file mode 100644 index 0000000..d6be727 --- /dev/null +++ b/app/Http/Requests/Bo/UpdateChangeOrderRequest.php @@ -0,0 +1,42 @@ +check(); + } + + /** + * Prepare the data for validation. + * + * @return void + */ + protected function prepareForValidation(): void + { + $this->merge([ + 'direction' => $this->route('direction') === 'up' ? true : false + ]); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'direction' => 'required|boolean', + ]; + } +} diff --git a/app/Http/Requests/Bo/Users/StoreUserRequest.php b/app/Http/Requests/Bo/Users/StoreUserRequest.php index dbbef55..bf9ed2e 100644 --- a/app/Http/Requests/Bo/Users/StoreUserRequest.php +++ b/app/Http/Requests/Bo/Users/StoreUserRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\Bo\Users; use App\Enums\Users\RoleEnum; +use App\Models\User; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Gate; use Illuminate\Validation\Rules\Enum; diff --git a/app/Http/Requests/Bo/Users/UpdateUserRequest.php b/app/Http/Requests/Bo/Users/UpdateUserRequest.php index c19c740..f2468d8 100644 --- a/app/Http/Requests/Bo/Users/UpdateUserRequest.php +++ b/app/Http/Requests/Bo/Users/UpdateUserRequest.php @@ -25,14 +25,16 @@ class UpdateUserRequest extends StoreUserRequest */ protected function prepareForValidation() { + /** @var \App\Models\User */ + $userModel = $this->route('user'); $this->merge([ 'published' => $this->boolean('published'), 'password' => $this->input( 'password', - ) ?? $this->route('user')->password, + ) ?? $userModel->password, 'password_confirmation' => $this->input( 'password_confirmation' - ) ?? $this->route('user')->password + ) ?? $userModel->password ]); } @@ -43,11 +45,13 @@ class UpdateUserRequest extends StoreUserRequest */ public function rules(): array { + /** @var \App\Models\User */ + $userModel = $this->route('user'); return array_merge(parent::rules(), [ 'email' => [ 'required', 'email:rfc,strict,dns,spoof,filter', - Rule::unique('users', 'email')->ignore($this->route('user')->getRouteKey()) + Rule::unique('users', 'email')->ignore($userModel->getRouteKey()) ], 'password' => [ 'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8) diff --git a/app/Http/Requests/Fo/ParticipateRequest.php b/app/Http/Requests/Fo/ParticipateRequest.php index 7dc2297..13b0b9e 100644 --- a/app/Http/Requests/Fo/ParticipateRequest.php +++ b/app/Http/Requests/Fo/ParticipateRequest.php @@ -100,17 +100,17 @@ class ParticipateRequest extends FormRequest 'unique_code' => [ 'required', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed - function (string $attribute, $value, callable $fail) use ($settings) { + function (string $attribute, $value, callable $fail) { // ? Le Code unique est resolved ? if ($value === false or !\is_object($value) or \get_class($value) !== Code::class) { $fail(trans('Code unique incorrect, veuillez réessayer.')); return; } - /** @var \App\Models\Code $value */ /** @var \App\Models\Customer */ $customer = auth('frontend')->user(); + /** @var \App\Models\Code $value */ // * Check si l'utilisateur n'a pas déjà utilisé ce code. $query = Participation::query() ->whereHas('code', fn (Builder $q) => $q->where('id', $value->id)) diff --git a/app/Lib/Discount.php b/app/Lib/Discount.php index 0f23a6d..195c0f1 100644 --- a/app/Lib/Discount.php +++ b/app/Lib/Discount.php @@ -9,13 +9,13 @@ use Illuminate\Support\Arr; /** * Ligne de Coupon stocké dans settings * - * @property-read integer $web_coupon_identifiant EAN 13 format (Mais ne représente pas un EAN 13), + * @property integer $web_coupon_identifiant EAN 13 format (Mais ne représente pas un EAN 13), * Format utilisé dans MesBr. - * @property-read integer $percentage Pourcentage de chance de gagner le lot nombre de 1 à 100. - * @property-read integer $face_value Valeur faciale en centimes. - * @property-read string $valid_on Text valable sur.. (duplicat de ce qui est inscrit dans MesBr) + * @property integer $percentage Pourcentage de chance de gagner le lot nombre de 1 à 100. + * @property integer $face_value Valeur faciale en centimes. + * @property string $valid_on Text valable sur.. (duplicat de ce qui est inscrit dans MesBr) * Pour affichage sur la page de gain est dans le mail. - * @property-read string $picture Image locale du Coupon. + * @property string $picture Image locale du Coupon. * @package App\Lib\Inputs */ class Discount extends \stdClass implements Jsonable, Arrayable, \JsonSerializable diff --git a/app/Lib/Helpers/ExceptionsHelper.php b/app/Lib/Helpers/ExceptionsHelper.php index 4813275..30deb54 100644 --- a/app/Lib/Helpers/ExceptionsHelper.php +++ b/app/Lib/Helpers/ExceptionsHelper.php @@ -145,7 +145,7 @@ class ExceptionsHelper $traceStr .= self::handleArgs($stack); } $traceStr .= ")\n"; - } elseif (isset($stack['function'])) { + } else { $traceStr .= "{$stack['function']}("; if (isset($stack['args'])) { $traceStr .= self::handleArgs($stack); diff --git a/app/Lib/Helpers/FileStorageHelper.php b/app/Lib/Helpers/FileStorageHelper.php index 40227bf..47bd49c 100644 --- a/app/Lib/Helpers/FileStorageHelper.php +++ b/app/Lib/Helpers/FileStorageHelper.php @@ -323,7 +323,6 @@ class FileStorageHelper $private ? 'app/private/modelfiles' : 'app/public/modelfiles', $tableName, $filename, - $private ); $filename = self::getFileUniqueName($folderPath, $filename); return "{$folderPath}/{$filename}"; @@ -418,7 +417,7 @@ class FileStorageHelper $filename = Str::of($filename)->ltrim('.-'); // * Optional beautification if ($beautify) { - $filename = static::beautifyFilename($filename); + $filename = self::beautifyFilename($filename); } // * Maximize filename length to 255 bytes http://serverfault.com/a/9548/44086 /** @var string */ diff --git a/app/Lib/Helpers/ToolboxHelper.php b/app/Lib/Helpers/ToolboxHelper.php index 43770e1..748fd02 100644 --- a/app/Lib/Helpers/ToolboxHelper.php +++ b/app/Lib/Helpers/ToolboxHelper.php @@ -220,11 +220,10 @@ class ToolboxHelper $url = $match; try { $request = Request::create($url); - // If a route is match then it do not throws exception. - if ( - \parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST) && - $routes->match($request) - ) { + // Assert route matches existing routes. + $routes->match($request); + // ? Is url internal ? + if (\parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST)) { // Removes the matched url. throw ValidationException::withMessages([ $field => trans( @@ -250,14 +249,14 @@ class ToolboxHelper * @param array|string $replace * @param array|string $subject * @param integer $count - * @return array|string + * @return array|string|false */ public static function mbReplace( array|string $search, array|string $replace, array|string $subject, int &$count = 0 - ): array|string { + ): array|string|false { if (!is_array($search) && is_array($replace)) { return false; } @@ -334,9 +333,12 @@ class ToolboxHelper public static function getOriginal(Model $model, string $attribute): mixed { if (\in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model))) { + // @phpstan-ignore-next-line return $model->getTranslation( $attribute, + // @phpstan-ignore-next-line $model->getLocale(), + // @phpstan-ignore-next-line $model->useFallbackLocale() ); } @@ -406,55 +408,54 @@ class ToolboxHelper /** * Convert deeply an object to array * - * @param array|object $input + * @param mixed $input * @return array * @throws \RuntimeException If $input var is a scalar value. */ - public static function objectToArray($input): array + public static function objectToArray(mixed $input): array { // Only process if it's an object or array being passed to the function. - if (is_object($input) or is_array($input)) { - $ret = (array)$input; - foreach ($ret as &$item) { - // Recursively process EACH element only if not scalar. - $item = (is_object($item) or is_array($item)) ? - self::objectToArray($item) : $item; - } - return $ret; - } else { + if (!(is_object($input) or is_array($input))) { throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input)); } + $ret = (array)$input; + foreach ($ret as &$item) { + // Recursively process EACH element only if not scalar. + $item = (is_object($item) or is_array($item)) ? + self::objectToArray($item) : $item; + } + return $ret; } /** * Convert deeply an array to object * - * @param array|object $input + * @param mixed $input * @return object * @throws \RuntimeException If $input var is a scalar value. */ - public static function arrayToObject($input): object + public static function arrayToObject(mixed $input): object { // Only process if it's an object or array being passed to the function. - if (is_object($input) or is_array($input)) { - $ret = (object)$input; - foreach ($ret as &$item) { - // Recursively process EACH element only if not scalar. - $item = (is_object($item) or is_array($item)) ? - self::arrayToObject($item) : $item; - } - return $ret; - } else { + if (!(is_object($input) or is_array($input))) { throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input)); } + $ret = (object)$input; + foreach ($ret as &$item) { + // Recursively process EACH element only if not scalar. + $item = (is_object($item) or is_array($item)) ? + self::arrayToObject($item) : $item; + } + return $ret; } + /** * Validate picture * * @param string $attribute * @param string|null $value - * @param callback $fail + * @param callable $fail * @param object $sizes * @return void */ @@ -477,7 +478,7 @@ class ToolboxHelper 'attribute' => $attribute ])); } - if (!($dimensions = \getimagesize($fileFullPath)) or !isset($dimensions[0]) or !isset($dimensions[1])) { + if (!($dimensions = \getimagesize($fileFullPath))) { $fail(trans(':attribute impossible de valider les dimensions', [ 'attribute' => $attribute ])); diff --git a/app/Models/ActivityLog.php b/app/Models/ActivityLog.php index 0eca06b..3d44694 100644 --- a/app/Models/ActivityLog.php +++ b/app/Models/ActivityLog.php @@ -3,18 +3,17 @@ namespace App\Models; use App\Enums\ActivityLogs\ActivityLogsEventEnum; -use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Schema; /** - * @property string $model Target model. - * @property string $model_id Id of the target model. - * @property string $event Event of this activity (ActivityLogsEventEnum). - * @property string $data Changes. - * @property-read \Illuminate\Support\Carbon $created_at Created date. + * @property string $model Target model. + * @property string $model_id Id of the target model. + * @property \App\Enums\ActivityLogs\ActivityLogsEventEnum $event Event of this activity (ActivityLogsEventEnum). + * @property array $data Changes. + * @property-read \Illuminate\Support\Carbon $created_at Created date. * * @property-read \App\Models\User $user User BelongsTo relation. */ @@ -82,19 +81,20 @@ class ActivityLog extends Model $activity->model_id = $model->getKey(); $activity->event = $eventEnum; $activity->data = static::getChangedColumns($activity, $model, $eventEnum); - $activity->created_at = Carbon::now(); + // @phpstan-ignore-next-line + $activity->created_at = now(); $activity->saveOrFail(); } /** * Get old, new columns that has changed. * - * @param \self $activity + * @param self $activity * @param \Illuminate\Database\Eloquent\Model $model * @param \App\Enums\ActivityLogs\ActivityLogsEventEnum $eventEnum - * @return array|null + * @return array */ - public static function getChangedColumns(self $activity, Model $model, ActivityLogsEventEnum $eventEnum): array|null + public static function getChangedColumns(self $activity, Model $model, ActivityLogsEventEnum $eventEnum): array { $modelClassName = $activity->model_class; /** Get type of each fields of the target model */ @@ -109,10 +109,11 @@ class ActivityLog extends Model return Schema::getColumnType($targetModel->getTable(), $fieldIndex); })->toArray(); // phpcs:enable + /** Return old, new and type of values changed */ + return ($eventEnum === ActivityLogsEventEnum::updated) ? + array_intersect_key($targetModelTypes, $model->getChanges()) : []; } - /** Return old, new and type of values changed */ - return ($eventEnum === ActivityLogsEventEnum::updated) ? - array_intersect_key($targetModelTypes, $model->getChanges()) : null; + return []; } // * RELATIONS diff --git a/app/Models/BannedIp.php b/app/Models/BannedIp.php index dff3cb4..1f10fe3 100644 --- a/app/Models/BannedIp.php +++ b/app/Models/BannedIp.php @@ -27,14 +27,14 @@ class BannedIp extends Model /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = ['ip']; /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'ip' => Ip::class diff --git a/app/Models/Code.php b/app/Models/Code.php index 9ff810e..9a49fba 100644 --- a/app/Models/Code.php +++ b/app/Models/Code.php @@ -18,8 +18,8 @@ use Kwaadpepper\Serial\SerialCaster; * @property-read string|null $code_unique The unique code * @property-read boolean $has_been_used_too_many_times Has this code been used too many times ? * - * @method public static function intToSerial($int) Generate a serial from an int. - * @method public static function serialToInt($serial) Get an int from a serial. + * @method static mixed intToSerial($int) Generate a serial from an int. + * @method static mixed serialToInt($serial) Get an int from a serial. * * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Participation[] $participations * Associated participations. @@ -36,7 +36,7 @@ class Code extends Model /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = [ 'code_exported', @@ -46,7 +46,7 @@ class Code extends Model /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'code_exported' => 'bool', @@ -91,13 +91,13 @@ class Code extends Model /** * Generate code_unique attribute * - * @return string|null + * @return \Illuminate\Database\Eloquent\Casts\Attribute */ public function codeUnique(): Attribute { return Attribute::make( get: function (): ?string { - if (!$this->id or !\is_integer($this->id) or $this->id < 1) { + if (!$this->id or $this->id < 1) { return null; } return self::intToSerial($this->id); @@ -120,7 +120,7 @@ class Code extends Model * * @param integer $int * @return string The serial - * @throws SerialCasterException If an error happens du to config. + * @throws \Kwaadpepper\Serial\Exceptions\SerialCasterException If an error happens du to config. */ public static function intToSerial(int $int): string { @@ -137,7 +137,8 @@ class Code extends Model * * @param string $serial * @return integer The ID represented - * @throws SerialCasterException If an error happens due to config or wrong serial is given. + * @throws \Kwaadpepper\Serial\Exceptions\SerialCasterException If an error happens due to config or + * wrong serial is given. */ public static function serialToInt(string $serial): int { diff --git a/app/Models/Customer.php b/app/Models/Customer.php index f0aa9ba..342ab6a 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -27,7 +27,7 @@ use LDC\LDCCRM\Models\Customer as CrmCustomer; * @property string $email Email. * @property string $hashcode Hashcode. * @property string $remember_token Remember token. - * @property \LDC\LDCCRM\Models\Customer api_data + * @property \LDC\LDCCRM\Models\Customer $api_data * @property \Carbon\Carbon|null $email_verified_at * @property \Carbon\Carbon|null $last_connection Date de derniere connexion, (pour les questions oblig CRM). * @property-read \Carbon\Carbon $created_at Created date. @@ -69,10 +69,10 @@ class Customer extends Authenticatable implements MustVerifyEmail { // * EVENT CLOSURES. static::creating(function (self $model) { - static::assertEmailIsUnique($model->id, $model->email); + self::assertEmailIsUnique($model->id, $model->email); }); static::updating(function (self $model) { - static::assertEmailIsUnique($model->id, $model->email); + self::assertEmailIsUnique($model->id, $model->email); }); static::deleting(function () { throw new \RuntimeException('This cannot be done à cause de MesBr'); @@ -115,9 +115,9 @@ class Customer extends Authenticatable implements MustVerifyEmail * * ! Les comptes non activés depuis une semaine ou les comptes supprimés depuis une semaine. * - * @return \Illuminate\Database\Query\Builder + * @return \Illuminate\Database\Eloquent\Builder */ - public function prunable(): Builder + public function prunable(): \Illuminate\Database\Eloquent\Builder { return static::query()->where(function (Builder $q) { $q->where('updated_at', '<=', now()->subWeek()) @@ -189,7 +189,7 @@ class Customer extends Authenticatable implements MustVerifyEmail return $this->api_data->activate() && parent::markEmailAsVerified(); } catch (ApiErrorException $e) { if ($e->getApiError()->equals(ApiError::customerAlreadyActive())) { - return true && parent::markEmailAsVerified(); + return parent::markEmailAsVerified(); } throw $e; } @@ -232,7 +232,7 @@ class Customer extends Authenticatable implements MustVerifyEmail } /** @var static|null $loggedCustomer */ $loggedCustomer = \auth('frontend')->user(); - $isLogged = \optional($loggedCustomer)->id === $this->id and !\is_null($this->id); + $isLogged = \optional($loggedCustomer)->id === $this->id and !empty($this->id); if ($isLogged) { \auth('frontend')->logout(); } @@ -277,7 +277,7 @@ class Customer extends Authenticatable implements MustVerifyEmail public function updateApiData(array $data): bool { // phpcs:enable - /** @var \LDC\LDCCRM\Models\Customer */ + /** @var \LDC\LDCCRM\Models\Customer|null $crmCustomer */ $crmCustomer = $this->api_data; if (!$crmCustomer) { throw new CrmException('CRM get Customer returned null'); @@ -308,10 +308,10 @@ class Customer extends Authenticatable implements MustVerifyEmail * Put customer crm part in cache * * @template T - * @param string $uuid The customer uuid. - * @param string $part_name The part name for the cache path. - * @param \Closure(void):T $part The part to cache. - * @param integer $ttl Time to live in seconds for the cache part. + * @param string $uuid The customer uuid. + * @param string $part_name The part name for the cache path. + * @param \Closure():T $part The part to cache. + * @param integer $ttl Time to live in seconds for the cache part. * @return T * @phpcs:disable Squiz.Commenting.FunctionComment.IncorrectTypeHint */ @@ -351,7 +351,7 @@ class Customer extends Authenticatable implements MustVerifyEmail if ($this->hashcode) { return collect(array_merge( parent::toArray(), - (array)$this->apiData + (array)$this->api_data ))->intersectByKeys([ 'email' => '', 'firstname' => '', diff --git a/app/Models/FaqQuestion.php b/app/Models/FaqQuestion.php index ef3854a..0039e4d 100644 --- a/app/Models/FaqQuestion.php +++ b/app/Models/FaqQuestion.php @@ -25,7 +25,7 @@ class FaqQuestion extends Model /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = [ 'question', diff --git a/app/Models/FaqTheme.php b/app/Models/FaqTheme.php index 7acf5fe..3511e59 100644 --- a/app/Models/FaqTheme.php +++ b/app/Models/FaqTheme.php @@ -27,7 +27,7 @@ class FaqTheme extends Model /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = ['name']; diff --git a/app/Models/InstantWin.php b/app/Models/InstantWin.php index 35e9052..06fce88 100644 --- a/app/Models/InstantWin.php +++ b/app/Models/InstantWin.php @@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * InstantWin. * - * @property \Illuminate\Support\Carbon $available_at When the instant win will be available. + * @property \Carbon\Carbon $available_at When the instant win will be available. * * @property-read \App\Models\Prize $prize Associated prize. * @property-read \App\Models\Participation $participation Associated participation. diff --git a/app/Models/Participation.php b/app/Models/Participation.php index f30aaf2..106c02b 100644 --- a/app/Models/Participation.php +++ b/app/Models/Participation.php @@ -37,7 +37,7 @@ class Participation extends Model /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = [ 'barcode', 'ticket', 'sticker', @@ -46,7 +46,7 @@ class Participation extends Model /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'ip' => Ip::class, @@ -211,10 +211,10 @@ class Participation extends Model /** * Common methods function. * - * @param \Illuminate\Database\Eloquent\Model $model + * @param self $model * @return void */ - private static function manageFields(Model $model) + private static function manageFields(self $model) { if ($model->barcode) { $model->barcode = FileStorageHelper::storeFile($model, $model->barcode, true); diff --git a/app/Models/Prize.php b/app/Models/Prize.php index e268c93..1ce8b02 100644 --- a/app/Models/Prize.php +++ b/app/Models/Prize.php @@ -35,7 +35,7 @@ class Prize extends Model /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = [ 'label', @@ -112,7 +112,7 @@ class Prize extends Model /** * HasMany InstantWin relation * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function instantWins(): HasMany { diff --git a/app/Models/Product.php b/app/Models/Product.php index cef4235..81ae005 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -32,7 +32,7 @@ class Product extends Model /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = [ 'name', @@ -74,10 +74,10 @@ class Product extends Model /** * Common methods function. * - * @param \Illuminate\Database\Eloquent\Model $model + * @param self $model * @return void */ - private static function manageFields(Model $model) + private static function manageFields(self $model) { $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); } diff --git a/app/Models/Range.php b/app/Models/Range.php index 9f3d159..be3dea5 100644 --- a/app/Models/Range.php +++ b/app/Models/Range.php @@ -25,7 +25,7 @@ class Range extends Model /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = [ 'name', @@ -60,10 +60,10 @@ class Range extends Model /** * Common methods function. * - * @param \Illuminate\Database\Eloquent\Model $model + * @param self $model * @return void */ - private static function manageFields(Model $model) + private static function manageFields(self $model) { $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); } diff --git a/app/Models/Settings.php b/app/Models/Settings.php index f6e0259..96cb133 100644 --- a/app/Models/Settings.php +++ b/app/Models/Settings.php @@ -52,7 +52,7 @@ class Settings extends Model /** * The attributes that are mass assignable. * - * @var array + * @var array */ protected $fillable = [ 'name', @@ -80,7 +80,7 @@ class Settings extends Model /** * The attributes that should be cast to native types. * - * @var array + * @var array */ protected $casts = [ 'notify_prize_sent' => 'bool', diff --git a/app/Models/StaticPage.php b/app/Models/StaticPage.php index 2255d7c..1a0aa19 100644 --- a/app/Models/StaticPage.php +++ b/app/Models/StaticPage.php @@ -56,14 +56,14 @@ class StaticPage extends Model { static::creating(function (self $model) { // * ASSERTIONS - static::assertTitleIsUnique($model->title); + self::assertTitleIsUnique($model->title); // * CHANGES $model->slug = Str::slug($model->title); }); static::updating(function (self $model) { // * ASSERTIONS - static::assertTitleIsUnique($model->title, $model->id); + self::assertTitleIsUnique($model->title, $model->id); // * CHANGES $model->slug = Str::slug($model->title); diff --git a/app/Models/User.php b/app/Models/User.php index a31dd48..fae2f5e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -75,7 +75,7 @@ class User extends Authenticatable protected static function booted(): void { static::creating(function (self $model) { - static::updatePassword($model); + self::updatePassword($model); // * Prevent user elevation privileges throw_if( auth('backend')->user() and auth('backend')->user()->role->value() > $model->role->value(), @@ -83,7 +83,7 @@ class User extends Authenticatable ); }); static::updating(function (self $model) { - static::updatePassword($model); + self::updatePassword($model); if (optional(auth('backend')->user())->getKey() === $model->getKey()) { \validator( ['published' => $model->published], diff --git a/app/Notifications/Customer/ResetPassword.php b/app/Notifications/Customer/ResetPassword.php index f0a5ecd..65f1ea0 100644 --- a/app/Notifications/Customer/ResetPassword.php +++ b/app/Notifications/Customer/ResetPassword.php @@ -12,7 +12,7 @@ class ResetPassword extends NotificationsResetPassword /** * The callback that should be used to create the reset password URL. * - * @var \Closure|null + * @var (\Closure(mixed, string): string)|null */ public static $createUrlCallback; diff --git a/app/Policies/ParticipationPolicy.php b/app/Policies/ParticipationPolicy.php index 5c09e2c..47eab9a 100644 --- a/app/Policies/ParticipationPolicy.php +++ b/app/Policies/ParticipationPolicy.php @@ -52,7 +52,9 @@ class ParticipationPolicy fn (Builder $q) => $q->where('ip', app('clientIp')) )->count() < $settings->nb_participation_ip); } - $playerCanParticipate = ($playerCanParticipateAccount && $playerCanParticipateIp) ? true : false; + $playerCanParticipate = (!empty($playerCanParticipateAccount) && !empty($playerCanParticipateIp)) ? + true : + false; // * Deny banned IP, Check did not participate too much return !(bool)BannedIp::getCached() @@ -72,8 +74,9 @@ class ParticipationPolicy // * Recettage return true; } - return (bool)$authUser->participations()->where(fn (Builder $q) => - $q->whereHas('instantWin')->orWhereHas('discount'))->count(); + return (bool)$authUser->participations()->where(function (Builder $q) { + $q->whereHas('instantWin')->orWhereHas('discount'); + })->count(); } /** @@ -94,10 +97,12 @@ class ParticipationPolicy fn (Builder $q) => $q->where('id', $authUser->id) )->where('id', $model->id)->whereHas('instantWin') - ->where(fn (Builder $q) => $q->whereNull( - ['sticker', 'ticket', 'barcode'], - 'or' - ))->exists(); + ->where(function (Builder $q) { + $q->whereNull( + ['sticker', 'ticket', 'barcode'], + 'or' + ); + })->exists(); } /** diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index f07f12c..05ad6b6 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -10,7 +10,9 @@ use App\Models\Product; use App\Models\Settings; use App\Models\User; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Gate; +use Illuminate\Support\Facades\View; class AuthServiceProvider extends ServiceProvider { @@ -43,14 +45,14 @@ class AuthServiceProvider extends ServiceProvider Gate::define( 'fo.showProducts', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass - fn (User|Customer|null $user) => view()->exists('theme::pages.products') and + fn (User|Customer|null $user) => View::exists('theme::pages.products') and (bool)Product::getCached()->count() ); Gate::define( 'fo.showFaq', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass - fn (User|Customer|null $user) => view()->exists('theme::pages.faq') and + fn (User|Customer|null $user) => View::exists('theme::pages.faq') and (bool)FaqQuestion::getCached()->count() ); @@ -64,7 +66,7 @@ class AuthServiceProvider extends ServiceProvider } ); - $this->app->auth->provider('crm', function ($app, array $config) { + Auth::provider('crm', function ($app, array $config) { return new CrmUserProvider($app['hash'], $config['model']); }); } diff --git a/app/Providers/TranslationServiceProvider.php b/app/Providers/TranslationServiceProvider.php index b3e3f4b..4849099 100644 --- a/app/Providers/TranslationServiceProvider.php +++ b/app/Providers/TranslationServiceProvider.php @@ -32,7 +32,7 @@ class TranslationServiceProvider extends ServiceProvider /** * Gather provided langs checking from files * - * @return \Illuminate\Support\Collection + * @return \Illuminate\Support\Collection */ private function collectLocalesStrings(): Collection { diff --git a/app/Rules/IsAdult.php b/app/Rules/IsAdult.php index 4bbe241..7bcb192 100644 --- a/app/Rules/IsAdult.php +++ b/app/Rules/IsAdult.php @@ -50,7 +50,7 @@ class IsAdult implements ValidationRule $d = Carbon::createFromFormat('d/m/Y', $value); } // * Could not parse date. - if (!$d) { + if (!isset($d)) { throw new \RuntimeException("Could not parse date {$value} for attribute '{$attribute}'."); } if (!$d->lessThanOrEqualTo($MJ)) { diff --git a/app/Traits/Controllers/ChangesModelOrder.php b/app/Traits/Controllers/ChangesModelOrder.php index 51af5ba..1797d90 100644 --- a/app/Traits/Controllers/ChangesModelOrder.php +++ b/app/Traits/Controllers/ChangesModelOrder.php @@ -37,18 +37,16 @@ trait ChangesModelOrder return DB::transaction(function () use ($request, $className, $model) { /** @var \Illuminate\Database\Eloquent\Model|null */ - $tmp = $className::where('order', $request->direction ? '<' : '>', $model->order) + $tmp = $className::where('order', $request->direction ? '<' : '>', $model->getOriginal('order')) ->orderBy('order', $request->direction ? 'DESC' : 'ASC')->first(); if (!$tmp) { return back()->with('error', trans('crud.messages.order_not_changed')); } - $newOrder = $tmp->order; - $tmp->order = $model->order; - $model->order = $newOrder; - $tmp->saveOrFail(); - $model->saveOrFail(); + $newOrder = $tmp->getOriginal('order'); + $tmp->update(['order' => $model->getOriginal('order')]); + $model->update(['order' => $newOrder]); Session::flash('success', trans('crud.messages.order_changed')); return back(); diff --git a/app/Traits/Controllers/UpdateModelPublished.php b/app/Traits/Controllers/UpdateModelPublished.php index 4ca47df..05691b1 100644 --- a/app/Traits/Controllers/UpdateModelPublished.php +++ b/app/Traits/Controllers/UpdateModelPublished.php @@ -19,8 +19,7 @@ trait UpdateModelPublished */ public function changePublished(Model $model) { - $model->published = !$model->published; - $model->saveOrFail(); + $model->update(['published' => !$model->getOriginal('published')]); return redirect()->back()->with('success', trans(__('crud.messages.publish_status_saved'))); } } diff --git a/app/Traits/Enums/BaseEnum.php b/app/Traits/Enums/BaseEnum.php index 559b1ee..d6016cb 100644 --- a/app/Traits/Enums/BaseEnum.php +++ b/app/Traits/Enums/BaseEnum.php @@ -118,9 +118,9 @@ trait BaseEnum /** * Fetch enum using value. * - * @param \App\Traits\Enums\BaseEnum|integer|string $value - * @param string $field - * @return \App\Traits\Enums\BaseEnum|null + * @param self|integer|string $value + * @param string $field + * @return self|null */ public static function make(self|int|string $value, string $field = 'value'): self|null { diff --git a/app/Traits/Models/IsCachedAsCollection.php b/app/Traits/Models/IsCachedAsCollection.php index 87ed939..b946c24 100644 --- a/app/Traits/Models/IsCachedAsCollection.php +++ b/app/Traits/Models/IsCachedAsCollection.php @@ -10,7 +10,8 @@ use Illuminate\Support\Facades\Cache; /** * ! Use this only on limited elements, (not on tags, or products, or posts for ex.) * - * @property private static array $cacheConditions Eloquent condition to cache elements (to be used in where statement). + * @property array $cacheConditions + * Eloquent condition to cache elements (to be used in where statement). */ trait IsCachedAsCollection { @@ -18,7 +19,7 @@ trait IsCachedAsCollection * Get all available instances from cache. * If cache was reset, it will fetch them from DB. * - * @return \Illuminate\Database\Eloquent\Collection + * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection<(int|string), mixed> */ public static function getCached(): Collection { @@ -52,7 +53,7 @@ trait IsCachedAsCollection { $conditions = []; if (property_exists(get_called_class(), 'cacheConditions')) { - $conditions = collect(static::${'cacheConditions'})->all(); + $conditions = collect(get_called_class()::${'cacheConditions'})->all(); } Cache::put(static::getCacheKeyName(), static::queryCached(static::query()) ->where($conditions)->get() diff --git a/app/Traits/Requests/HasPicture.php b/app/Traits/Requests/HasPicture.php index 5cc57dd..88806ad 100644 --- a/app/Traits/Requests/HasPicture.php +++ b/app/Traits/Requests/HasPicture.php @@ -66,7 +66,7 @@ trait HasPicture $name => [ !$nullable ? 'required' : 'nullable', function (string $attribute, $value, callable $fail) use ($sizes) { - return ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes); + ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes); } ] ]; @@ -101,7 +101,7 @@ trait HasPicture "{$name}Validate.*" => [ 'required', function (string $attribute, $value, callable $fail) use ($sizes) { - return $this->validatePicture($attribute, $value, $fail, $sizes); + ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes); } ] ]; diff --git a/composer.json b/composer.json index b4cb6a7..bec50ca 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "uwil/gen-game-web", - "version": "2.2.7", + "version": "2.2.8", "type": "project", "description": "Game generator", "support": { @@ -34,6 +34,7 @@ "fakerphp/faker": "^1.9.1", "kitloong/laravel-migrations-generator": "^6.8", "krlove/eloquent-model-generator": "dev-l10-compatibility", + "larastan/larastan": "^2.8", "laravel-lang/common": "^4.0", "laravel/pint": "^1.0", "laravel/sail": "^1.18", @@ -103,4 +104,4 @@ }, "minimum-stability": "stable", "prefer-stable": true -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index d9ed141..6ba0b2e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fb04367922e600ae7eeebd46aa7521bc", + "content-hash": "a19494fb3b2f363a386a09f439ba9d5b", "packages": [ { "name": "axlon/laravel-postal-code-validation", @@ -9595,6 +9595,107 @@ }, "time": "2023-01-30T20:15:06+00:00" }, + { + "name": "larastan/larastan", + "version": "v2.8.1", + "source": { + "type": "git", + "url": "https://github.com/larastan/larastan.git", + "reference": "b7cc6a29c457a7d4f3de90466392ae9ad3e17022" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/larastan/larastan/zipball/b7cc6a29c457a7d4f3de90466392ae9ad3e17022", + "reference": "b7cc6a29c457a7d4f3de90466392ae9ad3e17022", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/console": "^9.52.16 || ^10.28.0 || ^11.0", + "illuminate/container": "^9.52.16 || ^10.28.0 || ^11.0", + "illuminate/contracts": "^9.52.16 || ^10.28.0 || ^11.0", + "illuminate/database": "^9.52.16 || ^10.28.0 || ^11.0", + "illuminate/http": "^9.52.16 || ^10.28.0 || ^11.0", + "illuminate/pipeline": "^9.52.16 || ^10.28.0 || ^11.0", + "illuminate/support": "^9.52.16 || ^10.28.0 || ^11.0", + "php": "^8.0.2", + "phpmyadmin/sql-parser": "^5.8.2", + "phpstan/phpstan": "^1.10.50" + }, + "require-dev": { + "nikic/php-parser": "^4.17.1", + "orchestra/canvas": "^7.11.1 || ^8.11.0 || ^9.0.0", + "orchestra/testbench": "^7.33.0 || ^8.13.0 || ^9.0.0", + "phpunit/phpunit": "^9.6.13 || ^10.5" + }, + "suggest": { + "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" + }, + "type": "phpstan-extension", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + }, + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "Larastan\\Larastan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Can Vural", + "email": "can9119@gmail.com" + }, + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "larastan", + "laravel", + "package", + "php", + "static analysis" + ], + "support": { + "issues": "https://github.com/larastan/larastan/issues", + "source": "https://github.com/larastan/larastan/tree/v2.8.1" + }, + "funding": [ + { + "url": "https://www.paypal.com/paypalme/enunomaduro", + "type": "custom" + }, + { + "url": "https://github.com/canvural", + "type": "github" + }, + { + "url": "https://github.com/nunomaduro", + "type": "github" + }, + { + "url": "https://www.patreon.com/nunomaduro", + "type": "patreon" + } + ], + "time": "2024-01-08T09:11:17+00:00" + }, { "name": "laravel-lang/attributes", "version": "2.5.1", @@ -10666,6 +10767,94 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpmyadmin/sql-parser", + "version": "5.9.0", + "source": { + "type": "git", + "url": "https://github.com/phpmyadmin/sql-parser.git", + "reference": "011fa18a4e55591fac6545a821921dd1d61c6984" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/011fa18a4e55591fac6545a821921dd1d61c6984", + "reference": "011fa18a4e55591fac6545a821921dd1d61c6984", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "symfony/polyfill-mbstring": "^1.3", + "symfony/polyfill-php80": "^1.16" + }, + "conflict": { + "phpmyadmin/motranslator": "<3.0" + }, + "require-dev": { + "phpbench/phpbench": "^1.1", + "phpmyadmin/coding-standard": "^3.0", + "phpmyadmin/motranslator": "^4.0 || ^5.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.9.12", + "phpstan/phpstan-phpunit": "^1.3.3", + "phpunit/php-code-coverage": "*", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "^0.16.1", + "vimeo/psalm": "^4.11", + "zumba/json-serializer": "~3.0.2" + }, + "suggest": { + "ext-mbstring": "For best performance", + "phpmyadmin/motranslator": "Translate messages to your favorite locale" + }, + "bin": [ + "bin/highlight-query", + "bin/lint-query", + "bin/sql-parser", + "bin/tokenize-query" + ], + "type": "library", + "autoload": { + "psr-4": { + "PhpMyAdmin\\SqlParser\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "The phpMyAdmin Team", + "email": "developers@phpmyadmin.net", + "homepage": "https://www.phpmyadmin.net/team/" + } + ], + "description": "A validating SQL lexer and parser with a focus on MySQL dialect.", + "homepage": "https://github.com/phpmyadmin/sql-parser", + "keywords": [ + "analysis", + "lexer", + "parser", + "query linter", + "sql", + "sql lexer", + "sql linter", + "sql parser", + "sql syntax highlighter", + "sql tokenizer" + ], + "support": { + "issues": "https://github.com/phpmyadmin/sql-parser/issues", + "source": "https://github.com/phpmyadmin/sql-parser" + }, + "funding": [ + { + "url": "https://www.phpmyadmin.net/donate/", + "type": "other" + } + ], + "time": "2024-01-20T20:34:02+00:00" + }, { "name": "phpstan/phpdoc-parser", "version": "1.24.3", @@ -10713,6 +10902,68 @@ }, "time": "2023-11-18T20:15:32+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.57", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1627b1d03446904aaa77593f370c5201d2ecc34e", + "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2024-01-24T11:51:34+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "10.1.8", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b10f8f8 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +includes: + - vendor/larastan/larastan/extension.neon + +parameters: + + paths: + - app/ + + excludePaths: + - app/Lib/vendor/ + + # Level 9 is the highest level + level: 5