Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php rector and tech dept updates #254

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.4'
extensions: bcmath, ctype, fileinfo, json, mbstring, openssl, pdo, tokenizer, xml, zip, gd
coverage: none
- name: Get composer cache directory
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.4'
tools: phplint, laravel/pint
- name: Check syntax
run: phplint .
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
operating-system:
- ubuntu-latest
php-version:
- '8.2'
- '8.4'
name: php ${{ matrix.php-version }} on ${{ matrix.operating-system }}
services:
mariadb:
Expand All @@ -30,7 +30,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: bcmath, ctype, fileinfo, json, mbstring, openssl, pdo, tokenizer, xml, zip, gd
coverage: none
coverage: xdebug
- name: Prepare the environment
run: cp .env.ci .env
- name: Get composer cache directory
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/LegacyBudgetGroupShiftCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LegacyBudgetGroupShiftCommand extends Command

public function handle(): void
{
\DB::transaction(function () {
\DB::transaction(function (): void {
$latestPlan = LegacyBudgetPlan::orderBy('id', 'desc')->limit(1)->sole();
$budgetGroups = LegacyBudgetGroup::where('hhp_id', $latestPlan->id)
->where('id', '>=', $this->argument('new_group_id'));
Expand Down
8 changes: 4 additions & 4 deletions app/Console/Commands/LegacyMigrateEncryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public function handle(): int

return self::FAILURE;
}
DB::transaction(function () {
DB::transaction(function (): void {

$messages = ChatMessage::all();
$count = 0;
$messages->each(function ($message) use (&$count) {
$messages->each(function ($message) use (&$count): void {
$text = $message->text;
if (! empty($text)) {
if (str_starts_with($message->text, '$enc$')) {
Expand All @@ -48,7 +48,7 @@ public function handle(): int
} elseif ($message->type == -1) {
try {
$text = ChatHandler::legacyDecryptMessage($text, config('app.chat.private_key'));
} catch (\Exception $exception) {
} catch (\Exception) {
}
}
}
Expand All @@ -59,7 +59,7 @@ public function handle(): int
$this->info("Migrated $count chat messages from legacy encryption to laravel integrated");

$count = 0;
Expenses::all()->each(function ($expense) use (&$count) {
Expenses::all()->each(function ($expense) use (&$count): void {
$cryptIban = $expense->getAttribute('zahlung-iban');
$iban = AuslagenHandler2::legacyDecryptStr($cryptIban ?? '');
$expense->setAttribute('zahlung-iban', \Crypt::encryptString($iban));
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/LegacyMigrateFilesToStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LegacyMigrateFilesToStorage extends Command
*/
public function handle(): void
{
FileInfo::lazy(20)->each(function (FileInfo $fileInfo) {
FileInfo::lazy(20)->each(function (FileInfo $fileInfo): void {
$data = $fileInfo->fileData;
$link = $fileInfo->link;
$beleg = ExpensesReceipt::find($link);
Expand Down
5 changes: 1 addition & 4 deletions app/Exceptions/LegacyDieException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

class LegacyDieException extends Exception
{
public string $debug;

public function __construct(int $code = 0, string $message = '', string $debug = '', ?Throwable $previous = null)
public function __construct(int $code = 0, string $message = '', public string $debug = '', ?Throwable $previous = null)
{
$this->debug = $debug;
parent::__construct($message, $code, $previous);
}
}
5 changes: 1 addition & 4 deletions app/Exceptions/LegacyJsonException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

class LegacyJsonException extends Exception
{
public mixed $content;

public function __construct(mixed $content)
public function __construct(public mixed $content)
{
$this->content = $content;
parent::__construct('', 200, null);
}
}
4 changes: 1 addition & 3 deletions app/Exports/LegacyBudgetExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public function columnFormats(): array
public function sum(string $column, array|Collection $rows)
{
$rows = collect($rows);
$fields = $rows->map(function ($row) use ($column) {
return "$column$row";
})->join(',');
$fields = $rows->map(fn ($row) => "$column$row")->join(',');

return '=SUM('.$fields.')';
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Legacy/DeleteExpenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __invoke(int $expense_id)
// to make sure to delete everything and not only parts
\DB::beginTransaction();
$reciepts = $expense->receipts;
$reciepts->each(function (ExpensesReceipt $receipt) {
$reciepts->each(function (ExpensesReceipt $receipt): void {
// delete all posts
$receipt->posts()->delete();
// delete all files db entries (storage later)
Expand All @@ -46,7 +46,7 @@ public function __invoke(int $expense_id)
$expense->delete();

// clean up storage if DB is successfully cleaned
DB::afterCommit(function () use ($expense_id) {
DB::afterCommit(function () use ($expense_id): void {
\Storage::deleteDirectory("auslagen/{$expense_id}/");
});
\DB::commit();
Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/LogModelChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function handle(UpdatingModel $modelChange): void
->map(fn ($item, $key) => $model->getOriginal($key));

Changelog::create([
'type' => get_class($model),
'type' => $model::class,
'type_id' => $model->getKey(),
'previous_data' => $changes,
'user_id' => \Auth::user()->id,
Expand Down
24 changes: 9 additions & 15 deletions app/Livewire/TransactionImportWire.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ private function createMapping(array $merger = []): Collection
$foo = new BankTransaction;
$emptyMapping = collect(array_flip(array_keys($foo->getLabels())));

return $emptyMapping->map(function ($value, $key) use ($merger) {
return $merger[$key] ?? '';
});
return $emptyMapping->map(fn ($value, $key) => $merger[$key] ?? '');
}

public function parseCSV(): void
Expand All @@ -122,7 +120,7 @@ public function parseCSV(): void
$content = $this->csv->get();

// check for windows excel file encoding, transform to utf-8
$enc = mb_detect_encoding($content, ['Windows-1252', 'UTF-8']);
$enc = mb_detect_encoding((string) $content, ['Windows-1252', 'UTF-8']);
if ($enc !== 'UTF-8') {
$content = mb_convert_encoding($content, 'UTF-8', 'Windows-1252');
}
Expand All @@ -136,13 +134,11 @@ public function parseCSV(): void
$this->separator = $amountSemicolon > $amountComma ? ';' : ',';

// extract header and data, explode data with csv separator guesses above
$this->header = str_getcsv($lines->first(), $this->separator);
$this->header = str_getcsv((string) $lines->first(), $this->separator);
$this->data = $lines->except(0)
->filter(function ($line) {
return ! (empty($line) || Regex::match('/^(,*|;*)\r?\n?$/', $line)->hasMatch());
})->map(function ($line) {
return str_getcsv($line, $this->separator);
})->map(function ($lineArray) {
->filter(fn ($line) => ! (empty($line) || Regex::match('/^(,*|;*)\r?\n?$/', $line)->hasMatch()))
->map(fn ($line) => str_getcsv((string) $line, $this->separator))
->map(function ($lineArray) {
// normalize data
foreach ($lineArray as $key => $cell) {
// tests
Expand Down Expand Up @@ -171,9 +167,7 @@ public function parseCSV(): void
}

// check if mapping has some presets, if then do an initial validation, no preset, no validation
$hasPreset = $this->mapping->reject(function ($value) {
return $value === '';
})->count() > 0;
$hasPreset = $this->mapping->reject(fn ($value) => $value === '')->count() > 0;
if ($hasPreset) {
$this->validate();
}
Expand Down Expand Up @@ -217,7 +211,7 @@ public function save()
$transaction->$db_col_name = $this->formatDataDb($row[$this->mapping[$db_col_name]], $db_col_name);
} elseif ($db_col_name === 'saldo') {
$currentValue = str($row[$this->mapping['value']])->replace(',', '.');
$currentBalance = bcadd($currentBalance, $currentValue, 2);
$currentBalance = bcadd($currentBalance, (string) $currentValue, 2);
$transaction->$db_col_name = $this->formatDataDb($currentBalance, $db_col_name);
}
}
Expand All @@ -226,7 +220,7 @@ public function save()
}
try {
DB::commit();
} catch (\Exception $exception) {
} catch (\Exception) {
DB::rollBack();
$this->addError('csv', 'Nope');

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Legacy/LegacyBudgetItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public function bookingSum(): float

public function bookingDiff(): float
{
return (float) bcsub($this->value, $this->bookings()->sum('value'));
return (float) bcsub($this->value, (string) $this->bookings()->sum('value'));
}
}
8 changes: 3 additions & 5 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function boot(): void
$this->loadMigrationsFrom(base_path('database/migrations/preview'));
}

Event::listen(function (SocialiteWasCalled $event) {
Event::listen(function (SocialiteWasCalled $event): void {
$event->extendSocialite('stumv', \SocialiteProviders\LaravelPassport\Provider::class);
});

Expand All @@ -57,16 +57,14 @@ public function boot(): void

public function bootRoute()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
RateLimiter::for('api', fn (Request $request) => Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()));

}

public function registerAuth(): void
{
$this->app->singleton(AuthService::class, function (Application $application) {
$serviceName = ucfirst(strtolower(config('auth.service')));
$serviceName = ucfirst(strtolower((string) config('auth.service')));
// weird to escape, but correct
$classPath = "\App\Services\Auth\\{$serviceName}AuthService";
if (class_exists($classPath)) {
Expand Down
14 changes: 5 additions & 9 deletions app/Rules/CsvTransactionImport/BalanceColumnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ class BalanceColumnRule implements ValidationRule
public function __construct(Collection $differences, Collection $balances, ?string $initalBalance)
{
// make sure all given Money strings have the same format: XXXX.XX (2 decimals, with . as separator)
$this->differences = $differences->map(function ($item) {
return number_format((float) str_replace(',', '.', $item ?? ''), 2, '.', '');
});
$this->balances = $balances->map(function ($item) {
return number_format((float) str_replace(',', '.', $item ?? ''), 2, '.', '');
});
$this->differences = $differences->map(fn ($item) => number_format((float) str_replace(',', '.', $item ?? ''), 2, '.', ''));
$this->balances = $balances->map(fn ($item) => number_format((float) str_replace(',', '.', $item ?? ''), 2, '.', ''));
$this->initalBalance = is_null($initalBalance) ? null : number_format((float) str_replace(',', '.', $initalBalance), 2, '.', '');
}

Expand All @@ -35,9 +31,9 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
// if there is no initial balance (no prior transaction) then make sure the first csv entry as correct
$currentBalance = $this->initalBalance ?? bcsub($this->balances[0], $this->differences[0], 2);
$currentBalance = $this->initalBalance ?? bcsub((string) $this->balances[0], (string) $this->differences[0], 2);
foreach ($this->differences as $id => $currentValue) {
$currentBalance = bcadd($currentBalance, $currentValue, 2);
$currentBalance = bcadd($currentBalance, (string) $currentValue, 2);
$csvBalance = $this->balances->get($id);
if ($currentBalance !== $csvBalance) {
$fail(__('konto.csv-verify-balance-error', [
Expand All @@ -47,7 +43,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
]));
}
}
} catch (\ValueError $error) {
} catch (\ValueError) {
// thrown by bcsub and bc add
$fail(__('konto.csv-verify-balance-error-wrong-datatype'));
}
Expand Down
2 changes: 1 addition & 1 deletion app/Rules/CsvTransactionImport/DateColumnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
$fail(__('konto.csv-verify-date-order-error'));
}
// dump("$attribute test if $firstDate >= $lastDate -> Result: ". !$firstDate->lessThanOrEqualTo($lastDate) );
} catch (InvalidFormatException $exception) {
} catch (InvalidFormatException) {
$fail(__('konto.csv-verify-date-error'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Rules/CsvTransactionImport/MoneyColumnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class MoneyColumnRule implements ValidationRule
{
public function __construct(private Collection $column) {}
public function __construct(private readonly Collection $column) {}

/**
* Run the validation rule.
Expand Down
8 changes: 2 additions & 6 deletions app/Services/Auth/StumvAuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,12 @@ public function userFromCallback(Request $request): array

public function userCommittees(): Collection
{
return \Session::remember('stumv.comittees', function () {
return $this->api()->get('/api/my/committees')->collect();
});
return \Session::remember('stumv.comittees', fn () => $this->api()->get('/api/my/committees')->collect());
}

public function userGroupsRaw(): Collection
{
return \Session::remember('stumv.groups', function () {
return $this->api()->get('/api/my/groups')->collect();
});
return \Session::remember('stumv.groups', fn () => $this->api()->get('/api/my/groups')->collect());
}

public function groupMapping(): Collection
Expand Down
2 changes: 1 addition & 1 deletion app/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function guessCarbon(string $dateString, ?string $newFormat = null): Carbon|stri
foreach ($formats as $format) {
try {
$ret = Carbon::rawCreateFromFormat($format, $dateString);
} catch (InvalidFormatException $e) {
} catch (InvalidFormatException) {
continue;
}
// if successfully parsed
Expand Down
11 changes: 4 additions & 7 deletions app/View/Components/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ class Layout extends Component

public string $version;

/**
* @var string if not empty, the legacy iframe will be shown with this content, instead of the slot
*/
public string $legacyContent = '';

public array $profileSkeleton = [
[
'text' => 'Mein Profil',
Expand All @@ -31,9 +26,11 @@ class Layout extends Component
*
* @return void
*/
public function __construct($legacyContent = '')
public function __construct(/**
* @var string if not empty, the legacy iframe will be shown with this content, instead of the slot
*/
public string $legacyContent = '')
{
$this->legacyContent = $legacyContent;
$this->version = config('app.version');
}

Expand Down
6 changes: 3 additions & 3 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
commands: __DIR__.'/../routes/console.php',
// channels: __DIR__.'/../routes/channels.php',
health: '/up',
then: function () {
then: function (): void {
Route::middleware('api')
->prefix('api')
->group(base_path('routes/api.php'));
Expand Down Expand Up @@ -45,7 +45,7 @@
->group(base_path('routes/legacy.php'));
}
)
->withMiddleware(function (Middleware $middleware) {
->withMiddleware(function (Middleware $middleware): void {
$middleware->redirectUsersTo(AppServiceProvider::HOME);

$middleware->throttleApi();
Expand All @@ -63,6 +63,6 @@
'auth' => \App\Http\Middleware\Authenticate::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
->withExceptions(function (Exceptions $exceptions): void {
//
})->create();
Loading
Loading