From 4a4f5d7880a5c16ea5a89c6c6ff644a43df7e771 Mon Sep 17 00:00:00 2001 From: Karlo Mikus Date: Wed, 15 Oct 2025 20:30:54 +0200 Subject: [PATCH 1/4] Rector changes --- app/BarContext.php | 4 +- app/Console/Commands/BarFullBackup.php | 2 +- app/Console/Commands/BarMaintenance.php | 2 +- app/Exceptions/Handler.php | 20 ++-- app/External/Export/ToDataPack.php | 2 +- app/External/Export/ToFullBackup.php | 2 +- app/External/Export/ToRecipeType.php | 2 +- app/External/Import/FromDataPack.php | 18 ++-- app/External/Import/FromJsonSchema.php | 2 +- app/External/Matcher.php | 8 +- app/External/Model/Calculator.php | 20 ++-- app/External/Model/Cocktail.php | 12 +-- app/External/Model/CocktailIngredient.php | 4 +- app/External/Model/Ingredient.php | 12 +-- app/Http/Controllers/AuthController.php | 4 +- app/Http/Controllers/CocktailController.php | 2 +- app/Http/Controllers/ImageController.php | 2 +- app/Http/Controllers/ImportController.php | 2 +- app/Http/Controllers/IngredientController.php | 12 +-- app/Http/Controllers/UsersController.php | 2 +- app/Http/Middleware/CheckMetricsAccess.php | 4 +- .../Middleware/EnsureRequestHasBarQuery.php | 8 +- app/Http/Resources/AmountFormats.php | 4 +- app/Http/Resources/CocktailBasicResource.php | 4 +- app/Http/Resources/CocktailResource.php | 28 +++--- app/Http/Resources/CollectionResource.php | 4 +- .../Resources/ExploreCocktailResource.php | 50 +++++----- .../Resources/IngredientBasicResource.php | 4 +- app/Http/Resources/IngredientResource.php | 4 +- app/Http/Resources/MenuPublicResource.php | 30 +++--- app/Http/Resources/MenuResource.php | 26 +++-- .../Resources/Public/CocktailResource.php | 38 +++----- app/Http/Resources/UserResource.php | 12 +-- app/Metrics/MetricsServiceProvider.php | 4 +- app/Metrics/TotalBars.php | 10 +- app/Models/Cocktail.php | 16 +-- app/Models/Concerns/HasImages.php | 2 +- app/Models/FileToken.php | 2 +- .../BaseMaterializedPathRelation.php | 6 +- app/Models/Relations/HasManyAncestors.php | 4 +- app/Models/Relations/HasManyDescendants.php | 4 +- app/OpenAPI/Schemas/BarRequest.php | 2 +- app/Providers/AppServiceProvider.php | 2 +- app/Providers/HorizonServiceProvider.php | 8 +- app/Providers/RouteServiceProvider.php | 20 ++-- app/Scraper/AbstractSite.php | 40 ++++---- app/Scraper/Concerns/ReadsHTMLSchema.php | 2 +- app/Scraper/Sites/CocktailParty.php | 8 +- app/Scraper/Sites/DiffordsGuide.php | 2 +- app/Scraper/Sites/EricsCocktailGuide.php | 4 +- app/Scraper/Sites/HausAlpenz.php | 8 +- app/Scraper/Sites/ImbibeMagazine.php | 12 +-- app/Scraper/Sites/LiberAndCo.php | 4 +- app/Scraper/Sites/LiquorCom.php | 2 +- app/Scraper/Sites/MakeMeACocktail.php | 2 +- app/Scraper/Sites/PunchDrink.php | 4 +- app/Scraper/Sites/SteveTheBartender.php | 6 +- app/Scraper/Sites/TuxedoNo2.php | 6 +- app/Services/Auth/PocketIdProvider.php | 2 +- app/Services/Auth/SSOService.php | 4 +- app/Services/BarOptimizerService.php | 4 +- app/Services/CocktailService.php | 10 +- app/Services/Feeds/RecipeFeedsService.php | 4 +- app/Services/Image/ImageService.php | 2 +- app/Services/IngredientService.php | 10 +- app/Utils.php | 4 +- app/ZipUtils.php | 4 +- composer.json | 4 +- composer.lock | 97 ++++++++++++++++++- config/bar-assistant.php | 4 +- config/sanctum.php | 2 +- rector.php | 18 ++++ routes/api.php | 10 +- routes/web.php | 8 +- tests/Feature/Http/AuthControllerTest.php | 8 +- .../Http/ShoppingListControllerTest.php | 12 +-- tests/Feature/Http/UsersControllerTest.php | 2 +- 77 files changed, 364 insertions(+), 375 deletions(-) create mode 100644 rector.php diff --git a/app/BarContext.php b/app/BarContext.php index 11a0b253..b840fd3f 100644 --- a/app/BarContext.php +++ b/app/BarContext.php @@ -11,9 +11,9 @@ * Combined with bar() helper method you can always get the current requested Bar model. * @see \Kami\Cocktail\Http\Middleware\EnsureRequestHasBarQuery */ -final class BarContext +final readonly class BarContext { - public function __construct(private readonly Bar $currentBar) + public function __construct(private Bar $currentBar) { } diff --git a/app/Console/Commands/BarFullBackup.php b/app/Console/Commands/BarFullBackup.php index f2d44123..7c550432 100644 --- a/app/Console/Commands/BarFullBackup.php +++ b/app/Console/Commands/BarFullBackup.php @@ -23,7 +23,7 @@ class BarFullBackup extends Command */ protected $description = 'Create a .zip file with the full backup of your Bar Assistant instance data'; - public function __construct(private ToFullBackup $exporter) + public function __construct(private readonly ToFullBackup $exporter) { parent::__construct(); } diff --git a/app/Console/Commands/BarMaintenance.php b/app/Console/Commands/BarMaintenance.php index 5e229d7f..572c0fd4 100644 --- a/app/Console/Commands/BarMaintenance.php +++ b/app/Console/Commands/BarMaintenance.php @@ -29,7 +29,7 @@ class BarMaintenance extends Command */ protected $description = 'This will remove unused images, update missing ABVs, fix ingredient sort and refresh cache'; - private Filesystem $disk; + private readonly Filesystem $disk; public function __construct() { diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index af1d1529..72cc4468 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -60,18 +60,14 @@ public function register() } }); - $this->renderable(function (NotFoundHttpException $e, $request) { - return response()->json([ - 'type' => 'api_error', - 'message' => 'Resource not found.', - ], 404); - }); + $this->renderable(fn(NotFoundHttpException $e, $request) => response()->json([ + 'type' => 'api_error', + 'message' => 'Resource not found.', + ], 404)); - $this->renderable(function (MethodNotAllowedHttpException $e, $request) { - return response()->json([ - 'type' => 'api_error', - 'message' => $e->getMessage(), - ], 405); - }); + $this->renderable(fn(MethodNotAllowedHttpException $e, $request) => response()->json([ + 'type' => 'api_error', + 'message' => $e->getMessage(), + ], 405)); } } diff --git a/app/External/Export/ToDataPack.php b/app/External/Export/ToDataPack.php index 81dedbce..ee424a3a 100644 --- a/app/External/Export/ToDataPack.php +++ b/app/External/Export/ToDataPack.php @@ -48,7 +48,7 @@ public function process(int $barId, ?string $filename = null, ForceUnitConvertEn $meta = [ 'version' => $version, 'date' => Carbon::now()->toAtomString(), - 'called_from' => __CLASS__, + 'called_from' => self::class, ]; File::ensureDirectoryExists($this->file->disk('exports')->path((string) $barId)); diff --git a/app/External/Export/ToFullBackup.php b/app/External/Export/ToFullBackup.php index f0aec593..8548b019 100644 --- a/app/External/Export/ToFullBackup.php +++ b/app/External/Export/ToFullBackup.php @@ -23,7 +23,7 @@ public function process(?string $exportPath = null): string $meta = [ 'version' => $version, 'date' => Carbon::now()->toAtomString(), - 'called_from' => __CLASS__, + 'called_from' => self::class, ]; $zip = new ZipArchive(); diff --git a/app/External/Export/ToRecipeType.php b/app/External/Export/ToRecipeType.php index 70af93f7..1457d01c 100644 --- a/app/External/Export/ToRecipeType.php +++ b/app/External/Export/ToRecipeType.php @@ -38,7 +38,7 @@ public function process(int $barId, ?string $filename = null, ExportTypeEnum $ty $meta = [ 'version' => $version, 'date' => Carbon::now()->toAtomString(), - 'called_from' => __CLASS__, + 'called_from' => self::class, 'type' => $type->value, 'bar_id' => $barId, 'schema' => $type === ExportTypeEnum::Schema ? 'https://barassistant.app/cocktail-02.schema.json' : null, diff --git a/app/External/Import/FromDataPack.php b/app/External/Import/FromDataPack.php index a0778ea7..eb20366e 100644 --- a/app/External/Import/FromDataPack.php +++ b/app/External/Import/FromDataPack.php @@ -25,7 +25,7 @@ class FromDataPack { - private Filesystem $uploadsDisk; + private readonly Filesystem $uploadsDisk; /** @var array */ private array $barShelf = []; @@ -107,9 +107,9 @@ private function importBaseData(string $tableName, string $filepath, int $barId) }, $data); // Skip duplicates - $existing = DB::table($tableName)->select('name')->where('bar_id', $barId)->get()->keyBy(fn ($row) => strtolower($row->name))->toArray(); + $existing = DB::table($tableName)->select('name')->where('bar_id', $barId)->get()->keyBy(fn ($row) => strtolower((string) $row->name))->toArray(); $importData = array_filter($importData, function ($item) use ($existing) { - if (array_key_exists(strtolower($item['name']), $existing)) { + if (array_key_exists(strtolower((string) $item['name']), $existing)) { return false; } @@ -127,9 +127,9 @@ private function importCalculators(string $filepath, int $barId): void $data = []; } - $existing = DB::table('calculators')->select('name')->where('bar_id', $barId)->get()->keyBy(fn ($row) => strtolower($row->name))->toArray(); + $existing = DB::table('calculators')->select('name')->where('bar_id', $barId)->get()->keyBy(fn ($row) => strtolower((string) $row->name))->toArray(); $data = array_filter($data, function ($item) use ($existing) { - if (array_key_exists(strtolower($item['name']), $existing)) { + if (array_key_exists(strtolower((string) $item['name']), $existing)) { return false; } @@ -175,9 +175,7 @@ private function importIngredients(Filesystem $dataDisk, Bar $bar, User $user): { $timerStart = microtime(true); - $existingIngredients = DB::table('ingredients')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(function ($ingredient) { - return Str::slug($ingredient->name); - }); + $existingIngredients = DB::table('ingredients')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(fn($ingredient) => Str::slug($ingredient->name)); $ingredientsToInsert = []; $parentIngredientsToInsert = []; @@ -322,9 +320,7 @@ private function importBaseCocktails(Filesystem $dataDisk, Bar $bar, User $user) $dbIngredients = DB::table('ingredients')->select('id', DB::raw('LOWER(name) AS name'))->where('bar_id', $bar->id)->get()->keyBy('name')->map(fn ($row) => $row->id)->toArray(); $dbGlasses = DB::table('glasses')->select('id', DB::raw('LOWER(name) AS name'))->where('bar_id', $bar->id)->get()->keyBy('name')->map(fn ($row) => $row->id)->toArray(); $dbMethods = DB::table('cocktail_methods')->select('id', DB::raw('LOWER(name) AS name'))->where('bar_id', $bar->id)->get()->keyBy('name')->map(fn ($row) => $row->id)->toArray(); - $existingCocktails = DB::table('cocktails')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(function ($cocktail) { - return Str::slug($cocktail->name); - }); + $existingCocktails = DB::table('cocktails')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(fn($cocktail) => Str::slug($cocktail->name)); $cocktailImages = []; $uniqueTags = []; diff --git a/app/External/Import/FromJsonSchema.php b/app/External/Import/FromJsonSchema.php index 4cb0d8d8..b73c1d34 100644 --- a/app/External/Import/FromJsonSchema.php +++ b/app/External/Import/FromJsonSchema.php @@ -20,7 +20,7 @@ class FromJsonSchema { - private Matcher $matcher; + private readonly Matcher $matcher; public function __construct( private readonly CocktailService $cocktailService, diff --git a/app/External/Matcher.php b/app/External/Matcher.php index 54d3132c..782290ff 100644 --- a/app/External/Matcher.php +++ b/app/External/Matcher.php @@ -35,7 +35,7 @@ public function matchCocktailByName(string $name): ?int } $this->matchedCocktails = DB::table('cocktails')->select('id', 'name')->where('bar_id', $this->barId)->get()->map(function ($row) { - $row->name = mb_strtolower($row->name, 'UTF-8'); + $row->name = mb_strtolower((string) $row->name, 'UTF-8'); return $row; })->pluck('id', 'name')->toArray(); @@ -59,7 +59,7 @@ public function matchOrCreateIngredientByName(IngredientDTO $ingredient): int } $this->matchedIngredients = DB::table('ingredients')->select('id', 'name')->where('bar_id', $this->barId)->get()->map(function ($row) { - $row->name = mb_strtolower($row->name, 'UTF-8'); + $row->name = mb_strtolower((string) $row->name, 'UTF-8'); return $row; })->pluck('id', 'name')->toArray(); @@ -87,7 +87,7 @@ public function matchGlassByName(string $name): ?int } $this->matchedGlasses = DB::table('glasses')->select('id', 'name')->where('bar_id', $this->barId)->get()->map(function ($row) { - $row->name = mb_strtolower($row->name, 'UTF-8'); + $row->name = mb_strtolower((string) $row->name, 'UTF-8'); return $row; })->pluck('id', 'name')->toArray(); @@ -111,7 +111,7 @@ public function matchMethodByName(string $name): ?int } $this->matchedMethods = DB::table('cocktail_methods')->select('id', 'name')->where('bar_id', $this->barId)->get()->map(function ($row) { - $row->name = mb_strtolower($row->name, 'UTF-8'); + $row->name = mb_strtolower((string) $row->name, 'UTF-8'); return $row; })->pluck('id', 'name')->toArray(); diff --git a/app/External/Model/Calculator.php b/app/External/Model/Calculator.php index 9ff73901..7db7ee14 100644 --- a/app/External/Model/Calculator.php +++ b/app/External/Model/Calculator.php @@ -27,17 +27,15 @@ public static function fromModel(CalculatorModel $model): self $model->getExternalId(), $model->name, $model->description, - $model->blocks->map(function (CalculatorBlock $block) { - return [ - 'label' => $block->label, - 'variable_name' => $block->variable_name, - 'value' => $block->value, - 'type' => $block->type, - 'settings' => $block->settings, - 'description' => $block->description, - 'sort' => $block->sort, - ]; - })->toArray() + $model->blocks->map(fn(CalculatorBlock $block) => [ + 'label' => $block->label, + 'variable_name' => $block->variable_name, + 'value' => $block->value, + 'type' => $block->type, + 'settings' => $block->settings, + 'description' => $block->description, + 'sort' => $block->sort, + ])->toArray() ); } diff --git a/app/External/Model/Cocktail.php b/app/External/Model/Cocktail.php index 677ca9ee..8758d7bf 100644 --- a/app/External/Model/Cocktail.php +++ b/app/External/Model/Cocktail.php @@ -45,13 +45,9 @@ private function __construct( public static function fromModel(CocktailModel $model, bool $useFileURI = false, ?Units $toUnits = null): self { - $images = $model->images->map(function (ImageModel $image) use ($useFileURI) { - return Image::fromModel($image, $useFileURI); - })->toArray(); + $images = $model->images->map(fn(ImageModel $image) => Image::fromModel($image, $useFileURI))->toArray(); - $ingredients = $model->ingredients->map(function (CocktailIngredientModel $cocktailIngredient) use ($toUnits) { - return CocktailIngredient::fromModel($cocktailIngredient, $toUnits); - })->toArray(); + $ingredients = $model->ingredients->map(fn(CocktailIngredientModel $cocktailIngredient) => CocktailIngredient::fromModel($cocktailIngredient, $toUnits))->toArray(); return new self( $model->getExternalId(), @@ -211,9 +207,7 @@ public function toJSONLD(): string "recipeCategory" => "Drink", "recipeCuisine" => "Cocktail", "keywords" => implode(', ', $this->tags), - "recipeIngredient" => array_map(function (CocktailIngredient $ci) { - return (new CocktailIngredientFormatter($ci->amount, $ci->ingredient->name, $ci->optional))->format(); - }, $this->ingredients), + "recipeIngredient" => array_map(fn(CocktailIngredient $ci) => (new CocktailIngredientFormatter($ci->amount, $ci->ingredient->name, $ci->optional))->format(), $this->ingredients), ], ['image' => $image]); if ($data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)) { diff --git a/app/External/Model/CocktailIngredient.php b/app/External/Model/CocktailIngredient.php index 3d870ec8..01330829 100644 --- a/app/External/Model/CocktailIngredient.php +++ b/app/External/Model/CocktailIngredient.php @@ -31,9 +31,7 @@ private function __construct( public static function fromModel(CocktailIngredientModel $model, ?Units $toUnits = null): self { - $substitutes = $model->substitutes->map(function (CocktailIngredientSubstituteModel $substitute) use ($toUnits) { - return CocktailIngredientSubstitute::fromModel($substitute, $toUnits); - })->toArray(); + $substitutes = $model->substitutes->map(fn(CocktailIngredientSubstituteModel $substitute) => CocktailIngredientSubstitute::fromModel($substitute, $toUnits))->toArray(); $amount = $model->getAmount(); if ($toUnits && !$model->getAmount()->units->isDash()) { diff --git a/app/External/Model/Ingredient.php b/app/External/Model/Ingredient.php index a2709939..4d1b1785 100644 --- a/app/External/Model/Ingredient.php +++ b/app/External/Model/Ingredient.php @@ -45,17 +45,11 @@ private function __construct( public static function fromModel(IngredientModel $model, bool $useFileURI = false, ?Units $toUnits = null): self { - $images = $model->images->map(function (ImageModel $image) use ($useFileURI) { - return Image::fromModel($image, $useFileURI); - })->toArray(); + $images = $model->images->map(fn(ImageModel $image) => Image::fromModel($image, $useFileURI))->toArray(); - $ingredientParts = $model->ingredientParts->map(function (ComplexIngredient $part) { - return Ingredient::fromModel($part->ingredient); - })->toArray(); + $ingredientParts = $model->ingredientParts->map(fn(ComplexIngredient $part) => Ingredient::fromModel($part->ingredient))->toArray(); - $ingredientPrices = $model->prices->map(function (IngredientPriceModel $price) { - return IngredientPrice::fromModel($price); - })->toArray(); + $ingredientPrices = $model->prices->map(fn(IngredientPriceModel $price) => IngredientPrice::fromModel($price))->toArray(); $defaultIngredientUnits = $model->getDefaultUnits(); if ($model->getDefaultUnits()?->isConvertable() && $toUnits) { diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 68bb678b..8e12a703 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -112,7 +112,7 @@ public function register(RegisterRequest $req): JsonResource $user->save(); if ($requireConfirmation === true) { - Mail::to($user)->queue(new ConfirmAccount($user->id, sha1($user->email))); + Mail::to($user)->queue(new ConfirmAccount($user->id, sha1((string) $user->email))); Log::info('User registered and confirmation email sent', [ 'email' => $user->email, ]); @@ -208,7 +208,7 @@ public function confirmAccount(int $id, string $hash): JsonResponse $user = User::findOrFail($id); - if (!hash_equals(sha1($user->getEmailForVerification()), $hash)) { + if (!hash_equals(sha1((string) $user->getEmailForVerification()), $hash)) { abort(403); } diff --git a/app/Http/Controllers/CocktailController.php b/app/Http/Controllers/CocktailController.php index 82bb1ffd..bba3e323 100644 --- a/app/Http/Controllers/CocktailController.php +++ b/app/Http/Controllers/CocktailController.php @@ -401,7 +401,7 @@ public function copy(string $idOrSlug, CocktailService $cocktailService, ImageSe copyright: $image->copyright, sort: $image->sort, ); - } catch (Throwable $e) { + } catch (Throwable) { } } } diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php index 80a1d64a..7da41499 100644 --- a/app/Http/Controllers/ImageController.php +++ b/app/Http/Controllers/ImageController.php @@ -177,7 +177,7 @@ public function thumb(int $id): Response return new Response($responseContent, $statusCode, [ 'Content-Type' => 'image/webp', - 'Content-Length' => strlen($responseContent), + 'Content-Length' => strlen((string) $responseContent), 'Etag' => $etag ]); } diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index 5bd99429..003436d9 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -65,7 +65,7 @@ public function cocktail(ImportRequest $request): JsonResource if (is_array($source)) { $cocktail = $importer->process($source, $duplicateAction); } else { - $cocktail = $importer->process(json_decode($source, true), $duplicateAction); + $cocktail = $importer->process(json_decode((string) $source, true), $duplicateAction); } return new CocktailResource($cocktail); diff --git a/app/Http/Controllers/IngredientController.php b/app/Http/Controllers/IngredientController.php index 1096ba8e..b69ee1d8 100644 --- a/app/Http/Controllers/IngredientController.php +++ b/app/Http/Controllers/IngredientController.php @@ -217,13 +217,11 @@ public function extra(Request $request, CocktailService $cocktailRepo, string $i $extraCocktails = Cocktail::whereIn('id', $extraShelfCocktails->diff($currentShelfCocktails)->values())->where('bar_id', '=', $ingredient->bar_id)->get(); return response()->json([ - 'data' => $extraCocktails->map(function (Cocktail $cocktail) { - return [ - 'id' => $cocktail->id, - 'slug' => $cocktail->slug, - 'name' => $cocktail->name, - ]; - }) + 'data' => $extraCocktails->map(fn(Cocktail $cocktail) => [ + 'id' => $cocktail->id, + 'slug' => $cocktail->slug, + 'name' => $cocktail->name, + ]) ]); } diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index b9114a9e..88ccf4cd 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -103,7 +103,7 @@ public function store(UserRequest $request): JsonResponse } if ($requireConfirmation === true) { - Mail::to($user)->queue(new ConfirmAccount($user->id, sha1($user->email))); + Mail::to($user)->queue(new ConfirmAccount($user->id, sha1((string) $user->email))); } bar()->users()->save($user, ['user_role_id' => $roleId]); diff --git a/app/Http/Middleware/CheckMetricsAccess.php b/app/Http/Middleware/CheckMetricsAccess.php index f319f88c..2c1ab96f 100644 --- a/app/Http/Middleware/CheckMetricsAccess.php +++ b/app/Http/Middleware/CheckMetricsAccess.php @@ -26,9 +26,7 @@ public function handle(Request $request, Closure $next) return $next($request); } - $whitelist = array_filter(config('bar-assistant.metrics.allowed_ips', []), function ($ip) { - return $ip !== ''; - }); + $whitelist = array_filter(config('bar-assistant.metrics.allowed_ips', []), fn($ip) => $ip !== ''); if (count($whitelist) === 0) { abort(404); diff --git a/app/Http/Middleware/EnsureRequestHasBarQuery.php b/app/Http/Middleware/EnsureRequestHasBarQuery.php index de5820bf..673bc670 100644 --- a/app/Http/Middleware/EnsureRequestHasBarQuery.php +++ b/app/Http/Middleware/EnsureRequestHasBarQuery.php @@ -24,17 +24,13 @@ public function handle(Request $request, Closure $next): Response abort(400, sprintf("Missing required bar reference while requesting '%s'. Use 'Bar-Assistant-Bar-Id' header to specify bar id.", $request->path())); } - $bar = Cache::remember('ba:bar:' . $barId, 60 * 60 * 24, function () use ($barId) { - return Bar::findOrFail($barId); - }); + $bar = Cache::remember('ba:bar:' . $barId, 60 * 60 * 24, fn() => Bar::findOrFail($barId)); if ($request->user()->cannot('access', $bar)) { abort(403); } - app()->singleton(BarContext::class, function () use ($bar) { - return new BarContext($bar); - }); + app()->singleton(BarContext::class, fn() => new BarContext($bar)); return $next($request); } diff --git a/app/Http/Resources/AmountFormats.php b/app/Http/Resources/AmountFormats.php index 81633232..56cfb8ad 100644 --- a/app/Http/Resources/AmountFormats.php +++ b/app/Http/Resources/AmountFormats.php @@ -35,9 +35,9 @@ ], required: ['ml', 'oz', 'cl'] )] -final class AmountFormats implements JsonSerializable +final readonly class AmountFormats implements JsonSerializable { - public function __construct(private readonly CocktailIngredient $cocktailIngredient) + public function __construct(private CocktailIngredient $cocktailIngredient) { } diff --git a/app/Http/Resources/CocktailBasicResource.php b/app/Http/Resources/CocktailBasicResource.php index 73bd7bdb..f14c35e6 100644 --- a/app/Http/Resources/CocktailBasicResource.php +++ b/app/Http/Resources/CocktailBasicResource.php @@ -37,9 +37,7 @@ public function toArray($request) 'slug' => $this->slug, 'name' => $this->name, 'short_ingredients' => $this->getIngredientNames(), - 'image' => $this->when($this->relationLoaded('images'), function () { - return new ImageResource($this->getMainImage()); - }), + 'image' => $this->when($this->relationLoaded('images'), fn() => new ImageResource($this->getMainImage())), ]; } } diff --git a/app/Http/Resources/CocktailResource.php b/app/Http/Resources/CocktailResource.php index 4abd3e9c..fdea1e80 100644 --- a/app/Http/Resources/CocktailResource.php +++ b/app/Http/Resources/CocktailResource.php @@ -104,12 +104,10 @@ public function toArray($request) ), 'tags' => $this->when( $this->relationLoaded('tags'), - fn () => $this->tags->map(function ($tag) { - return [ - 'id' => $tag->id, - 'name' => $tag->name, - ]; - }) + fn () => $this->tags->map(fn($tag) => [ + 'id' => $tag->id, + 'name' => $tag->name, + ]) ), 'rating' => $this->when( $this->relationLoaded('ratings'), @@ -134,17 +132,13 @@ public function toArray($request) 'in_shelf' => in_array($this->id, $request->user()->getShelfCocktailsOnce($this->bar_id)), 'in_bar_shelf' => in_array($this->id, $this->bar->getShelfCocktailsOnce()), 'is_favorited' => $request->user()->getBarMembership($this->bar_id)->cocktailFavorites->where('cocktail_id', $this->id)->isNotEmpty(), - 'access' => $this->when(true, function () use ($request) { - return [ - 'can_edit' => $request->user()->can('edit', $this->resource), - 'can_delete' => $request->user()->can('delete', $this->resource), - 'can_rate' => $request->user()->can('rate', $this->resource), - 'can_add_note' => $request->user()->can('addNote', $this->resource), - ]; - }), - 'parent_cocktail' => $this->whenLoaded('parentCocktail', function () { - return new CocktailBasicResource($this->parentCocktail); - }), + 'access' => $this->when(true, fn() => [ + 'can_edit' => $request->user()->can('edit', $this->resource), + 'can_delete' => $request->user()->can('delete', $this->resource), + 'can_rate' => $request->user()->can('rate', $this->resource), + 'can_add_note' => $request->user()->can('addNote', $this->resource), + ]), + 'parent_cocktail' => $this->whenLoaded('parentCocktail', fn() => new CocktailBasicResource($this->parentCocktail)), 'varieties' => CocktailBasicResource::collection($this->whenLoaded('cocktailVarieties')), 'year' => $this->year, ]; diff --git a/app/Http/Resources/CollectionResource.php b/app/Http/Resources/CollectionResource.php index e581228c..6db6d103 100644 --- a/app/Http/Resources/CollectionResource.php +++ b/app/Http/Resources/CollectionResource.php @@ -40,9 +40,7 @@ public function toArray($request) 'description' => $this->description, 'is_bar_shared' => $this->is_bar_shared, 'created_at' => $this->created_at->toAtomString(), - 'created_user' => $this->whenLoaded('barMembership', function () { - return new UserBasicResource($this->barMembership->user); - }), + 'created_user' => $this->whenLoaded('barMembership', fn() => new UserBasicResource($this->barMembership->user)), 'cocktails' => CocktailBasicResource::collection($this->whenLoaded('cocktails')), ]; } diff --git a/app/Http/Resources/ExploreCocktailResource.php b/app/Http/Resources/ExploreCocktailResource.php index 47aafda6..d8a7a441 100644 --- a/app/Http/Resources/ExploreCocktailResource.php +++ b/app/Http/Resources/ExploreCocktailResource.php @@ -89,37 +89,31 @@ public function toArray($request) 'glass' => $this->glass->name ?? null, 'utensils' => $this->utensils->pluck('name'), 'method' => $this->method->name ?? null, - 'images' => $this->images->map(function (Image $image) { - return [ - 'sort' => $image->sort, - 'placeholder_hash' => $image->placeholder_hash, - 'url' => $image->getImageUrl(), - 'copyright' => $image->copyright, - ]; - }), + 'images' => $this->images->map(fn(Image $image) => [ + 'sort' => $image->sort, + 'placeholder_hash' => $image->placeholder_hash, + 'url' => $image->getImageUrl(), + 'copyright' => $image->copyright, + ]), 'abv' => $this->abv, - 'ingredients' => $this->ingredients->map(function (CocktailIngredient $cocktailIngredient) { - return [ + 'ingredients' => $this->ingredients->map(fn(CocktailIngredient $cocktailIngredient) => [ + 'ingredient' => [ + 'name' => $cocktailIngredient->ingredient->name, + ], + 'amount' => $cocktailIngredient->amount, + 'amount_max' => $cocktailIngredient->amount_max, + 'units' => $cocktailIngredient->units, + 'optional' => (bool) $cocktailIngredient->optional, + 'note' => $cocktailIngredient->note, + 'substitutes' => $cocktailIngredient->substitutes->map(fn(CocktailIngredientSubstitute $substitute) => [ 'ingredient' => [ - 'name' => $cocktailIngredient->ingredient->name, + 'name' => $substitute->ingredient->name, ], - 'amount' => $cocktailIngredient->amount, - 'amount_max' => $cocktailIngredient->amount_max, - 'units' => $cocktailIngredient->units, - 'optional' => (bool) $cocktailIngredient->optional, - 'note' => $cocktailIngredient->note, - 'substitutes' => $cocktailIngredient->substitutes->map(function (CocktailIngredientSubstitute $substitute) { - return [ - 'ingredient' => [ - 'name' => $substitute->ingredient->name, - ], - 'amount' => $substitute->amount, - 'amount_max' => $substitute->amount_max, - 'units' => $substitute->units, - ]; - })->toArray(), - ]; - }), + 'amount' => $substitute->amount, + 'amount_max' => $substitute->amount_max, + 'units' => $substitute->units, + ])->toArray(), + ]), ]; } } diff --git a/app/Http/Resources/IngredientBasicResource.php b/app/Http/Resources/IngredientBasicResource.php index 81847ffe..3a2a541b 100644 --- a/app/Http/Resources/IngredientBasicResource.php +++ b/app/Http/Resources/IngredientBasicResource.php @@ -35,9 +35,7 @@ public function toArray($request) 'id' => $this->id, 'slug' => $this->slug, 'name' => $this->name, - 'image' => $this->when($this->relationLoaded('images'), function () { - return new ImageResource($this->getMainImage()); - }), + 'image' => $this->when($this->relationLoaded('images'), fn() => new ImageResource($this->getMainImage())), ]; } } diff --git a/app/Http/Resources/IngredientResource.php b/app/Http/Resources/IngredientResource.php index bc89ec84..4b1c7346 100644 --- a/app/Http/Resources/IngredientResource.php +++ b/app/Http/Resources/IngredientResource.php @@ -112,9 +112,7 @@ public function toArray($request) $this->relationLoaded('ingredientParts'), fn () => $this->ingredientParts->map(fn ($cip) => new IngredientBasicResource($cip->ingredient)) ), - 'prices' => $this->when($this->relationLoaded('prices'), function () { - return IngredientPriceResource::collection($this->prices); - }), + 'prices' => $this->when($this->relationLoaded('prices'), fn() => IngredientPriceResource::collection($this->prices)), 'calculator_id' => $this->calculator_id, 'sugar_g_per_ml' => $this->sugar_g_per_ml, 'acidity' => $this->acidity, diff --git a/app/Http/Resources/MenuPublicResource.php b/app/Http/Resources/MenuPublicResource.php index b4b1b085..63d24299 100644 --- a/app/Http/Resources/MenuPublicResource.php +++ b/app/Http/Resources/MenuPublicResource.php @@ -71,23 +71,19 @@ public function toArray($request) fn () => $this->bar->images->map(fn (Image $image) => $image->getImageUrl())->toArray(), ), ], - 'categories' => $this->getMenuItems()->groupBy('categoryName')->map(function ($items, $name) { - return [ - 'name' => $name, - 'items' => $items->sortBy(fn ($menuItem) => $menuItem->sort)->values()->map(function (MenuItem $menuItem) { - return [ - 'in_bar_shelf' => $menuItem->inShelf, - 'type' => $menuItem->type->value, - 'sort' => $menuItem->sort, - 'price' => new PriceResource($menuItem->price), - 'public_id' => $menuItem->publicId, - 'name' => $menuItem->name, - 'description' => $menuItem->description, - 'image' => $menuItem->image, - ]; - })->toArray(), - ]; - })->values() + 'categories' => $this->getMenuItems()->groupBy('categoryName')->map(fn($items, $name) => [ + 'name' => $name, + 'items' => $items->sortBy(fn ($menuItem) => $menuItem->sort)->values()->map(fn(MenuItem $menuItem) => [ + 'in_bar_shelf' => $menuItem->inShelf, + 'type' => $menuItem->type->value, + 'sort' => $menuItem->sort, + 'price' => new PriceResource($menuItem->price), + 'public_id' => $menuItem->publicId, + 'name' => $menuItem->name, + 'description' => $menuItem->description, + 'image' => $menuItem->image, + ])->toArray(), + ])->values() ]; } } diff --git a/app/Http/Resources/MenuResource.php b/app/Http/Resources/MenuResource.php index 1d32b1f6..df2179ca 100644 --- a/app/Http/Resources/MenuResource.php +++ b/app/Http/Resources/MenuResource.php @@ -49,21 +49,17 @@ public function toArray($request) 'is_enabled' => (bool) $this->is_enabled, 'created_at' => $this->created_at->toAtomString(), 'updated_at' => $this->updated_at?->toAtomString(), - 'categories' => $this->getMenuItems()->groupBy('categoryName')->map(function ($items, $name) { - return [ - 'name' => $name, - 'items' => $items->sortBy(fn ($menuItem) => $menuItem->sort)->values()->map(function (MenuItem $menuItem) { - return [ - 'id' => $menuItem->id, - 'type' => $menuItem->type->value, - 'sort' => $menuItem->sort, - 'price' => new PriceResource($menuItem->price), - 'name' => $menuItem->name, - 'description' => $menuItem->description, - ]; - })->toArray(), - ]; - })->values() + 'categories' => $this->getMenuItems()->groupBy('categoryName')->map(fn($items, $name) => [ + 'name' => $name, + 'items' => $items->sortBy(fn ($menuItem) => $menuItem->sort)->values()->map(fn(MenuItem $menuItem) => [ + 'id' => $menuItem->id, + 'type' => $menuItem->type->value, + 'sort' => $menuItem->sort, + 'price' => new PriceResource($menuItem->price), + 'name' => $menuItem->name, + 'description' => $menuItem->description, + ])->toArray(), + ])->values() ]; } } diff --git a/app/Http/Resources/Public/CocktailResource.php b/app/Http/Resources/Public/CocktailResource.php index 10225ca1..ec64547c 100644 --- a/app/Http/Resources/Public/CocktailResource.php +++ b/app/Http/Resources/Public/CocktailResource.php @@ -94,9 +94,7 @@ public function toArray($request) 'images' => ImageResource::collection($this->images), 'tags' => $this->when( $this->relationLoaded('tags'), - fn () => $this->tags->map(function ($tag) { - return $tag->name; - }) + fn () => $this->tags->map(fn($tag) => $tag->name) ), 'glass' => $this->glass->name ?? null, 'utensils' => $this->utensils->pluck('name'), @@ -107,25 +105,21 @@ public function toArray($request) 'in_bar_shelf' => $this->inBarShelf(), 'abv' => $this->abv, 'year' => $this->year, - 'ingredients' => $this->ingredients->map(function (CocktailIngredient $cocktailIngredient) { - return [ - 'name' => $cocktailIngredient->ingredient->name, - 'amount' => $cocktailIngredient->amount, - 'amount_max' => $cocktailIngredient->amount_max, - 'units' => $cocktailIngredient->units, - 'units_formatted' => new AmountFormats($cocktailIngredient), - 'optional' => (bool) $cocktailIngredient->optional, - 'note' => $cocktailIngredient->note, - 'substitutes' => $cocktailIngredient->substitutes->map(function (CocktailIngredientSubstitute $substitute) { - return [ - 'name' => $substitute->ingredient->name, - 'amount' => $substitute->amount, - 'amount_max' => $substitute->amount_max, - 'units' => $substitute->units, - ]; - })->toArray(), - ]; - }), + 'ingredients' => $this->ingredients->map(fn(CocktailIngredient $cocktailIngredient) => [ + 'name' => $cocktailIngredient->ingredient->name, + 'amount' => $cocktailIngredient->amount, + 'amount_max' => $cocktailIngredient->amount_max, + 'units' => $cocktailIngredient->units, + 'units_formatted' => new AmountFormats($cocktailIngredient), + 'optional' => (bool) $cocktailIngredient->optional, + 'note' => $cocktailIngredient->note, + 'substitutes' => $cocktailIngredient->substitutes->map(fn(CocktailIngredientSubstitute $substitute) => [ + 'name' => $substitute->ingredient->name, + 'amount' => $substitute->amount, + 'amount_max' => $substitute->amount_max, + 'units' => $substitute->units, + ])->toArray(), + ]), ]; } } diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index 78c60354..764964dc 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -54,13 +54,11 @@ public function toArray($request) 'name' => $this->name, 'email' => $this->email, 'is_subscribed' => $this->hasActiveSubscription(), - 'role' => $this->memberships->where('bar_id', $bar->id)->map(function (BarMembership $membership) { - return [ - 'bar_id' => $membership->bar_id, - 'role_id' => $membership->role->id ?? null, - 'role_name' => $membership->role->name ?? null, - ]; - })->first(), + 'role' => $this->memberships->where('bar_id', $bar->id)->map(fn(BarMembership $membership) => [ + 'bar_id' => $membership->bar_id, + 'role_id' => $membership->role->id ?? null, + 'role_name' => $membership->role->name ?? null, + ])->first(), ]; } } diff --git a/app/Metrics/MetricsServiceProvider.php b/app/Metrics/MetricsServiceProvider.php index e51bf28d..aefda931 100644 --- a/app/Metrics/MetricsServiceProvider.php +++ b/app/Metrics/MetricsServiceProvider.php @@ -27,9 +27,7 @@ public function register(): void return; } - $this->app->scoped(CollectorRegistry::class, function () { - return new CollectorRegistry(Redis::fromExistingConnection(LaravelRedis::connection()->client())); - }); + $this->app->scoped(CollectorRegistry::class, fn() => new CollectorRegistry(Redis::fromExistingConnection(LaravelRedis::connection()->client()))); } public function boot(): void diff --git a/app/Metrics/TotalBars.php b/app/Metrics/TotalBars.php index ca73ca97..038ab2db 100644 --- a/app/Metrics/TotalBars.php +++ b/app/Metrics/TotalBars.php @@ -12,12 +12,10 @@ class TotalBars extends BaseMetrics { public function __invoke(): void { - $counts = Cache::remember('metrics_bass_total_bars', 60 * 24, function () { - return DB::table('bars')->select( - DB::raw("(CASE WHEN status IS NULL THEN 'active' ELSE status END) AS bar_status"), - DB::raw('COUNT(*) AS total') - )->groupBy('bar_status')->get()->keyBy('bar_status'); - }); + $counts = Cache::remember('metrics_bass_total_bars', 60 * 24, fn() => DB::table('bars')->select( + DB::raw("(CASE WHEN status IS NULL THEN 'active' ELSE status END) AS bar_status"), + DB::raw('COUNT(*) AS total') + )->groupBy('bar_status')->get()->keyBy('bar_status')); foreach (BarStatusEnum::cases() as $status) { $metric = $this->registry->getOrRegisterGauge( diff --git a/app/Models/Cocktail.php b/app/Models/Cocktail.php index bf216e14..65d0cbad 100644 --- a/app/Models/Cocktail.php +++ b/app/Models/Cocktail.php @@ -194,9 +194,7 @@ public function getABV(): ?float public function getVolume(): float { - $ingredients = $this->ingredients->map(function ($i) { - return $i->getAmount(); - })->toArray(); + $ingredients = $this->ingredients->map(fn($i) => $i->getAmount())->toArray(); return Utils::calculateVolume($ingredients); } @@ -342,9 +340,7 @@ public function getUserShelfMatchPercentage(User $user): float { $currentShelf = $user->getShelfIngredients($this->bar_id); $totalIngredients = $this->ingredients->count(); - $matchIngredients = $this->ingredients->filter(function (CocktailIngredient $ci) use ($currentShelf) { - return $currentShelf->contains('ingredient_id', $ci->ingredient_id); - })->count(); + $matchIngredients = $this->ingredients->filter(fn(CocktailIngredient $ci) => $currentShelf->contains('ingredient_id', $ci->ingredient_id))->count(); return ($matchIngredients / $totalIngredients) * 100; } @@ -353,9 +349,7 @@ public function getBarShelfMatchPercentage(): float { $currentShelf = $this->bar->shelfIngredients; $totalIngredients = $this->ingredients->count(); - $matchIngredients = $this->ingredients->filter(function (CocktailIngredient $ci) use ($currentShelf) { - return $currentShelf->contains('ingredient_id', $ci->ingredient_id); - })->count(); + $matchIngredients = $this->ingredients->filter(fn(CocktailIngredient $ci) => $currentShelf->contains('ingredient_id', $ci->ingredient_id))->count(); return ($matchIngredients / $totalIngredients) * 100; } @@ -410,9 +404,7 @@ public function asJsonLDSchema(): array "recipeCategory" => "Drink", "recipeCuisine" => "Cocktail", "keywords" => $this->tags->pluck('name')->implode(', '), - "recipeIngredient" => $this->ingredients->map(function (CocktailIngredient $ci) { - return $ci->amount . ' ' . $ci->units . ' ' . $ci->ingredient->name; - }), + "recipeIngredient" => $this->ingredients->map(fn(CocktailIngredient $ci) => $ci->amount . ' ' . $ci->units . ' ' . $ci->ingredient->name), ]; } diff --git a/app/Models/Concerns/HasImages.php b/app/Models/Concerns/HasImages.php index 0ff23df8..acbcfd06 100644 --- a/app/Models/Concerns/HasImages.php +++ b/app/Models/Concerns/HasImages.php @@ -39,7 +39,7 @@ public function getMainImageThumbUrl(bool $absolute = true): ?string if (!empty(config('app.url'))) { $path = route('images.thumb', ['id' => $this->getMainImage()->id], false); - return rtrim(config('app.url'), '/') . '/' . ltrim($path, '/'); + return rtrim((string) config('app.url'), '/') . '/' . ltrim($path, '/'); } return route('images.thumb', ['id' => $this->getMainImage()->id], $absolute); diff --git a/app/Models/FileToken.php b/app/Models/FileToken.php index 54e228b0..83e526e4 100644 --- a/app/Models/FileToken.php +++ b/app/Models/FileToken.php @@ -17,7 +17,7 @@ public static function generate(int $id, string $filename, DateTimeImmutable $ex $payload = urldecode(http_build_query($payload)); $payload = implode("\n", [$id, $expires->getTimestamp(), $payload]); - return hash_hmac('sha256', $payload, config('app.key')); + return hash_hmac('sha256', $payload, (string) config('app.key')); } public static function check(string $token, int $id, string $filename, DateTimeImmutable $expires): bool diff --git a/app/Models/Relations/BaseMaterializedPathRelation.php b/app/Models/Relations/BaseMaterializedPathRelation.php index 18b9bdd2..5ff8803b 100644 --- a/app/Models/Relations/BaseMaterializedPathRelation.php +++ b/app/Models/Relations/BaseMaterializedPathRelation.php @@ -13,16 +13,12 @@ */ abstract class BaseMaterializedPathRelation extends Relation { - private string $pathColumn; - /** * @param Ingredient $parent In our case the root ingredient * @param string $pathColumn Name of column containing materialized path */ - public function __construct(Ingredient $parent, string $pathColumn) + public function __construct(Ingredient $parent, private readonly string $pathColumn) { - $this->pathColumn = $pathColumn; - parent::__construct(Ingredient::query(), $parent); } diff --git a/app/Models/Relations/HasManyAncestors.php b/app/Models/Relations/HasManyAncestors.php index bbd9a869..532494df 100644 --- a/app/Models/Relations/HasManyAncestors.php +++ b/app/Models/Relations/HasManyAncestors.php @@ -40,9 +40,7 @@ public function addEagerConstraints(array $models) public function match(array $models, EloquentCollection $results, $relation) { foreach ($models as $model) { - $ancestors = $results->filter(function ($possibleAncestor) use ($model) { - return $possibleAncestor['_leaf_id'] === $model->id; - })->sort(function ($a, $b) use ($model) { + $ancestors = $results->filter(fn($possibleAncestor) => $possibleAncestor['_leaf_id'] === $model->id)->sort(function ($a, $b) use ($model) { // Sort by position in materialized path $path = $model->getMaterializedPath()->toArray(); $posA = (int) array_search($a['id'], $path); diff --git a/app/Models/Relations/HasManyDescendants.php b/app/Models/Relations/HasManyDescendants.php index ade5d451..da5edf9d 100644 --- a/app/Models/Relations/HasManyDescendants.php +++ b/app/Models/Relations/HasManyDescendants.php @@ -44,9 +44,7 @@ public function addEagerConstraints(array $rootIngredients) public function match(array $rootIngredients, EloquentCollection $descendants, $relation) { foreach ($rootIngredients as $rootIngredient) { - $relationDescendants = $descendants->filter(function ($possibleDescendant) use ($rootIngredient) { - return $possibleDescendant['_root_id'] === $rootIngredient->id; - })->sort(function ($a, $b) use ($rootIngredient) { + $relationDescendants = $descendants->filter(fn($possibleDescendant) => $possibleDescendant['_root_id'] === $rootIngredient->id)->sort(function ($a, $b) use ($rootIngredient) { // Sort by position in materialized path $path = $rootIngredient->getMaterializedPath()->toArray(); $posA = (int) array_search($a['id'], $path); diff --git a/app/OpenAPI/Schemas/BarRequest.php b/app/OpenAPI/Schemas/BarRequest.php index cd4af4e6..c731b258 100644 --- a/app/OpenAPI/Schemas/BarRequest.php +++ b/app/OpenAPI/Schemas/BarRequest.php @@ -30,7 +30,7 @@ class BarRequest #[OAT\Property(property: 'enable_invites', description: 'Enable users with invite code to join this bar. Default `false`.')] public bool $invitesEnabled = false; #[OAT\Property(description: 'List of data that the bar will start with. Cocktails cannot be imported without ingredients.')] - public ?BarOptionsEnum $options; + public ?BarOptionsEnum $options = null; /** @var array */ #[OAT\Property(items: new OAT\Items(type: 'integer'), description: 'Existing image ids')] public array $images = []; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 7a1575c8..bddfc563 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -67,7 +67,7 @@ public function boot() PRAGMA cache_size = -20000; PRAGMA mmap_size = 2147483648; '); - } catch (Throwable $e) { + } catch (Throwable) { Log::warning('Unable to connect to DB setup PRAGMAs'); } } diff --git a/app/Providers/HorizonServiceProvider.php b/app/Providers/HorizonServiceProvider.php index ad9dd618..13146958 100644 --- a/app/Providers/HorizonServiceProvider.php +++ b/app/Providers/HorizonServiceProvider.php @@ -27,10 +27,8 @@ public function boot(): void */ protected function gate(): void { - Gate::define('viewHorizon', function ($user) { - return in_array($user->email, [ - // - ]); - }); + Gate::define('viewHorizon', fn($user) => in_array($user->email, [ + // + ])); } } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index c079523f..c410897e 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -48,22 +48,14 @@ public function boot() */ protected function configureRateLimiting() { - RateLimiter::for('api', function (Request $request) { - return Limit::perMinute(1000)->by($request->user()?->id ?: $request->ip()); - }); + RateLimiter::for('api', fn(Request $request) => Limit::perMinute(1000)->by($request->user()?->id ?: $request->ip())); - RateLimiter::for('importing', function (Request $request) { - return $request->user()->hasActiveSubscription() - ? Limit::none() - : Limit::perMinute(2)->by($request->user()->id); - }); + RateLimiter::for('importing', fn(Request $request) => $request->user()->hasActiveSubscription() + ? Limit::none() + : Limit::perMinute(2)->by($request->user()->id)); - RateLimiter::for('exports', function (Request $request) { - return App::environment('production') ? Limit::perMinute(1)->by($request->user()?->id ?: $request->ip()) : Limit::none(); - }); + RateLimiter::for('exports', fn(Request $request) => App::environment('production') ? Limit::perMinute(1)->by($request->user()?->id ?: $request->ip()) : Limit::none()); - RateLimiter::for('bar-optimization', function (Request $request) { - return App::environment('production') ? Limit::perMinute(1, 10)->by($request->user()?->id ?: $request->ip()) : Limit::none(); - }); + RateLimiter::for('bar-optimization', fn(Request $request) => App::environment('production') ? Limit::perMinute(1, 10)->by($request->user()?->id ?: $request->ip()) : Limit::none()); } } diff --git a/app/Scraper/AbstractSite.php b/app/Scraper/AbstractSite.php index 0ced689b..9fd31591 100644 --- a/app/Scraper/AbstractSite.php +++ b/app/Scraper/AbstractSite.php @@ -137,26 +137,22 @@ public function method(): ?string public function toArray(): array { $ingredients = $this->ingredients(); - $ingredients = array_map(function (RecipeIngredient $recipeIngredient, int $sort) { - return [ - '_id' => Ulid::generate(), - 'name' => $this->clean(ucfirst($recipeIngredient->name)), - 'amount' => $recipeIngredient->amount->getValue(), - 'amount_max' => $recipeIngredient->amountMax?->getValue(), - 'units' => $recipeIngredient->units === '' ? null : $recipeIngredient->units, - 'note' => $recipeIngredient->comment === '' ? null : $recipeIngredient->comment, - 'source' => $this->clean($recipeIngredient->source), - 'optional' => false, - 'sort' => $sort + 1, - ]; - }, $ingredients, array_keys($ingredients)); - - $meta = array_map(function (array $org) { - return [ - '_id' => $org['_id'], - 'source' => $org['source'], - ]; - }, $ingredients); + $ingredients = array_map(fn(RecipeIngredient $recipeIngredient, int $sort) => [ + '_id' => Ulid::generate(), + 'name' => $this->clean(ucfirst($recipeIngredient->name)), + 'amount' => $recipeIngredient->amount->getValue(), + 'amount_max' => $recipeIngredient->amountMax?->getValue(), + 'units' => $recipeIngredient->units === '' ? null : $recipeIngredient->units, + 'note' => $recipeIngredient->comment === '' ? null : $recipeIngredient->comment, + 'source' => $this->clean($recipeIngredient->source), + 'optional' => false, + 'sort' => $sort + 1, + ], $ingredients, array_keys($ingredients)); + + $meta = array_map(fn(array $org) => [ + '_id' => $org['_id'], + 'source' => $org['source'], + ], $ingredients); $image = $this->convertImagesToDataUri(); $images = []; @@ -209,7 +205,7 @@ protected function clean(?string $str): ?string $str = str_replace(' ', " ", $str); $str = preg_replace("/\s+/u", " ", $str); - return html_entity_decode($str, encoding: 'UTF-8'); + return html_entity_decode((string) $str, encoding: 'UTF-8'); } /** @@ -235,7 +231,7 @@ private function convertImagesToDataUri(): array $image = $this->image(); if ($image['uri'] && !blank($image['uri'])) { $url = parse_url($image['uri']); - $cleanUrl = ($url['scheme'] ?? '') . '://' . ($url['host'] ?? '') . (isset($url['path']) ? $url['path'] : ''); + $cleanUrl = ($url['scheme'] ?? '') . '://' . ($url['host'] ?? '') . ($url['path'] ?? ''); $dataUri = null; $type = pathinfo($cleanUrl, PATHINFO_EXTENSION); diff --git a/app/Scraper/Concerns/ReadsHTMLSchema.php b/app/Scraper/Concerns/ReadsHTMLSchema.php index 782512cf..abe21aff 100644 --- a/app/Scraper/Concerns/ReadsHTMLSchema.php +++ b/app/Scraper/Concerns/ReadsHTMLSchema.php @@ -46,7 +46,7 @@ public function readHTML(Crawler $from): ?SchemaModel } if ($propName === 'keywords' && count($schemaModel->tags) === 0) { - $schemaModel->tags = explode(',', $node->attr('content')); + $schemaModel->tags = explode(',', (string) $node->attr('content')); } if ($propName === 'image') { diff --git a/app/Scraper/Sites/CocktailParty.php b/app/Scraper/Sites/CocktailParty.php index 5d12bf3f..794425a8 100644 --- a/app/Scraper/Sites/CocktailParty.php +++ b/app/Scraper/Sites/CocktailParty.php @@ -39,9 +39,7 @@ public function instructions(): ?string public function tags(): array { - return $this->findDescriptionContainer()->filter('.elementor-widget-post-info a')->each(function ($node): string { - return $node->text(); - }); + return $this->findDescriptionContainer()->filter('.elementor-widget-post-info a')->each(fn($node): string => $node->text()); } public function ingredients(): array @@ -91,9 +89,7 @@ protected function cleanDescription(?string $description): ?string private function joinParagraphs(Crawler $nodes): string { - $paragraphs = $nodes->each(function ($node): string { - return $this->clean($node->text()); - }); + $paragraphs = $nodes->each(fn($node): string => $this->clean($node->text())); return implode("\n\n", $paragraphs); } diff --git a/app/Scraper/Sites/DiffordsGuide.php b/app/Scraper/Sites/DiffordsGuide.php index 236aae50..58b099b0 100644 --- a/app/Scraper/Sites/DiffordsGuide.php +++ b/app/Scraper/Sites/DiffordsGuide.php @@ -37,7 +37,7 @@ public function garnish(): ?string $garnish = null; foreach ($instructions as $instructionStep) { - if (isset($instructionStep['name']) && mb_strtolower($instructionStep['name']) === 'garnish') { + if (isset($instructionStep['name']) && mb_strtolower((string) $instructionStep['name']) === 'garnish') { $garnish = $instructionStep['text']; } } diff --git a/app/Scraper/Sites/EricsCocktailGuide.php b/app/Scraper/Sites/EricsCocktailGuide.php index 9e2174b7..2229e262 100644 --- a/app/Scraper/Sites/EricsCocktailGuide.php +++ b/app/Scraper/Sites/EricsCocktailGuide.php @@ -58,10 +58,10 @@ public function ingredients(): array public function image(): ?array { $style = $this->crawler->filterXPath("//div[contains(@class, 'recipe_recipeImage__')]")->attr('style'); - preg_match_all('~\bbackground(-image)?\s*:(.*?)\(\s*(\'|")?(?.*?)\3?\s*\)~i', $style, $matches); + preg_match_all('~\bbackground(-image)?\s*:(.*?)\(\s*(\'|")?(?.*?)\3?\s*\)~i', (string) $style, $matches); return [ - 'uri' => $this->getSupportedUrls()[0] . $matches['image'][0], + 'uri' => static::getSupportedUrls()[0] . $matches['image'][0], 'copyright' => 'Eric\'s Cocktail Guide', ]; } diff --git a/app/Scraper/Sites/HausAlpenz.php b/app/Scraper/Sites/HausAlpenz.php index 950327a7..88993601 100644 --- a/app/Scraper/Sites/HausAlpenz.php +++ b/app/Scraper/Sites/HausAlpenz.php @@ -36,8 +36,8 @@ public function instructions(): ?string $step = 1; $this->crawler->filter(".recipeFull p:not(:first-child):not(.measure)")->each(function ($node) use (&$result, &$step) { - if (!str_contains(strtolower($node->text()), 'garnish')) { - $result .= $step . '. ' . trim($node->text()) . "\n"; + if (!str_contains(strtolower((string) $node->text()), 'garnish')) { + $result .= $step . '. ' . trim((string) $node->text()) . "\n"; } $step++; }); @@ -53,7 +53,7 @@ public function tags(): array public function glass(): ?string { $imageSource = $this->crawler->filter(".recipeFull h1 img:not(.protocol)")->attr('src'); - $urlSplit = explode('/', $imageSource); + $urlSplit = explode('/', (string) $imageSource); $svg = end($urlSplit); return match ($svg) { @@ -88,7 +88,7 @@ public function garnish(): ?string $result = null; $this->crawler->filter(".recipeFull p:not(:first-child):not(.measure)")->each(function ($node) use (&$result) { - if (str_contains(strtolower($node->text()), 'garnish')) { + if (str_contains(strtolower((string) $node->text()), 'garnish')) { $result = $node->text(); } }); diff --git a/app/Scraper/Sites/ImbibeMagazine.php b/app/Scraper/Sites/ImbibeMagazine.php index c09a8634..50ff310c 100644 --- a/app/Scraper/Sites/ImbibeMagazine.php +++ b/app/Scraper/Sites/ImbibeMagazine.php @@ -22,7 +22,7 @@ public function description(): ?string { $desc = $this->getRecipeSchema()['articleBody'] ?? parent::description(); - return trim($desc); + return trim((string) $desc); } public function source(): ?string @@ -35,7 +35,7 @@ public function instructions(): ?string $result = ''; $i = 1; foreach ($this->getRecipeSchema()['recipeInstructions'] ?? [] as $step) { - $result .= $i . '. ' . trim($step['text']) . "\n"; + $result .= $i . '. ' . trim((string) $step['text']) . "\n"; $i++; } @@ -54,7 +54,7 @@ public function glass(): ?string $result = null; $this->crawler->filter('.ingredients__tools li')->each(function ($listItem) use (&$result) { - if (str_contains(strtolower($listItem->text()), 'glass')) { + if (str_contains(strtolower((string) $listItem->text()), 'glass')) { $result = $listItem->text(); $result = ucfirst(str_replace('Glass:', '', $result)); @@ -99,7 +99,7 @@ public function garnish(): ?string $result = null; $this->crawler->filter('.ingredients__tools li')->each(function ($listItem) use (&$result) { - if (str_contains(strtolower($listItem->text()), 'garnish')) { + if (str_contains(strtolower((string) $listItem->text()), 'garnish')) { $result = $listItem->text(); $result = ucfirst(str_replace('Garnish:', '', $result)); @@ -132,7 +132,7 @@ public function image(): ?array if (!empty($schema)) { $url = $schema['image'] ?? null; } else { - $url = explode(' ', $this->crawler->filter('img.recipe__image')->first()->attr('data-srcset'))[0]; + $url = explode(' ', (string) $this->crawler->filter('img.recipe__image')->first()->attr('data-srcset'))[0]; } return [ @@ -149,7 +149,7 @@ private function getRecipeSchema(): array $recipeSchema = []; $this->crawler->filterXPath('//script[@type="application/ld+json"]')->each(function ($node) use (&$recipeSchema) { - $parsedSchema = json_decode($node->text(), true); + $parsedSchema = json_decode((string) $node->text(), true); if (array_key_exists('@type', $parsedSchema) && $parsedSchema['@type'] === 'Recipe') { $recipeSchema = $parsedSchema; } diff --git a/app/Scraper/Sites/LiberAndCo.php b/app/Scraper/Sites/LiberAndCo.php index 8235944a..e1c7fc19 100644 --- a/app/Scraper/Sites/LiberAndCo.php +++ b/app/Scraper/Sites/LiberAndCo.php @@ -38,7 +38,7 @@ public function instructions(): ?string $result = ''; $this->crawler->filterXPath('//p/strong[contains(text(), \'Instructions:\')]/following::ul')->first()->filter('li')->each(function ($node, $i) use (&$result) { - $result .= ($i + 1) . ". " . trim($node->text()) . "\n"; + $result .= ($i + 1) . ". " . trim((string) $node->text()) . "\n"; }); return trim($result); @@ -105,7 +105,7 @@ public function image(): ?array } try { - $srcUrl = trim($this->crawler->filter('.product-gallery img')->first()->attr('src')); + $srcUrl = trim((string) $this->crawler->filter('.product-gallery img')->first()->attr('src')); $imageUrl = substr($srcUrl, 0, (int) strrpos($srcUrl, "?")); if (str_starts_with($imageUrl, '//')) { $imageUrl = 'https:' . $imageUrl; diff --git a/app/Scraper/Sites/LiquorCom.php b/app/Scraper/Sites/LiquorCom.php index 9b17a2e8..13512600 100644 --- a/app/Scraper/Sites/LiquorCom.php +++ b/app/Scraper/Sites/LiquorCom.php @@ -70,7 +70,7 @@ private function getRecipeSchema(): array $recipeSchema = []; $this->crawler->filterXPath('//script[@type="application/ld+json"]')->each(function ($node) use (&$recipeSchema) { - $recipeSchema = json_decode($node->text(), true, JSON_INVALID_UTF8_SUBSTITUTE); + $recipeSchema = json_decode((string) $node->text(), true, JSON_INVALID_UTF8_SUBSTITUTE); }); return $recipeSchema[0] ?? []; diff --git a/app/Scraper/Sites/MakeMeACocktail.php b/app/Scraper/Sites/MakeMeACocktail.php index f5b99032..71bb2b55 100644 --- a/app/Scraper/Sites/MakeMeACocktail.php +++ b/app/Scraper/Sites/MakeMeACocktail.php @@ -18,7 +18,7 @@ public function tags(): array $result = []; $this->crawler->filterXPath('//div[contains(text(), "Details")]/following::div[2]/div/div')->each(function ($node) use (&$result) { - $result[] = trim($node->text()); + $result[] = trim((string) $node->text()); }); return $result; diff --git a/app/Scraper/Sites/PunchDrink.php b/app/Scraper/Sites/PunchDrink.php index 9cc59b2b..786dcf06 100644 --- a/app/Scraper/Sites/PunchDrink.php +++ b/app/Scraper/Sites/PunchDrink.php @@ -23,7 +23,7 @@ public function instructions(): ?string $i = 1; $result = ""; $instructionsList->each(function ($node) use (&$result, &$i) { - $result .= $i . ". " . trim($node->text()) . "\n"; + $result .= $i . ". " . trim((string) $node->text()) . "\n"; $i++; }); @@ -67,7 +67,7 @@ private function parseEditorsNote(): string // Convert
to new lines $editorsNote = preg_replace('//ius', "\n\n", str_replace("\n", "", str_replace("\r", "", htmlspecialchars_decode($editorsNote)))); // Convert bolds to markdown - $editorsNote = preg_replace('/<(b|strong)>(.*?)<\/\1>/i', '### $2', $editorsNote); + $editorsNote = preg_replace('/<(b|strong)>(.*?)<\/\1>/i', '### $2', (string) $editorsNote); $editorsNote = str_replace(' ', '', $editorsNote); return "\n\n ## Editors note:\n\n" . htmlentities($editorsNote); diff --git a/app/Scraper/Sites/SteveTheBartender.php b/app/Scraper/Sites/SteveTheBartender.php index 357ff34e..39ed9a3b 100644 --- a/app/Scraper/Sites/SteveTheBartender.php +++ b/app/Scraper/Sites/SteveTheBartender.php @@ -26,7 +26,7 @@ public function instructions(): ?string $i = 1; $result = ''; foreach ($instructions as $step) { - $result .= $i . ". " . trim($step['text']) . "\n"; + $result .= $i . ". " . trim((string) $step['text']) . "\n"; $i++; } @@ -61,7 +61,7 @@ public function source(): ?string public function description(): ?string { - return trim($this->getRecipeSchema()['description']); + return trim((string) $this->getRecipeSchema()['description']); } /** @@ -72,7 +72,7 @@ private function getRecipeSchema(): array $recipeSchema = []; $this->crawler->filterXPath('//script[@type="application/ld+json"]')->each(function ($node) use (&$recipeSchema) { - $parsedSchema = json_decode($node->text(), true); + $parsedSchema = json_decode((string) $node->text(), true); foreach ($parsedSchema['@graph'] as $graph) { if (array_key_exists('@type', $graph) && $graph['@type'] === 'Recipe') { $recipeSchema = $graph; diff --git a/app/Scraper/Sites/TuxedoNo2.php b/app/Scraper/Sites/TuxedoNo2.php index 38b8b681..5934905c 100644 --- a/app/Scraper/Sites/TuxedoNo2.php +++ b/app/Scraper/Sites/TuxedoNo2.php @@ -67,7 +67,7 @@ public function ingredients(): array $result = []; $this->crawler->filter('.recipe__recipe ul')->first()->filter('li')->each(function ($node) use (&$result) { - $isGarnish = str_contains($node->filter('.ingredient')->text(), 'garnish'); + $isGarnish = str_contains((string) $node->filter('.ingredient')->text(), 'garnish'); if ($isGarnish) { return; @@ -106,7 +106,7 @@ public function garnish(): ?string $this->crawler->filter('.recipe__recipe ul')->first()->filter('li')->each(function ($node) use (&$garnish) { if ($node->filter('.amount .unit')->count() === 0) { - $garnish .= trim($node->filter('.ingredient')->text()) . "\n"; + $garnish .= trim((string) $node->filter('.ingredient')->text()) . "\n"; } }); @@ -116,7 +116,7 @@ public function garnish(): ?string public function image(): ?array { $srcSet = $this->crawler->filter('.recipe__primary-image.recipe__primary-image--1')->first()->attr('srcset'); - $sources = explode(' ', $srcSet); + $sources = explode(' ', (string) $srcSet); if (!$sources[2]) { return null; diff --git a/app/Services/Auth/PocketIdProvider.php b/app/Services/Auth/PocketIdProvider.php index 1136b54c..1fe045fd 100644 --- a/app/Services/Auth/PocketIdProvider.php +++ b/app/Services/Auth/PocketIdProvider.php @@ -28,7 +28,7 @@ public static function additionalConfigKeys(): array protected function getBaseUrl(): string { - return rtrim($this->getConfig('base_url'), '/'); + return rtrim((string) $this->getConfig('base_url'), '/'); } /** diff --git a/app/Services/Auth/SSOService.php b/app/Services/Auth/SSOService.php index 58843158..472dd7e6 100644 --- a/app/Services/Auth/SSOService.php +++ b/app/Services/Auth/SSOService.php @@ -9,9 +9,9 @@ use Kami\Cocktail\OpenAPI\Schemas\RegisterRequest; use Laravel\Socialite\Contracts\User as SocialiteUser; -final class SSOService +final readonly class SSOService { - public function __construct(private readonly RegisterUserService $registerUserService) + public function __construct(private RegisterUserService $registerUserService) { } diff --git a/app/Services/BarOptimizerService.php b/app/Services/BarOptimizerService.php index e80bd02c..ac57b121 100644 --- a/app/Services/BarOptimizerService.php +++ b/app/Services/BarOptimizerService.php @@ -11,10 +11,10 @@ use Kami\Cocktail\Models\Ingredient; use Kami\Cocktail\Models\ValueObjects\UnitValueObject; -final class BarOptimizerService +final readonly class BarOptimizerService { public function __construct( - private readonly IngredientService $ingredientRepository, + private IngredientService $ingredientRepository, ) { } diff --git a/app/Services/CocktailService.php b/app/Services/CocktailService.php index 89999a22..d4efecc2 100644 --- a/app/Services/CocktailService.php +++ b/app/Services/CocktailService.php @@ -20,11 +20,11 @@ use Kami\Cocktail\Exceptions\ImagesNotAttachedException; use Kami\Cocktail\OpenAPI\Schemas\CocktailRequest as CocktailDTO; -final class CocktailService +final readonly class CocktailService { public function __construct( - private readonly DatabaseManager $db, - private readonly LogManager $log, + private DatabaseManager $db, + private LogManager $log, ) { } @@ -100,7 +100,7 @@ public function createCocktail(CocktailDTO $cocktailDTO): Cocktail try { $imageModels = Image::findOrFail($cocktailDTO->images); $cocktail->attachImages($imageModels); - } catch (Throwable $e) { + } catch (Throwable) { throw new ImagesNotAttachedException('Unable to attach images to cocktail'); } } @@ -207,7 +207,7 @@ public function updateCocktail(int $id, CocktailDTO $cocktailDTO): Cocktail try { $imageModels = Image::findOrFail($cocktailDTO->images); $cocktail->attachImages($imageModels); - } catch (Throwable $e) { + } catch (Throwable) { throw new ImagesNotAttachedException(); } } diff --git a/app/Services/Feeds/RecipeFeedsService.php b/app/Services/Feeds/RecipeFeedsService.php index 6fbacb59..c910a613 100644 --- a/app/Services/Feeds/RecipeFeedsService.php +++ b/app/Services/Feeds/RecipeFeedsService.php @@ -56,9 +56,7 @@ public function fetch(): array } // Sort the recipes by date - usort($recipes, function (FeedsRecipe $a, FeedsRecipe $b) { - return $b->dateModified <=> $a->dateModified; - }); + usort($recipes, fn(FeedsRecipe $a, FeedsRecipe $b) => $b->dateModified <=> $a->dateModified); return $recipes; } diff --git a/app/Services/Image/ImageService.php b/app/Services/Image/ImageService.php index 56b01cea..8188f485 100644 --- a/app/Services/Image/ImageService.php +++ b/app/Services/Image/ImageService.php @@ -154,7 +154,7 @@ public function cleanBarImages(Bar $bar): void */ private function processImageFile(string $image, ?string $filename = null): array { - $filename = $filename ?? Str::random(40); + $filename ??= Str::random(40); try { $fileExtension = 'webp'; diff --git a/app/Services/IngredientService.php b/app/Services/IngredientService.php index 52a1668b..8504de32 100644 --- a/app/Services/IngredientService.php +++ b/app/Services/IngredientService.php @@ -19,11 +19,11 @@ use Kami\Cocktail\Exceptions\ImagesNotAttachedException; use Kami\Cocktail\Exceptions\IngredientValidationException; -final class IngredientService +final readonly class IngredientService { public function __construct( - private readonly LogManager $log, - private readonly DatabaseManager $db, + private LogManager $log, + private DatabaseManager $db, ) { } @@ -87,7 +87,7 @@ public function createIngredient(IngredientRequest $dto): Ingredient try { $imageModels = Image::findOrFail($dto->images); $ingredient->attachImages($imageModels); - } catch (Throwable $e) { + } catch (Throwable) { throw new ImagesNotAttachedException(); } } @@ -176,7 +176,7 @@ public function updateIngredient(int $id, IngredientRequest $dto): Ingredient try { $imageModels = Image::findOrFail($dto->images); $ingredient->attachImages($imageModels); - } catch (Throwable $e) { + } catch (Throwable) { throw new ImagesNotAttachedException(); } } diff --git a/app/Utils.php b/app/Utils.php index 50fbd30a..e2057e22 100644 --- a/app/Utils.php +++ b/app/Utils.php @@ -23,9 +23,7 @@ public static function calculateAbv(array $ingredients, int $dilutionPercentage) $dilutionPercentage = $dilutionPercentage / 100; $amountUsed = array_sum(array_column($ingredients, 'amount')); - $alcoholVolume = floatval(array_reduce($ingredients, function ($carry, $item) { - return (($item['amount'] * $item['strength']) / 100) + $carry; - })); + $alcoholVolume = floatval(array_reduce($ingredients, fn($carry, $item) => (($item['amount'] * $item['strength']) / 100) + $carry)); $afterDilution = ($amountUsed * $dilutionPercentage) + $amountUsed; diff --git a/app/ZipUtils.php b/app/ZipUtils.php index 85eb5315..073c277c 100644 --- a/app/ZipUtils.php +++ b/app/ZipUtils.php @@ -12,8 +12,8 @@ class ZipUtils { - private Filesystem $unzipDisk; - private string $dirName; + private readonly Filesystem $unzipDisk; + private readonly string $dirName; public function __construct() { diff --git a/composer.json b/composer.json index bee27e6f..d412c0b7 100644 --- a/composer.json +++ b/composer.json @@ -39,13 +39,15 @@ }, "require-dev": { "barryvdh/laravel-debugbar": "^3.7", + "driftingly/rector-laravel": "^2.1", "fakerphp/faker": "^1.9.1", "larastan/larastan": "^3.0", "laravel/pint": "^1.0", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.6", "phpstan/phpstan": "^2.0", - "phpunit/phpunit": "^11.0" + "phpunit/phpunit": "^11.0", + "rector/rector": "^2.2" }, "autoload": { "files": [ diff --git a/composer.lock b/composer.lock index 2a30b87a..027754ea 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": "832f605d9d287023e3ded62286dd19e0", + "content-hash": "5fc248aafd09830734d0fdb586728a02", "packages": [ { "name": "brick/math", @@ -9943,6 +9943,41 @@ ], "time": "2025-07-14T11:56:43+00:00" }, + { + "name": "driftingly/rector-laravel", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/driftingly/rector-laravel.git", + "reference": "efb636a08dfddfa2a3f4527b1dd970a898a075a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/driftingly/rector-laravel/zipball/efb636a08dfddfa2a3f4527b1dd970a898a075a4", + "reference": "efb636a08dfddfa2a3f4527b1dd970a898a075a4", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "rector/rector": "^2.0" + }, + "type": "rector-extension", + "autoload": { + "psr-4": { + "RectorLaravel\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Rector upgrades rules for Laravel Framework", + "support": { + "issues": "https://github.com/driftingly/rector-laravel/issues", + "source": "https://github.com/driftingly/rector-laravel/tree/2.1.0" + }, + "time": "2025-10-12T21:51:39+00:00" + }, { "name": "fakerphp/faker", "version": "v1.24.1", @@ -11254,6 +11289,66 @@ ], "time": "2025-09-28T12:09:13+00:00" }, + { + "name": "rector/rector", + "version": "2.2.3", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "d27f976a332a87b5d03553c2e6f04adbe5da034f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/d27f976a332a87b5d03553c2e6f04adbe5da034f", + "reference": "d27f976a332a87b5d03553c2e6f04adbe5da034f", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "phpstan/phpstan": "^2.1.26" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "suggest": { + "ext-dom": "To manipulate phpunit.xml via the custom-rule command" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "homepage": "https://getrector.com/", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/2.2.3" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2025-10-11T21:50:23+00:00" + }, { "name": "sebastian/cli-parser", "version": "3.0.2", diff --git a/config/bar-assistant.php b/config/bar-assistant.php index ce677efb..e9108967 100644 --- a/config/bar-assistant.php +++ b/config/bar-assistant.php @@ -64,11 +64,11 @@ */ 'enable_billing' => env('ENABLE_BILLING', false), - 'prices' => explode('|', env('BILLING_PRODUCT_PRICES', '')), + 'prices' => explode('|', (string) env('BILLING_PRODUCT_PRICES', '')), 'metrics' => [ 'enabled' => (bool) env('METRICS_ENABLED', false), - 'allowed_ips' => explode(',', env('METRICS_ALLOWED_IPS', '')), + 'allowed_ips' => explode(',', (string) env('METRICS_ALLOWED_IPS', '')), ], 'enable_feeds' => (bool) env('ENABLE_FEEDS', false), diff --git a/config/sanctum.php b/config/sanctum.php index d6e1ddd7..23861997 100644 --- a/config/sanctum.php +++ b/config/sanctum.php @@ -15,7 +15,7 @@ | */ - 'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( + 'stateful' => explode(',', (string) env('SANCTUM_STATEFUL_DOMAINS', sprintf( '%s%s', 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', Sanctum::currentApplicationUrlWithPort() diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..514eb50c --- /dev/null +++ b/rector.php @@ -0,0 +1,18 @@ +withPaths([ + __DIR__ . '/app', + __DIR__ . '/bootstrap', + __DIR__ . '/config', + __DIR__ . '/public', + __DIR__ . '/resources', + __DIR__ . '/routes', + __DIR__ . '/tests', + ]) + ->withPhpSets(); diff --git a/routes/api.php b/routes/api.php index e79a13a9..a09a742e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -297,9 +297,7 @@ }); }); -Route::fallback(function () { - return response()->json([ - 'type' => 'api_error', - 'message' => 'Endpoint not found.' - ], 404); -}); +Route::fallback(fn() => response()->json([ + 'type' => 'api_error', + 'message' => 'Endpoint not found.' +], 404)); diff --git a/routes/web.php b/routes/web.php index d074399c..c6955158 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,13 +15,9 @@ | */ -Route::get('/', function () { - return 'This is your Bar Assistant instance. Checkout /docs to see documentation.
If you are trying to make a request to the API, make sure you are using the correct endpoint (e.g., /api/cocktails).
Also make sure you are using all the required headers: Accept, Authorization.'; -}); +Route::get('/', fn() => 'This is your Bar Assistant instance. Checkout /docs to see documentation.
If you are trying to make a request to the API, make sure you are using the correct endpoint (e.g., /api/cocktails).
Also make sure you are using all the required headers: Accept, Authorization.'); -Route::get('/docs', function () { - return view('elements'); -}); +Route::get('/docs', fn() => view('elements')); if (config('bar-assistant.metrics.enabled') === true) { Route::get('/metrics', [MetricsController::class, 'index'])->name('metrics')->middleware(CheckMetricsAccess::class); diff --git a/tests/Feature/Http/AuthControllerTest.php b/tests/Feature/Http/AuthControllerTest.php index 0ecdab2e..f225ec2a 100644 --- a/tests/Feature/Http/AuthControllerTest.php +++ b/tests/Feature/Http/AuthControllerTest.php @@ -89,9 +89,7 @@ public function test_register_response_sends_confirm_email(): void 'name' => 'Test Guy', ]); - Mail::assertQueued(ConfirmAccount::class, function (ConfirmAccount $mail) { - return $mail->hasTo('test@test.com'); - }); + Mail::assertQueued(ConfirmAccount::class, fn(ConfirmAccount $mail) => $mail->hasTo('test@test.com')); } public function test_forgot_password_response(): void @@ -106,9 +104,7 @@ public function test_forgot_password_response(): void 'email' => 'test@test.com' ]); - Mail::assertQueued(PasswordReset::class, function (PasswordReset $mail) { - return $mail->hasTo('test@test.com'); - }); + Mail::assertQueued(PasswordReset::class, fn(PasswordReset $mail) => $mail->hasTo('test@test.com')); $response->assertSuccessful(); } diff --git a/tests/Feature/Http/ShoppingListControllerTest.php b/tests/Feature/Http/ShoppingListControllerTest.php index 322d1791..d627103d 100644 --- a/tests/Feature/Http/ShoppingListControllerTest.php +++ b/tests/Feature/Http/ShoppingListControllerTest.php @@ -43,9 +43,7 @@ public function test_add_multiple_ingredients_to_shopping_list_response(): void $ingredients = Ingredient::factory()->recycle($membership->bar)->count(3)->create(); $response = $this->postJson('/api/users/'. $membership->user_id .'/shopping-list/batch-store', [ - 'ingredients' => $ingredients->map(function ($ing) { - return ['id' => $ing->id]; - })->toArray() + 'ingredients' => $ingredients->map(fn($ing) => ['id' => $ing->id])->toArray() ], ['Bar-Assistant-Bar-Id' => $membership->bar_id]); $response->assertNoContent(); @@ -59,9 +57,7 @@ public function test_add_multiple_ingredients_to_shopping_list_from_another_bar_ $unOwnedIngredients = Ingredient::factory()->count(3)->create(); $response = $this->postJson('/api/users/'. $membership->user_id .'/shopping-list/batch-store', [ - 'ingredients' => $unOwnedIngredients->map(function ($ing) { - return ['id' => $ing->id]; - })->toArray() + 'ingredients' => $unOwnedIngredients->map(fn($ing) => ['id' => $ing->id])->toArray() ], ['Bar-Assistant-Bar-Id' => $membership->bar_id]); $response->assertNoContent(); @@ -81,9 +77,7 @@ public function test_delete_multiple_ingredients_from_shopping_list_response(): $this->assertDatabaseCount('user_shopping_lists', 5); $response = $this->postJson('/api/users/'. $membership->user_id .'/shopping-list/batch-delete', [ - 'ingredients' => $ingredients->pluck('ingredient')->map(function ($ing) { - return ['id' => $ing->id]; - })->toArray() + 'ingredients' => $ingredients->pluck('ingredient')->map(fn($ing) => ['id' => $ing->id])->toArray() ], ['Bar-Assistant-Bar-Id' => $membership->bar_id]); $response->assertNoContent(); diff --git a/tests/Feature/Http/UsersControllerTest.php b/tests/Feature/Http/UsersControllerTest.php index f9e74033..2a92f6c9 100644 --- a/tests/Feature/Http/UsersControllerTest.php +++ b/tests/Feature/Http/UsersControllerTest.php @@ -135,7 +135,7 @@ public function test_delete_user_response(): void $anonUser = DB::table('users')->find($user->id); $this->assertSame('Deleted User', $anonUser->name); $this->assertSame('deleted', $anonUser->password); - $this->assertTrue(str_starts_with($anonUser->email, 'userdeleted')); + $this->assertTrue(str_starts_with((string) $anonUser->email, 'userdeleted')); $this->assertNull($anonUser->email_verified_at); $this->assertNull($anonUser->remember_token); } From aac1ba1e1a7cd00b4b9087e8656261098df8cdb7 Mon Sep 17 00:00:00 2001 From: Karlo Mikus Date: Sun, 2 Nov 2025 17:04:11 +0100 Subject: [PATCH 2/4] Fix public menu #375 --- CHANGELOG.md | 4 ++++ app/Http/Controllers/Public/BarController.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ebb222..76127a3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v5.9.1 +## Fixes +- Public menu can be enabled independently of `is_public` bar setting + # v5.9.0 # New - Documented `public/{slugOrId}` endpoints diff --git a/app/Http/Controllers/Public/BarController.php b/app/Http/Controllers/Public/BarController.php index 8cab6f09..aae9d86c 100644 --- a/app/Http/Controllers/Public/BarController.php +++ b/app/Http/Controllers/Public/BarController.php @@ -23,7 +23,7 @@ class BarController extends Controller public function show(string $slugOrId): BarResource { $bar = Bar::where('slug', $slugOrId)->orWhere('id', $slugOrId)->firstOrFail(); - if (!$bar->isPublic()) { + if (!$bar->isPublic() && !$bar->menu->is_enabled) { abort(404); } From 0d22d340ac5cb865d42d00ef3bda0b57e855fd3c Mon Sep 17 00:00:00 2001 From: Karlo Mikus Date: Sun, 2 Nov 2025 17:08:22 +0100 Subject: [PATCH 3/4] csfix --- app/Exceptions/Handler.php | 4 ++-- app/External/Import/FromDataPack.php | 4 ++-- app/External/Model/Calculator.php | 2 +- app/External/Model/Cocktail.php | 6 +++--- app/External/Model/CocktailIngredient.php | 2 +- app/External/Model/Ingredient.php | 6 +++--- app/Http/Controllers/IngredientController.php | 2 +- app/Http/Controllers/Public/CocktailController.php | 2 +- app/Http/Middleware/CheckMetricsAccess.php | 2 +- app/Http/Middleware/EnsureRequestHasBarQuery.php | 4 ++-- app/Http/Resources/CocktailBasicResource.php | 2 +- app/Http/Resources/CocktailResource.php | 6 +++--- app/Http/Resources/CollectionResource.php | 2 +- app/Http/Resources/ExploreCocktailResource.php | 6 +++--- app/Http/Resources/IngredientBasicResource.php | 2 +- app/Http/Resources/IngredientResource.php | 2 +- app/Http/Resources/MenuPublicResource.php | 4 ++-- app/Http/Resources/MenuResource.php | 4 ++-- app/Http/Resources/Public/CocktailResource.php | 6 +++--- app/Http/Resources/UserResource.php | 2 +- app/Metrics/MetricsServiceProvider.php | 2 +- app/Metrics/TotalBars.php | 2 +- app/Models/Cocktail.php | 8 ++++---- app/Models/Relations/HasManyAncestors.php | 2 +- app/Models/Relations/HasManyDescendants.php | 2 +- app/Providers/HorizonServiceProvider.php | 2 +- app/Providers/RouteServiceProvider.php | 8 ++++---- app/Scraper/AbstractSite.php | 4 ++-- app/Scraper/Sites/CocktailParty.php | 4 ++-- app/Services/Feeds/RecipeFeedsService.php | 2 +- app/Utils.php | 2 +- routes/api.php | 2 +- routes/web.php | 4 ++-- tests/Feature/Http/AuthControllerTest.php | 4 ++-- tests/Feature/Http/ShoppingListControllerTest.php | 6 +++--- 35 files changed, 62 insertions(+), 62 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 72cc4468..202c20e5 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -60,12 +60,12 @@ public function register() } }); - $this->renderable(fn(NotFoundHttpException $e, $request) => response()->json([ + $this->renderable(fn (NotFoundHttpException $e, $request) => response()->json([ 'type' => 'api_error', 'message' => 'Resource not found.', ], 404)); - $this->renderable(fn(MethodNotAllowedHttpException $e, $request) => response()->json([ + $this->renderable(fn (MethodNotAllowedHttpException $e, $request) => response()->json([ 'type' => 'api_error', 'message' => $e->getMessage(), ], 405)); diff --git a/app/External/Import/FromDataPack.php b/app/External/Import/FromDataPack.php index eb20366e..ca96a651 100644 --- a/app/External/Import/FromDataPack.php +++ b/app/External/Import/FromDataPack.php @@ -175,7 +175,7 @@ private function importIngredients(Filesystem $dataDisk, Bar $bar, User $user): { $timerStart = microtime(true); - $existingIngredients = DB::table('ingredients')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(fn($ingredient) => Str::slug($ingredient->name)); + $existingIngredients = DB::table('ingredients')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(fn ($ingredient) => Str::slug($ingredient->name)); $ingredientsToInsert = []; $parentIngredientsToInsert = []; @@ -320,7 +320,7 @@ private function importBaseCocktails(Filesystem $dataDisk, Bar $bar, User $user) $dbIngredients = DB::table('ingredients')->select('id', DB::raw('LOWER(name) AS name'))->where('bar_id', $bar->id)->get()->keyBy('name')->map(fn ($row) => $row->id)->toArray(); $dbGlasses = DB::table('glasses')->select('id', DB::raw('LOWER(name) AS name'))->where('bar_id', $bar->id)->get()->keyBy('name')->map(fn ($row) => $row->id)->toArray(); $dbMethods = DB::table('cocktail_methods')->select('id', DB::raw('LOWER(name) AS name'))->where('bar_id', $bar->id)->get()->keyBy('name')->map(fn ($row) => $row->id)->toArray(); - $existingCocktails = DB::table('cocktails')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(fn($cocktail) => Str::slug($cocktail->name)); + $existingCocktails = DB::table('cocktails')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(fn ($cocktail) => Str::slug($cocktail->name)); $cocktailImages = []; $uniqueTags = []; diff --git a/app/External/Model/Calculator.php b/app/External/Model/Calculator.php index 7db7ee14..91c128c4 100644 --- a/app/External/Model/Calculator.php +++ b/app/External/Model/Calculator.php @@ -27,7 +27,7 @@ public static function fromModel(CalculatorModel $model): self $model->getExternalId(), $model->name, $model->description, - $model->blocks->map(fn(CalculatorBlock $block) => [ + $model->blocks->map(fn (CalculatorBlock $block) => [ 'label' => $block->label, 'variable_name' => $block->variable_name, 'value' => $block->value, diff --git a/app/External/Model/Cocktail.php b/app/External/Model/Cocktail.php index 8758d7bf..960ecfab 100644 --- a/app/External/Model/Cocktail.php +++ b/app/External/Model/Cocktail.php @@ -45,9 +45,9 @@ private function __construct( public static function fromModel(CocktailModel $model, bool $useFileURI = false, ?Units $toUnits = null): self { - $images = $model->images->map(fn(ImageModel $image) => Image::fromModel($image, $useFileURI))->toArray(); + $images = $model->images->map(fn (ImageModel $image) => Image::fromModel($image, $useFileURI))->toArray(); - $ingredients = $model->ingredients->map(fn(CocktailIngredientModel $cocktailIngredient) => CocktailIngredient::fromModel($cocktailIngredient, $toUnits))->toArray(); + $ingredients = $model->ingredients->map(fn (CocktailIngredientModel $cocktailIngredient) => CocktailIngredient::fromModel($cocktailIngredient, $toUnits))->toArray(); return new self( $model->getExternalId(), @@ -207,7 +207,7 @@ public function toJSONLD(): string "recipeCategory" => "Drink", "recipeCuisine" => "Cocktail", "keywords" => implode(', ', $this->tags), - "recipeIngredient" => array_map(fn(CocktailIngredient $ci) => (new CocktailIngredientFormatter($ci->amount, $ci->ingredient->name, $ci->optional))->format(), $this->ingredients), + "recipeIngredient" => array_map(fn (CocktailIngredient $ci) => (new CocktailIngredientFormatter($ci->amount, $ci->ingredient->name, $ci->optional))->format(), $this->ingredients), ], ['image' => $image]); if ($data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)) { diff --git a/app/External/Model/CocktailIngredient.php b/app/External/Model/CocktailIngredient.php index 01330829..c01e8a4f 100644 --- a/app/External/Model/CocktailIngredient.php +++ b/app/External/Model/CocktailIngredient.php @@ -31,7 +31,7 @@ private function __construct( public static function fromModel(CocktailIngredientModel $model, ?Units $toUnits = null): self { - $substitutes = $model->substitutes->map(fn(CocktailIngredientSubstituteModel $substitute) => CocktailIngredientSubstitute::fromModel($substitute, $toUnits))->toArray(); + $substitutes = $model->substitutes->map(fn (CocktailIngredientSubstituteModel $substitute) => CocktailIngredientSubstitute::fromModel($substitute, $toUnits))->toArray(); $amount = $model->getAmount(); if ($toUnits && !$model->getAmount()->units->isDash()) { diff --git a/app/External/Model/Ingredient.php b/app/External/Model/Ingredient.php index 4d1b1785..4343e9a0 100644 --- a/app/External/Model/Ingredient.php +++ b/app/External/Model/Ingredient.php @@ -45,11 +45,11 @@ private function __construct( public static function fromModel(IngredientModel $model, bool $useFileURI = false, ?Units $toUnits = null): self { - $images = $model->images->map(fn(ImageModel $image) => Image::fromModel($image, $useFileURI))->toArray(); + $images = $model->images->map(fn (ImageModel $image) => Image::fromModel($image, $useFileURI))->toArray(); - $ingredientParts = $model->ingredientParts->map(fn(ComplexIngredient $part) => Ingredient::fromModel($part->ingredient))->toArray(); + $ingredientParts = $model->ingredientParts->map(fn (ComplexIngredient $part) => Ingredient::fromModel($part->ingredient))->toArray(); - $ingredientPrices = $model->prices->map(fn(IngredientPriceModel $price) => IngredientPrice::fromModel($price))->toArray(); + $ingredientPrices = $model->prices->map(fn (IngredientPriceModel $price) => IngredientPrice::fromModel($price))->toArray(); $defaultIngredientUnits = $model->getDefaultUnits(); if ($model->getDefaultUnits()?->isConvertable() && $toUnits) { diff --git a/app/Http/Controllers/IngredientController.php b/app/Http/Controllers/IngredientController.php index b69ee1d8..f2e118e3 100644 --- a/app/Http/Controllers/IngredientController.php +++ b/app/Http/Controllers/IngredientController.php @@ -217,7 +217,7 @@ public function extra(Request $request, CocktailService $cocktailRepo, string $i $extraCocktails = Cocktail::whereIn('id', $extraShelfCocktails->diff($currentShelfCocktails)->values())->where('bar_id', '=', $ingredient->bar_id)->get(); return response()->json([ - 'data' => $extraCocktails->map(fn(Cocktail $cocktail) => [ + 'data' => $extraCocktails->map(fn (Cocktail $cocktail) => [ 'id' => $cocktail->id, 'slug' => $cocktail->slug, 'name' => $cocktail->name, diff --git a/app/Http/Controllers/Public/CocktailController.php b/app/Http/Controllers/Public/CocktailController.php index 903a05f7..7fec4da0 100644 --- a/app/Http/Controllers/Public/CocktailController.php +++ b/app/Http/Controllers/Public/CocktailController.php @@ -59,7 +59,7 @@ public function index(Request $request, string $slugOrId): JsonResource abort(400, $e->getMessage()); } - $cocktails = $cocktailsQuery->paginate(50); + $cocktails = $cocktailsQuery->paginate(52); Cache::put($cacheKey, $cocktails, 3600); diff --git a/app/Http/Middleware/CheckMetricsAccess.php b/app/Http/Middleware/CheckMetricsAccess.php index 2c1ab96f..c1c8ff78 100644 --- a/app/Http/Middleware/CheckMetricsAccess.php +++ b/app/Http/Middleware/CheckMetricsAccess.php @@ -26,7 +26,7 @@ public function handle(Request $request, Closure $next) return $next($request); } - $whitelist = array_filter(config('bar-assistant.metrics.allowed_ips', []), fn($ip) => $ip !== ''); + $whitelist = array_filter(config('bar-assistant.metrics.allowed_ips', []), fn ($ip) => $ip !== ''); if (count($whitelist) === 0) { abort(404); diff --git a/app/Http/Middleware/EnsureRequestHasBarQuery.php b/app/Http/Middleware/EnsureRequestHasBarQuery.php index 673bc670..0db124e3 100644 --- a/app/Http/Middleware/EnsureRequestHasBarQuery.php +++ b/app/Http/Middleware/EnsureRequestHasBarQuery.php @@ -24,13 +24,13 @@ public function handle(Request $request, Closure $next): Response abort(400, sprintf("Missing required bar reference while requesting '%s'. Use 'Bar-Assistant-Bar-Id' header to specify bar id.", $request->path())); } - $bar = Cache::remember('ba:bar:' . $barId, 60 * 60 * 24, fn() => Bar::findOrFail($barId)); + $bar = Cache::remember('ba:bar:' . $barId, 60 * 60 * 24, fn () => Bar::findOrFail($barId)); if ($request->user()->cannot('access', $bar)) { abort(403); } - app()->singleton(BarContext::class, fn() => new BarContext($bar)); + app()->singleton(BarContext::class, fn () => new BarContext($bar)); return $next($request); } diff --git a/app/Http/Resources/CocktailBasicResource.php b/app/Http/Resources/CocktailBasicResource.php index f14c35e6..48b98e08 100644 --- a/app/Http/Resources/CocktailBasicResource.php +++ b/app/Http/Resources/CocktailBasicResource.php @@ -37,7 +37,7 @@ public function toArray($request) 'slug' => $this->slug, 'name' => $this->name, 'short_ingredients' => $this->getIngredientNames(), - 'image' => $this->when($this->relationLoaded('images'), fn() => new ImageResource($this->getMainImage())), + 'image' => $this->when($this->relationLoaded('images'), fn () => new ImageResource($this->getMainImage())), ]; } } diff --git a/app/Http/Resources/CocktailResource.php b/app/Http/Resources/CocktailResource.php index fdea1e80..b652c17c 100644 --- a/app/Http/Resources/CocktailResource.php +++ b/app/Http/Resources/CocktailResource.php @@ -104,7 +104,7 @@ public function toArray($request) ), 'tags' => $this->when( $this->relationLoaded('tags'), - fn () => $this->tags->map(fn($tag) => [ + fn () => $this->tags->map(fn ($tag) => [ 'id' => $tag->id, 'name' => $tag->name, ]) @@ -132,13 +132,13 @@ public function toArray($request) 'in_shelf' => in_array($this->id, $request->user()->getShelfCocktailsOnce($this->bar_id)), 'in_bar_shelf' => in_array($this->id, $this->bar->getShelfCocktailsOnce()), 'is_favorited' => $request->user()->getBarMembership($this->bar_id)->cocktailFavorites->where('cocktail_id', $this->id)->isNotEmpty(), - 'access' => $this->when(true, fn() => [ + 'access' => $this->when(true, fn () => [ 'can_edit' => $request->user()->can('edit', $this->resource), 'can_delete' => $request->user()->can('delete', $this->resource), 'can_rate' => $request->user()->can('rate', $this->resource), 'can_add_note' => $request->user()->can('addNote', $this->resource), ]), - 'parent_cocktail' => $this->whenLoaded('parentCocktail', fn() => new CocktailBasicResource($this->parentCocktail)), + 'parent_cocktail' => $this->whenLoaded('parentCocktail', fn () => new CocktailBasicResource($this->parentCocktail)), 'varieties' => CocktailBasicResource::collection($this->whenLoaded('cocktailVarieties')), 'year' => $this->year, ]; diff --git a/app/Http/Resources/CollectionResource.php b/app/Http/Resources/CollectionResource.php index 6db6d103..0c49cd59 100644 --- a/app/Http/Resources/CollectionResource.php +++ b/app/Http/Resources/CollectionResource.php @@ -40,7 +40,7 @@ public function toArray($request) 'description' => $this->description, 'is_bar_shared' => $this->is_bar_shared, 'created_at' => $this->created_at->toAtomString(), - 'created_user' => $this->whenLoaded('barMembership', fn() => new UserBasicResource($this->barMembership->user)), + 'created_user' => $this->whenLoaded('barMembership', fn () => new UserBasicResource($this->barMembership->user)), 'cocktails' => CocktailBasicResource::collection($this->whenLoaded('cocktails')), ]; } diff --git a/app/Http/Resources/ExploreCocktailResource.php b/app/Http/Resources/ExploreCocktailResource.php index d8a7a441..c923916a 100644 --- a/app/Http/Resources/ExploreCocktailResource.php +++ b/app/Http/Resources/ExploreCocktailResource.php @@ -89,14 +89,14 @@ public function toArray($request) 'glass' => $this->glass->name ?? null, 'utensils' => $this->utensils->pluck('name'), 'method' => $this->method->name ?? null, - 'images' => $this->images->map(fn(Image $image) => [ + 'images' => $this->images->map(fn (Image $image) => [ 'sort' => $image->sort, 'placeholder_hash' => $image->placeholder_hash, 'url' => $image->getImageUrl(), 'copyright' => $image->copyright, ]), 'abv' => $this->abv, - 'ingredients' => $this->ingredients->map(fn(CocktailIngredient $cocktailIngredient) => [ + 'ingredients' => $this->ingredients->map(fn (CocktailIngredient $cocktailIngredient) => [ 'ingredient' => [ 'name' => $cocktailIngredient->ingredient->name, ], @@ -105,7 +105,7 @@ public function toArray($request) 'units' => $cocktailIngredient->units, 'optional' => (bool) $cocktailIngredient->optional, 'note' => $cocktailIngredient->note, - 'substitutes' => $cocktailIngredient->substitutes->map(fn(CocktailIngredientSubstitute $substitute) => [ + 'substitutes' => $cocktailIngredient->substitutes->map(fn (CocktailIngredientSubstitute $substitute) => [ 'ingredient' => [ 'name' => $substitute->ingredient->name, ], diff --git a/app/Http/Resources/IngredientBasicResource.php b/app/Http/Resources/IngredientBasicResource.php index 3a2a541b..a746d38a 100644 --- a/app/Http/Resources/IngredientBasicResource.php +++ b/app/Http/Resources/IngredientBasicResource.php @@ -35,7 +35,7 @@ public function toArray($request) 'id' => $this->id, 'slug' => $this->slug, 'name' => $this->name, - 'image' => $this->when($this->relationLoaded('images'), fn() => new ImageResource($this->getMainImage())), + 'image' => $this->when($this->relationLoaded('images'), fn () => new ImageResource($this->getMainImage())), ]; } } diff --git a/app/Http/Resources/IngredientResource.php b/app/Http/Resources/IngredientResource.php index 4b1c7346..b284b3d5 100644 --- a/app/Http/Resources/IngredientResource.php +++ b/app/Http/Resources/IngredientResource.php @@ -112,7 +112,7 @@ public function toArray($request) $this->relationLoaded('ingredientParts'), fn () => $this->ingredientParts->map(fn ($cip) => new IngredientBasicResource($cip->ingredient)) ), - 'prices' => $this->when($this->relationLoaded('prices'), fn() => IngredientPriceResource::collection($this->prices)), + 'prices' => $this->when($this->relationLoaded('prices'), fn () => IngredientPriceResource::collection($this->prices)), 'calculator_id' => $this->calculator_id, 'sugar_g_per_ml' => $this->sugar_g_per_ml, 'acidity' => $this->acidity, diff --git a/app/Http/Resources/MenuPublicResource.php b/app/Http/Resources/MenuPublicResource.php index 63d24299..0b2aa031 100644 --- a/app/Http/Resources/MenuPublicResource.php +++ b/app/Http/Resources/MenuPublicResource.php @@ -71,9 +71,9 @@ public function toArray($request) fn () => $this->bar->images->map(fn (Image $image) => $image->getImageUrl())->toArray(), ), ], - 'categories' => $this->getMenuItems()->groupBy('categoryName')->map(fn($items, $name) => [ + 'categories' => $this->getMenuItems()->groupBy('categoryName')->map(fn ($items, $name) => [ 'name' => $name, - 'items' => $items->sortBy(fn ($menuItem) => $menuItem->sort)->values()->map(fn(MenuItem $menuItem) => [ + 'items' => $items->sortBy(fn ($menuItem) => $menuItem->sort)->values()->map(fn (MenuItem $menuItem) => [ 'in_bar_shelf' => $menuItem->inShelf, 'type' => $menuItem->type->value, 'sort' => $menuItem->sort, diff --git a/app/Http/Resources/MenuResource.php b/app/Http/Resources/MenuResource.php index df2179ca..7d47c755 100644 --- a/app/Http/Resources/MenuResource.php +++ b/app/Http/Resources/MenuResource.php @@ -49,9 +49,9 @@ public function toArray($request) 'is_enabled' => (bool) $this->is_enabled, 'created_at' => $this->created_at->toAtomString(), 'updated_at' => $this->updated_at?->toAtomString(), - 'categories' => $this->getMenuItems()->groupBy('categoryName')->map(fn($items, $name) => [ + 'categories' => $this->getMenuItems()->groupBy('categoryName')->map(fn ($items, $name) => [ 'name' => $name, - 'items' => $items->sortBy(fn ($menuItem) => $menuItem->sort)->values()->map(fn(MenuItem $menuItem) => [ + 'items' => $items->sortBy(fn ($menuItem) => $menuItem->sort)->values()->map(fn (MenuItem $menuItem) => [ 'id' => $menuItem->id, 'type' => $menuItem->type->value, 'sort' => $menuItem->sort, diff --git a/app/Http/Resources/Public/CocktailResource.php b/app/Http/Resources/Public/CocktailResource.php index ec64547c..979e03f5 100644 --- a/app/Http/Resources/Public/CocktailResource.php +++ b/app/Http/Resources/Public/CocktailResource.php @@ -94,7 +94,7 @@ public function toArray($request) 'images' => ImageResource::collection($this->images), 'tags' => $this->when( $this->relationLoaded('tags'), - fn () => $this->tags->map(fn($tag) => $tag->name) + fn () => $this->tags->map(fn ($tag) => $tag->name) ), 'glass' => $this->glass->name ?? null, 'utensils' => $this->utensils->pluck('name'), @@ -105,7 +105,7 @@ public function toArray($request) 'in_bar_shelf' => $this->inBarShelf(), 'abv' => $this->abv, 'year' => $this->year, - 'ingredients' => $this->ingredients->map(fn(CocktailIngredient $cocktailIngredient) => [ + 'ingredients' => $this->ingredients->map(fn (CocktailIngredient $cocktailIngredient) => [ 'name' => $cocktailIngredient->ingredient->name, 'amount' => $cocktailIngredient->amount, 'amount_max' => $cocktailIngredient->amount_max, @@ -113,7 +113,7 @@ public function toArray($request) 'units_formatted' => new AmountFormats($cocktailIngredient), 'optional' => (bool) $cocktailIngredient->optional, 'note' => $cocktailIngredient->note, - 'substitutes' => $cocktailIngredient->substitutes->map(fn(CocktailIngredientSubstitute $substitute) => [ + 'substitutes' => $cocktailIngredient->substitutes->map(fn (CocktailIngredientSubstitute $substitute) => [ 'name' => $substitute->ingredient->name, 'amount' => $substitute->amount, 'amount_max' => $substitute->amount_max, diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index 764964dc..b966ac44 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -54,7 +54,7 @@ public function toArray($request) 'name' => $this->name, 'email' => $this->email, 'is_subscribed' => $this->hasActiveSubscription(), - 'role' => $this->memberships->where('bar_id', $bar->id)->map(fn(BarMembership $membership) => [ + 'role' => $this->memberships->where('bar_id', $bar->id)->map(fn (BarMembership $membership) => [ 'bar_id' => $membership->bar_id, 'role_id' => $membership->role->id ?? null, 'role_name' => $membership->role->name ?? null, diff --git a/app/Metrics/MetricsServiceProvider.php b/app/Metrics/MetricsServiceProvider.php index aefda931..b1511549 100644 --- a/app/Metrics/MetricsServiceProvider.php +++ b/app/Metrics/MetricsServiceProvider.php @@ -27,7 +27,7 @@ public function register(): void return; } - $this->app->scoped(CollectorRegistry::class, fn() => new CollectorRegistry(Redis::fromExistingConnection(LaravelRedis::connection()->client()))); + $this->app->scoped(CollectorRegistry::class, fn () => new CollectorRegistry(Redis::fromExistingConnection(LaravelRedis::connection()->client()))); } public function boot(): void diff --git a/app/Metrics/TotalBars.php b/app/Metrics/TotalBars.php index 038ab2db..306b9b04 100644 --- a/app/Metrics/TotalBars.php +++ b/app/Metrics/TotalBars.php @@ -12,7 +12,7 @@ class TotalBars extends BaseMetrics { public function __invoke(): void { - $counts = Cache::remember('metrics_bass_total_bars', 60 * 24, fn() => DB::table('bars')->select( + $counts = Cache::remember('metrics_bass_total_bars', 60 * 24, fn () => DB::table('bars')->select( DB::raw("(CASE WHEN status IS NULL THEN 'active' ELSE status END) AS bar_status"), DB::raw('COUNT(*) AS total') )->groupBy('bar_status')->get()->keyBy('bar_status')); diff --git a/app/Models/Cocktail.php b/app/Models/Cocktail.php index 65d0cbad..9a194b7b 100644 --- a/app/Models/Cocktail.php +++ b/app/Models/Cocktail.php @@ -194,7 +194,7 @@ public function getABV(): ?float public function getVolume(): float { - $ingredients = $this->ingredients->map(fn($i) => $i->getAmount())->toArray(); + $ingredients = $this->ingredients->map(fn ($i) => $i->getAmount())->toArray(); return Utils::calculateVolume($ingredients); } @@ -340,7 +340,7 @@ public function getUserShelfMatchPercentage(User $user): float { $currentShelf = $user->getShelfIngredients($this->bar_id); $totalIngredients = $this->ingredients->count(); - $matchIngredients = $this->ingredients->filter(fn(CocktailIngredient $ci) => $currentShelf->contains('ingredient_id', $ci->ingredient_id))->count(); + $matchIngredients = $this->ingredients->filter(fn (CocktailIngredient $ci) => $currentShelf->contains('ingredient_id', $ci->ingredient_id))->count(); return ($matchIngredients / $totalIngredients) * 100; } @@ -349,7 +349,7 @@ public function getBarShelfMatchPercentage(): float { $currentShelf = $this->bar->shelfIngredients; $totalIngredients = $this->ingredients->count(); - $matchIngredients = $this->ingredients->filter(fn(CocktailIngredient $ci) => $currentShelf->contains('ingredient_id', $ci->ingredient_id))->count(); + $matchIngredients = $this->ingredients->filter(fn (CocktailIngredient $ci) => $currentShelf->contains('ingredient_id', $ci->ingredient_id))->count(); return ($matchIngredients / $totalIngredients) * 100; } @@ -404,7 +404,7 @@ public function asJsonLDSchema(): array "recipeCategory" => "Drink", "recipeCuisine" => "Cocktail", "keywords" => $this->tags->pluck('name')->implode(', '), - "recipeIngredient" => $this->ingredients->map(fn(CocktailIngredient $ci) => $ci->amount . ' ' . $ci->units . ' ' . $ci->ingredient->name), + "recipeIngredient" => $this->ingredients->map(fn (CocktailIngredient $ci) => $ci->amount . ' ' . $ci->units . ' ' . $ci->ingredient->name), ]; } diff --git a/app/Models/Relations/HasManyAncestors.php b/app/Models/Relations/HasManyAncestors.php index 532494df..3a82ac72 100644 --- a/app/Models/Relations/HasManyAncestors.php +++ b/app/Models/Relations/HasManyAncestors.php @@ -40,7 +40,7 @@ public function addEagerConstraints(array $models) public function match(array $models, EloquentCollection $results, $relation) { foreach ($models as $model) { - $ancestors = $results->filter(fn($possibleAncestor) => $possibleAncestor['_leaf_id'] === $model->id)->sort(function ($a, $b) use ($model) { + $ancestors = $results->filter(fn ($possibleAncestor) => $possibleAncestor['_leaf_id'] === $model->id)->sort(function ($a, $b) use ($model) { // Sort by position in materialized path $path = $model->getMaterializedPath()->toArray(); $posA = (int) array_search($a['id'], $path); diff --git a/app/Models/Relations/HasManyDescendants.php b/app/Models/Relations/HasManyDescendants.php index da5edf9d..ee76aed9 100644 --- a/app/Models/Relations/HasManyDescendants.php +++ b/app/Models/Relations/HasManyDescendants.php @@ -44,7 +44,7 @@ public function addEagerConstraints(array $rootIngredients) public function match(array $rootIngredients, EloquentCollection $descendants, $relation) { foreach ($rootIngredients as $rootIngredient) { - $relationDescendants = $descendants->filter(fn($possibleDescendant) => $possibleDescendant['_root_id'] === $rootIngredient->id)->sort(function ($a, $b) use ($rootIngredient) { + $relationDescendants = $descendants->filter(fn ($possibleDescendant) => $possibleDescendant['_root_id'] === $rootIngredient->id)->sort(function ($a, $b) use ($rootIngredient) { // Sort by position in materialized path $path = $rootIngredient->getMaterializedPath()->toArray(); $posA = (int) array_search($a['id'], $path); diff --git a/app/Providers/HorizonServiceProvider.php b/app/Providers/HorizonServiceProvider.php index 13146958..ede5acee 100644 --- a/app/Providers/HorizonServiceProvider.php +++ b/app/Providers/HorizonServiceProvider.php @@ -27,7 +27,7 @@ public function boot(): void */ protected function gate(): void { - Gate::define('viewHorizon', fn($user) => in_array($user->email, [ + Gate::define('viewHorizon', fn ($user) => in_array($user->email, [ // ])); } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index c410897e..f7e82798 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -48,14 +48,14 @@ public function boot() */ protected function configureRateLimiting() { - RateLimiter::for('api', fn(Request $request) => Limit::perMinute(1000)->by($request->user()?->id ?: $request->ip())); + RateLimiter::for('api', fn (Request $request) => Limit::perMinute(1000)->by($request->user()?->id ?: $request->ip())); - RateLimiter::for('importing', fn(Request $request) => $request->user()->hasActiveSubscription() + RateLimiter::for('importing', fn (Request $request) => $request->user()->hasActiveSubscription() ? Limit::none() : Limit::perMinute(2)->by($request->user()->id)); - RateLimiter::for('exports', fn(Request $request) => App::environment('production') ? Limit::perMinute(1)->by($request->user()?->id ?: $request->ip()) : Limit::none()); + RateLimiter::for('exports', fn (Request $request) => App::environment('production') ? Limit::perMinute(1)->by($request->user()?->id ?: $request->ip()) : Limit::none()); - RateLimiter::for('bar-optimization', fn(Request $request) => App::environment('production') ? Limit::perMinute(1, 10)->by($request->user()?->id ?: $request->ip()) : Limit::none()); + RateLimiter::for('bar-optimization', fn (Request $request) => App::environment('production') ? Limit::perMinute(1, 10)->by($request->user()?->id ?: $request->ip()) : Limit::none()); } } diff --git a/app/Scraper/AbstractSite.php b/app/Scraper/AbstractSite.php index 9fd31591..600e725e 100644 --- a/app/Scraper/AbstractSite.php +++ b/app/Scraper/AbstractSite.php @@ -137,7 +137,7 @@ public function method(): ?string public function toArray(): array { $ingredients = $this->ingredients(); - $ingredients = array_map(fn(RecipeIngredient $recipeIngredient, int $sort) => [ + $ingredients = array_map(fn (RecipeIngredient $recipeIngredient, int $sort) => [ '_id' => Ulid::generate(), 'name' => $this->clean(ucfirst($recipeIngredient->name)), 'amount' => $recipeIngredient->amount->getValue(), @@ -149,7 +149,7 @@ public function toArray(): array 'sort' => $sort + 1, ], $ingredients, array_keys($ingredients)); - $meta = array_map(fn(array $org) => [ + $meta = array_map(fn (array $org) => [ '_id' => $org['_id'], 'source' => $org['source'], ], $ingredients); diff --git a/app/Scraper/Sites/CocktailParty.php b/app/Scraper/Sites/CocktailParty.php index 794425a8..fa44c461 100644 --- a/app/Scraper/Sites/CocktailParty.php +++ b/app/Scraper/Sites/CocktailParty.php @@ -39,7 +39,7 @@ public function instructions(): ?string public function tags(): array { - return $this->findDescriptionContainer()->filter('.elementor-widget-post-info a')->each(fn($node): string => $node->text()); + return $this->findDescriptionContainer()->filter('.elementor-widget-post-info a')->each(fn ($node): string => $node->text()); } public function ingredients(): array @@ -89,7 +89,7 @@ protected function cleanDescription(?string $description): ?string private function joinParagraphs(Crawler $nodes): string { - $paragraphs = $nodes->each(fn($node): string => $this->clean($node->text())); + $paragraphs = $nodes->each(fn ($node): string => $this->clean($node->text())); return implode("\n\n", $paragraphs); } diff --git a/app/Services/Feeds/RecipeFeedsService.php b/app/Services/Feeds/RecipeFeedsService.php index c910a613..33d0a80b 100644 --- a/app/Services/Feeds/RecipeFeedsService.php +++ b/app/Services/Feeds/RecipeFeedsService.php @@ -56,7 +56,7 @@ public function fetch(): array } // Sort the recipes by date - usort($recipes, fn(FeedsRecipe $a, FeedsRecipe $b) => $b->dateModified <=> $a->dateModified); + usort($recipes, fn (FeedsRecipe $a, FeedsRecipe $b) => $b->dateModified <=> $a->dateModified); return $recipes; } diff --git a/app/Utils.php b/app/Utils.php index e2057e22..200fe1b1 100644 --- a/app/Utils.php +++ b/app/Utils.php @@ -23,7 +23,7 @@ public static function calculateAbv(array $ingredients, int $dilutionPercentage) $dilutionPercentage = $dilutionPercentage / 100; $amountUsed = array_sum(array_column($ingredients, 'amount')); - $alcoholVolume = floatval(array_reduce($ingredients, fn($carry, $item) => (($item['amount'] * $item['strength']) / 100) + $carry)); + $alcoholVolume = floatval(array_reduce($ingredients, fn ($carry, $item) => (($item['amount'] * $item['strength']) / 100) + $carry)); $afterDilution = ($amountUsed * $dilutionPercentage) + $amountUsed; diff --git a/routes/api.php b/routes/api.php index a09a742e..4835da47 100644 --- a/routes/api.php +++ b/routes/api.php @@ -297,7 +297,7 @@ }); }); -Route::fallback(fn() => response()->json([ +Route::fallback(fn () => response()->json([ 'type' => 'api_error', 'message' => 'Endpoint not found.' ], 404)); diff --git a/routes/web.php b/routes/web.php index c6955158..405af360 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,9 +15,9 @@ | */ -Route::get('/', fn() => 'This is your Bar Assistant instance. Checkout /docs to see documentation.
If you are trying to make a request to the API, make sure you are using the correct endpoint (e.g., /api/cocktails).
Also make sure you are using all the required headers: Accept, Authorization.'); +Route::get('/', fn () => 'This is your Bar Assistant instance. Checkout /docs to see documentation.
If you are trying to make a request to the API, make sure you are using the correct endpoint (e.g., /api/cocktails).
Also make sure you are using all the required headers: Accept, Authorization.'); -Route::get('/docs', fn() => view('elements')); +Route::get('/docs', fn () => view('elements')); if (config('bar-assistant.metrics.enabled') === true) { Route::get('/metrics', [MetricsController::class, 'index'])->name('metrics')->middleware(CheckMetricsAccess::class); diff --git a/tests/Feature/Http/AuthControllerTest.php b/tests/Feature/Http/AuthControllerTest.php index f225ec2a..e52d17ea 100644 --- a/tests/Feature/Http/AuthControllerTest.php +++ b/tests/Feature/Http/AuthControllerTest.php @@ -89,7 +89,7 @@ public function test_register_response_sends_confirm_email(): void 'name' => 'Test Guy', ]); - Mail::assertQueued(ConfirmAccount::class, fn(ConfirmAccount $mail) => $mail->hasTo('test@test.com')); + Mail::assertQueued(ConfirmAccount::class, fn (ConfirmAccount $mail) => $mail->hasTo('test@test.com')); } public function test_forgot_password_response(): void @@ -104,7 +104,7 @@ public function test_forgot_password_response(): void 'email' => 'test@test.com' ]); - Mail::assertQueued(PasswordReset::class, fn(PasswordReset $mail) => $mail->hasTo('test@test.com')); + Mail::assertQueued(PasswordReset::class, fn (PasswordReset $mail) => $mail->hasTo('test@test.com')); $response->assertSuccessful(); } diff --git a/tests/Feature/Http/ShoppingListControllerTest.php b/tests/Feature/Http/ShoppingListControllerTest.php index d627103d..9acd6000 100644 --- a/tests/Feature/Http/ShoppingListControllerTest.php +++ b/tests/Feature/Http/ShoppingListControllerTest.php @@ -43,7 +43,7 @@ public function test_add_multiple_ingredients_to_shopping_list_response(): void $ingredients = Ingredient::factory()->recycle($membership->bar)->count(3)->create(); $response = $this->postJson('/api/users/'. $membership->user_id .'/shopping-list/batch-store', [ - 'ingredients' => $ingredients->map(fn($ing) => ['id' => $ing->id])->toArray() + 'ingredients' => $ingredients->map(fn ($ing) => ['id' => $ing->id])->toArray() ], ['Bar-Assistant-Bar-Id' => $membership->bar_id]); $response->assertNoContent(); @@ -57,7 +57,7 @@ public function test_add_multiple_ingredients_to_shopping_list_from_another_bar_ $unOwnedIngredients = Ingredient::factory()->count(3)->create(); $response = $this->postJson('/api/users/'. $membership->user_id .'/shopping-list/batch-store', [ - 'ingredients' => $unOwnedIngredients->map(fn($ing) => ['id' => $ing->id])->toArray() + 'ingredients' => $unOwnedIngredients->map(fn ($ing) => ['id' => $ing->id])->toArray() ], ['Bar-Assistant-Bar-Id' => $membership->bar_id]); $response->assertNoContent(); @@ -77,7 +77,7 @@ public function test_delete_multiple_ingredients_from_shopping_list_response(): $this->assertDatabaseCount('user_shopping_lists', 5); $response = $this->postJson('/api/users/'. $membership->user_id .'/shopping-list/batch-delete', [ - 'ingredients' => $ingredients->pluck('ingredient')->map(fn($ing) => ['id' => $ing->id])->toArray() + 'ingredients' => $ingredients->pluck('ingredient')->map(fn ($ing) => ['id' => $ing->id])->toArray() ], ['Bar-Assistant-Bar-Id' => $membership->bar_id]); $response->assertNoContent(); From d2ab70463e47f22a4da6bc9e2e14f6325a2f50fa Mon Sep 17 00:00:00 2001 From: Karlo Mikus Date: Sun, 2 Nov 2025 17:11:16 +0100 Subject: [PATCH 4/4] csfix --- app/Providers/AppServiceProvider.php | 2 +- rector.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index bddfc563..c25e7e71 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -68,7 +68,7 @@ public function boot() PRAGMA mmap_size = 2147483648; '); } catch (Throwable) { - Log::warning('Unable to connect to DB setup PRAGMAs'); + Log::warning('Unable to set SQLite performance pragmas'); } } } diff --git a/rector.php b/rector.php index 514eb50c..90a7926f 100644 --- a/rector.php +++ b/rector.php @@ -3,7 +3,6 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use RectorLaravel\Set\LaravelSetProvider; return RectorConfig::configure() ->withPaths([