Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/BarContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/BarFullBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/BarMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
20 changes: 8 additions & 12 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion app/External/Export/ToDataPack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion app/External/Export/ToFullBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/External/Export/ToRecipeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 7 additions & 11 deletions app/External/Import/FromDataPack.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class FromDataPack
{
private Filesystem $uploadsDisk;
private readonly Filesystem $uploadsDisk;

/** @var array<string> */
private array $barShelf = [];
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion app/External/Import/FromJsonSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class FromJsonSchema
{
private Matcher $matcher;
private readonly Matcher $matcher;

public function __construct(
private readonly CocktailService $cocktailService,
Expand Down
8 changes: 4 additions & 4 deletions app/External/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
20 changes: 9 additions & 11 deletions app/External/Model/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
12 changes: 3 additions & 9 deletions app/External/Model/Cocktail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 1 addition & 3 deletions app/External/Model/CocktailIngredient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
12 changes: 3 additions & 9 deletions app/External/Model/Ingredient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/CocktailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public function copy(string $idOrSlug, CocktailService $cocktailService, ImageSe
copyright: $image->copyright,
sort: $image->sort,
);
} catch (Throwable $e) {
} catch (Throwable) {
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions app/Http/Controllers/IngredientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
]);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Public/BarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Public/CocktailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Middleware/CheckMetricsAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions app/Http/Middleware/EnsureRequestHasBarQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading