Skip to content

Commit 4a4f5d7

Browse files
committed
Rector changes
1 parent 00b4d73 commit 4a4f5d7

File tree

77 files changed

+364
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+364
-375
lines changed

app/BarContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* Combined with bar() helper method you can always get the current requested Bar model.
1212
* @see \Kami\Cocktail\Http\Middleware\EnsureRequestHasBarQuery
1313
*/
14-
final class BarContext
14+
final readonly class BarContext
1515
{
16-
public function __construct(private readonly Bar $currentBar)
16+
public function __construct(private Bar $currentBar)
1717
{
1818
}
1919

app/Console/Commands/BarFullBackup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class BarFullBackup extends Command
2323
*/
2424
protected $description = 'Create a .zip file with the full backup of your Bar Assistant instance data';
2525

26-
public function __construct(private ToFullBackup $exporter)
26+
public function __construct(private readonly ToFullBackup $exporter)
2727
{
2828
parent::__construct();
2929
}

app/Console/Commands/BarMaintenance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BarMaintenance extends Command
2929
*/
3030
protected $description = 'This will remove unused images, update missing ABVs, fix ingredient sort and refresh cache';
3131

32-
private Filesystem $disk;
32+
private readonly Filesystem $disk;
3333

3434
public function __construct()
3535
{

app/Exceptions/Handler.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,14 @@ public function register()
6060
}
6161
});
6262

63-
$this->renderable(function (NotFoundHttpException $e, $request) {
64-
return response()->json([
65-
'type' => 'api_error',
66-
'message' => 'Resource not found.',
67-
], 404);
68-
});
63+
$this->renderable(fn(NotFoundHttpException $e, $request) => response()->json([
64+
'type' => 'api_error',
65+
'message' => 'Resource not found.',
66+
], 404));
6967

70-
$this->renderable(function (MethodNotAllowedHttpException $e, $request) {
71-
return response()->json([
72-
'type' => 'api_error',
73-
'message' => $e->getMessage(),
74-
], 405);
75-
});
68+
$this->renderable(fn(MethodNotAllowedHttpException $e, $request) => response()->json([
69+
'type' => 'api_error',
70+
'message' => $e->getMessage(),
71+
], 405));
7672
}
7773
}

app/External/Export/ToDataPack.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function process(int $barId, ?string $filename = null, ForceUnitConvertEn
4848
$meta = [
4949
'version' => $version,
5050
'date' => Carbon::now()->toAtomString(),
51-
'called_from' => __CLASS__,
51+
'called_from' => self::class,
5252
];
5353

5454
File::ensureDirectoryExists($this->file->disk('exports')->path((string) $barId));

app/External/Export/ToFullBackup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function process(?string $exportPath = null): string
2323
$meta = [
2424
'version' => $version,
2525
'date' => Carbon::now()->toAtomString(),
26-
'called_from' => __CLASS__,
26+
'called_from' => self::class,
2727
];
2828

2929
$zip = new ZipArchive();

app/External/Export/ToRecipeType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function process(int $barId, ?string $filename = null, ExportTypeEnum $ty
3838
$meta = [
3939
'version' => $version,
4040
'date' => Carbon::now()->toAtomString(),
41-
'called_from' => __CLASS__,
41+
'called_from' => self::class,
4242
'type' => $type->value,
4343
'bar_id' => $barId,
4444
'schema' => $type === ExportTypeEnum::Schema ? 'https://barassistant.app/cocktail-02.schema.json' : null,

app/External/Import/FromDataPack.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
class FromDataPack
2727
{
28-
private Filesystem $uploadsDisk;
28+
private readonly Filesystem $uploadsDisk;
2929

3030
/** @var array<string> */
3131
private array $barShelf = [];
@@ -107,9 +107,9 @@ private function importBaseData(string $tableName, string $filepath, int $barId)
107107
}, $data);
108108

109109
// Skip duplicates
110-
$existing = DB::table($tableName)->select('name')->where('bar_id', $barId)->get()->keyBy(fn ($row) => strtolower($row->name))->toArray();
110+
$existing = DB::table($tableName)->select('name')->where('bar_id', $barId)->get()->keyBy(fn ($row) => strtolower((string) $row->name))->toArray();
111111
$importData = array_filter($importData, function ($item) use ($existing) {
112-
if (array_key_exists(strtolower($item['name']), $existing)) {
112+
if (array_key_exists(strtolower((string) $item['name']), $existing)) {
113113
return false;
114114
}
115115

@@ -127,9 +127,9 @@ private function importCalculators(string $filepath, int $barId): void
127127
$data = [];
128128
}
129129

130-
$existing = DB::table('calculators')->select('name')->where('bar_id', $barId)->get()->keyBy(fn ($row) => strtolower($row->name))->toArray();
130+
$existing = DB::table('calculators')->select('name')->where('bar_id', $barId)->get()->keyBy(fn ($row) => strtolower((string) $row->name))->toArray();
131131
$data = array_filter($data, function ($item) use ($existing) {
132-
if (array_key_exists(strtolower($item['name']), $existing)) {
132+
if (array_key_exists(strtolower((string) $item['name']), $existing)) {
133133
return false;
134134
}
135135

@@ -175,9 +175,7 @@ private function importIngredients(Filesystem $dataDisk, Bar $bar, User $user):
175175
{
176176
$timerStart = microtime(true);
177177

178-
$existingIngredients = DB::table('ingredients')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(function ($ingredient) {
179-
return Str::slug($ingredient->name);
180-
});
178+
$existingIngredients = DB::table('ingredients')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(fn($ingredient) => Str::slug($ingredient->name));
181179

182180
$ingredientsToInsert = [];
183181
$parentIngredientsToInsert = [];
@@ -322,9 +320,7 @@ private function importBaseCocktails(Filesystem $dataDisk, Bar $bar, User $user)
322320
$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();
323321
$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();
324322
$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();
325-
$existingCocktails = DB::table('cocktails')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(function ($cocktail) {
326-
return Str::slug($cocktail->name);
327-
});
323+
$existingCocktails = DB::table('cocktails')->select('id', 'name')->where('bar_id', $bar->id)->get()->keyBy(fn($cocktail) => Str::slug($cocktail->name));
328324

329325
$cocktailImages = [];
330326
$uniqueTags = [];

app/External/Import/FromJsonSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class FromJsonSchema
2222
{
23-
private Matcher $matcher;
23+
private readonly Matcher $matcher;
2424

2525
public function __construct(
2626
private readonly CocktailService $cocktailService,

app/External/Matcher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function matchCocktailByName(string $name): ?int
3535
}
3636

3737
$this->matchedCocktails = DB::table('cocktails')->select('id', 'name')->where('bar_id', $this->barId)->get()->map(function ($row) {
38-
$row->name = mb_strtolower($row->name, 'UTF-8');
38+
$row->name = mb_strtolower((string) $row->name, 'UTF-8');
3939

4040
return $row;
4141
})->pluck('id', 'name')->toArray();
@@ -59,7 +59,7 @@ public function matchOrCreateIngredientByName(IngredientDTO $ingredient): int
5959
}
6060

6161
$this->matchedIngredients = DB::table('ingredients')->select('id', 'name')->where('bar_id', $this->barId)->get()->map(function ($row) {
62-
$row->name = mb_strtolower($row->name, 'UTF-8');
62+
$row->name = mb_strtolower((string) $row->name, 'UTF-8');
6363

6464
return $row;
6565
})->pluck('id', 'name')->toArray();
@@ -87,7 +87,7 @@ public function matchGlassByName(string $name): ?int
8787
}
8888

8989
$this->matchedGlasses = DB::table('glasses')->select('id', 'name')->where('bar_id', $this->barId)->get()->map(function ($row) {
90-
$row->name = mb_strtolower($row->name, 'UTF-8');
90+
$row->name = mb_strtolower((string) $row->name, 'UTF-8');
9191

9292
return $row;
9393
})->pluck('id', 'name')->toArray();
@@ -111,7 +111,7 @@ public function matchMethodByName(string $name): ?int
111111
}
112112

113113
$this->matchedMethods = DB::table('cocktail_methods')->select('id', 'name')->where('bar_id', $this->barId)->get()->map(function ($row) {
114-
$row->name = mb_strtolower($row->name, 'UTF-8');
114+
$row->name = mb_strtolower((string) $row->name, 'UTF-8');
115115

116116
return $row;
117117
})->pluck('id', 'name')->toArray();

0 commit comments

Comments
 (0)