Skip to content

Commit 1aa31c1

Browse files
committed
rector
1 parent e274ca9 commit 1aa31c1

27 files changed

+73
-59
lines changed

app/Console/Commands/LegacyMigrateEncryption.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use forms\projekte\auslagen\AuslagenHandler2;
1010
use Illuminate\Console\Command;
1111
use Illuminate\Contracts\Encryption\DecryptException;
12+
use Illuminate\Support\Env;
1213
use Illuminate\Support\Facades\DB;
1314

1415
class LegacyMigrateEncryption extends Command
@@ -32,7 +33,7 @@ class LegacyMigrateEncryption extends Command
3233
*/
3334
public function handle(): int
3435
{
35-
if (! isset($_ENV['CHAT_PRIVATE_KEY'], $_ENV['CHAT_PUBLIC_KEY'], $_ENV['IBAN_SECRET_KEY'])) {
36+
if (!Env::get('CHAT_PRIVATE_KEY') !== null && Env::get('CHAT_PUBLIC_KEY') !== null && Env::get('IBAN_SECRET_KEY') !== null) {
3637
$this->error('Please set chat private key and public key / IBAN_SECRET_KEY');
3738

3839
return self::FAILURE;
@@ -49,13 +50,13 @@ public function handle(): int
4950
if (str_starts_with($message->text, '$enc$')) {
5051
// old prefix
5152
$text = substr($text, strlen('$enc$'));
52-
$text = ChatHandler::legacyDecryptMessage($text, $_ENV['CHAT_PRIVATE_KEY']);
53+
$text = ChatHandler::legacyDecryptMessage($text, Env::get('CHAT_PRIVATE_KEY'));
5354
$message->text = \Crypt::encryptString($text);
5455
$message->save();
5556
$count++;
5657
} elseif ($message->type === -1) {
5758
// not used productive anymore, was "private message"
58-
$text = ChatHandler::legacyDecryptMessage($text, $_ENV['CHAT_PRIVATE_KEY']);
59+
$text = ChatHandler::legacyDecryptMessage($text, Env::get('CHAT_PRIVATE_KEY'));
5960
$message->text = \Crypt::encryptString($text);
6061
$message->save();
6162
$count++;

app/Http/Controllers/BudgetPlanController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public function create(): RedirectResponse
5252
]);
5353
});
5454

55-
return redirect()->route('budget-plan.edit', ['plan_id' => $plan->id]);
55+
return to_route('budget-plan.edit', ['plan_id' => $plan->id]);
5656
}
5757
}

app/Http/Controllers/Legacy/DeleteExpenses.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public function __invoke(int $expense_id)
2020
$userPerm =
2121
AuthHandler::getInstance()->hasGroup('ref-finanzen-hv')
2222
|| $project->creator->id === \Auth::user()->id
23-
|| explode(';', $expense->created)[1] === \Auth::user()->username;
23+
|| explode(';', (string) $expense->created)[1] === \Auth::user()->username;
2424
// authorize state
25-
$deletableState = ! in_array(explode(';', $expense->state)[0], ['instructed', 'booked'], true);
25+
$deletableState = ! in_array(explode(';', (string) $expense->state)[0], ['instructed', 'booked'], true);
2626

2727
if ($userPerm === false || $deletableState === false) {
2828
abort(403);
@@ -53,6 +53,6 @@ public function __invoke(int $expense_id)
5353
});
5454
\DB::commit();
5555

56-
return redirect()->route('legacy.dashboard', ['sub' => 'mygremium']);
56+
return to_route('legacy.dashboard', ['sub' => 'mygremium']);
5757
}
5858
}

app/Http/Controllers/Legacy/DeleteProject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public function __invoke(int $project_id)
2525
$project->posts()->delete();
2626
$project->delete();
2727

28-
return redirect()->route('legacy.dashboard', ['sub' => 'mygremium']);
28+
return to_route('legacy.dashboard', ['sub' => 'mygremium']);
2929
}
3030
}

app/Http/Controllers/Legacy/ExportController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Http\Controllers\Controller;
77
use App\Models\Legacy\LegacyBudgetPlan;
88
use Carbon\Carbon;
9+
use Illuminate\Support\Facades\Date;
910
use Maatwebsite\Excel\Excel;
1011

1112
class ExportController extends Controller
@@ -18,10 +19,10 @@ public function budgetPlan(int $id, string $filetype)
1819
};
1920
$plan = LegacyBudgetPlan::findOrFail($id);
2021
$today = today()->format('Y-m-d');
21-
$start = Carbon::make($plan->von)?->format('y-m');
22-
$end = Carbon::make($plan->bis)?->format('y-m');
22+
$start = Date::make($plan->von)?->format('y-m');
23+
$end = Date::make($plan->bis)?->format('y-m');
2324
$fileName = "$today HHP $start".($end ? " bis $end" : '').".$filetype";
2425

25-
return (new LegacyBudgetExport($plan))->download($fileName, $writerType);
26+
return new LegacyBudgetExport($plan)->download($fileName, $writerType);
2627
}
2728
}

app/Livewire/ChatPanel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function save()
3535

3636
$this->validate(['content' => 'required|min:1']);
3737

38-
$cleanContent = strip_tags($this->content, '<p><br><strong><em><ul><ol><li><a><h1><h2><h3>');
38+
$cleanContent = strip_tags((string) $this->content, '<p><br><strong><em><ul><ol><li><a><h1><h2><h3>');
3939

4040
ChatMessage::create([
4141
'text' => $cleanContent,

app/Livewire/Project/EditProject.php

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,14 @@ public function mount(): void
5555
Gate::authorize('update', $project);
5656
$this->form->setProject($project);
5757
$this->state_name = $project->state->getValue();
58-
$this->posts = $project->posts->map(function (ProjectPost $post) {
59-
return [
60-
'id' => $post->id,
61-
'name' => $post->name,
62-
'bemerkung' => $post->bemerkung ?? '',
63-
'einnahmen' => $post->einnahmen,
64-
'ausgaben' => $post->ausgaben,
65-
'titel_id' => $post->titel_id,
66-
];
67-
});
58+
$this->posts = $project->posts->map(fn(ProjectPost $post) => [
59+
'id' => $post->id,
60+
'name' => $post->name,
61+
'bemerkung' => $post->bemerkung ?? '',
62+
'einnahmen' => $post->einnahmen,
63+
'ausgaben' => $post->ausgaben,
64+
'titel_id' => $post->titel_id,
65+
]);
6866
$this->attachments = []; // FIXME: load Attachments
6967
}
7068
}
@@ -124,7 +122,7 @@ public function save()
124122
}
125123
DB::commit();
126124

127-
return redirect()->route('project.show', $project->id);
125+
return to_route('project.show', $project->id);
128126
} catch (\Exception $e) {
129127
DB::rollBack();
130128
$this->addError('save', 'Fehler beim Speichern: '.$e->getMessage());
@@ -176,19 +174,15 @@ public function addEmptyPost(): void
176174
*/
177175
public function getTotalIncome(): Money
178176
{
179-
return $this->posts->reduce(function (?Money $carry, array $post) {
180-
return $carry ? $carry->add($post['einnahmen']) : $post['einnahmen'];
181-
}, Money::EUR(0));
177+
return $this->posts->reduce(fn(?Money $carry, array $post) => $carry ? $carry->add($post['einnahmen']) : $post['einnahmen'], Money::EUR(0));
182178
}
183179

184180
/**
185181
* Get the sum of all expense posts
186182
*/
187183
public function getTotalExpenses(): Money
188184
{
189-
return $this->posts->reduce(function (?Money $carry, array $post) {
190-
return $carry ? $carry->add($post['ausgaben']) : $post['ausgaben'];
191-
}, Money::EUR(0));
185+
return $this->posts->reduce(fn(?Money $carry, array $post) => $carry ? $carry->add($post['ausgaben']) : $post['ausgaben'], Money::EUR(0));
192186
}
193187

194188
public function removeAttachment(int $index): void
@@ -216,16 +210,14 @@ protected function getRechtsgrundlagenOptions(): array
216210
{
217211
$rechtsgrundlagen = config('stufis.project_legal', []);
218212

219-
return collect($rechtsgrundlagen)->map(function ($def, $key) {
220-
return [
221-
'key' => $key,
222-
'label' => $def['label'] ?? $key,
223-
'placeholder' => $def['placeholder'] ?? '',
224-
'label_additional' => $def['label-additional'] ?? 'Zusatzinformationen',
225-
'hint' => $def['hint-text'] ?? '',
226-
'has_additional' => isset($def['placeholder'], $def['label-additional']),
227-
];
228-
})->toArray();
213+
return collect($rechtsgrundlagen)->map(fn($def, $key) => [
214+
'key' => $key,
215+
'label' => $def['label'] ?? $key,
216+
'placeholder' => $def['placeholder'] ?? '',
217+
'label_additional' => $def['label-additional'] ?? 'Zusatzinformationen',
218+
'hint' => $def['hint-text'] ?? '',
219+
'has_additional' => isset($def['placeholder'], $def['label-additional']),
220+
])->all();
229221
}
230222

231223
/**

app/Livewire/Project/ProjectForm.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Models\Legacy\LegacyBudgetPlan;
66
use App\Models\Legacy\Project;
77
use Carbon\Carbon;
8+
use Illuminate\Support\Facades\Date;
89
use Livewire\Form;
910

1011
class ProjectForm extends Form
@@ -93,7 +94,7 @@ public function getValues(): array
9394
'date_start' => $this->dateRange['start'] ?? null,
9495
'date_end' => $this->dateRange['end'] ?? null,
9596
'version' => $this->version,
96-
'createdat' => Carbon::parse(LegacyBudgetPlan::find($this->hhp_id)->von),
97+
'createdat' => Date::parse(LegacyBudgetPlan::find($this->hhp_id)->von),
9798
];
9899
}
99100
}

app/Livewire/TransactionImportWire.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ private function parseCSV(): void
132132
$this->separator = $amountSemicolon > $amountComma ? ';' : ',';
133133

134134
// extract header and data, explode data with csv separator guesses above
135-
$this->header = str_getcsv((string) $lines->first(), $this->separator);
135+
$this->header = str_getcsv((string) $lines->first(), $this->separator, escape: '\\');
136136
$this->data = $lines->except(0)
137137
->reject(fn ($line): bool => empty($line) || Regex::match('/^(,*|;*)\r?\n?$/', $line)->hasMatch())
138-
->map(fn ($line) => str_getcsv((string) $line, $this->separator))
138+
->map(fn ($line) => str_getcsv((string) $line, $this->separator, escape: '\\'))
139139
->map(function ($lineArray) {
140140
// normalize data
141141
foreach ($lineArray as $key => $cell) {
@@ -211,7 +211,7 @@ public function save()
211211
$transaction->$db_col_name = $this->formatDataDb($row[$this->mapping[$db_col_name]], $db_col_name);
212212
} elseif ($db_col_name === 'saldo') {
213213
$currentValue = str($row[$this->mapping['value']])->replace(',', '.');
214-
$currentBalance = bcadd($currentBalance, (string) $currentValue, 2);
214+
$currentBalance = bcadd((string) $currentBalance, (string) $currentValue, 2);
215215
$transaction->$db_col_name = $this->formatDataDb($currentBalance, $db_col_name);
216216
}
217217
}
@@ -243,7 +243,7 @@ public function save()
243243

244244
// $this->redirectRoute('legacy.konto', ['account_id' => $this->account_id]);
245245
// return redirect()->route('konto.import.manual', ['account_id' => $this->account_id])
246-
return redirect()->route('legacy.konto', ['konto' => $this->account_id])
246+
return to_route('legacy.konto', ['konto' => $this->account_id])
247247
->with(['message' => __('konto.csv-import-success-msg', ['new-saldo' => $newBalance, 'transaction-amount' => $this->data->count()])]);
248248
}
249249

app/Models/Legacy/BankAccount.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function casts(): array
7070
];
7171
}
7272

73-
public function csvImportSettings(): Attribute
73+
protected function csvImportSettings(): Attribute
7474
{
7575
return Attribute::make(
7676
get: static function (?string $value) {

0 commit comments

Comments
 (0)