Clean up code.

This commit is contained in:
James Cole
2023-12-10 06:45:59 +01:00
parent 9a807fc215
commit c2b22a2bac
157 changed files with 648 additions and 669 deletions

View File

@@ -59,9 +59,10 @@ class DeleteEmptyJournals extends Command
*/
private function deleteUnevenJournals(): void
{
$set = Transaction::whereNull('deleted_at')
->groupBy('transactions.transaction_journal_id')
->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']); /** @phpstan-ignore-line */
$set = Transaction::whereNull('deleted_at')
->groupBy('transactions.transaction_journal_id')
->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']);
/** @phpstan-ignore-line */
$total = 0;
/** @var Transaction $row */
foreach ($set as $row) {

View File

@@ -43,8 +43,8 @@ class FixAccountTypes extends Command
{
use ShowsFriendlyMessages;
protected $description = 'Make sure all journals have the correct from/to account types.';
protected $signature = 'firefly-iii:fix-account-types';
protected $description = 'Make sure all journals have the correct from/to account types.';
protected $signature = 'firefly-iii:fix-account-types';
private int $count;
private array $expected;
private AccountFactory $factory;

View File

@@ -28,7 +28,6 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Facades\Preferences;
use FireflyIII\User;
use Illuminate\Console\Command;

View File

@@ -37,8 +37,8 @@ class FixIbans extends Command
{
use ShowsFriendlyMessages;
protected $description = 'Removes spaces from IBANs';
protected $signature = 'firefly-iii:fix-ibans';
protected $description = 'Removes spaces from IBANs';
protected $signature = 'firefly-iii:fix-ibans';
private int $count = 0;
/**
@@ -91,7 +91,7 @@ class FixIbans extends Command
/** @var Account $account */
foreach ($accounts as $account) {
$userId = $account->user_id;
$set[$userId] = $set[$userId] ?? [];
$set[$userId] ??= [];
$iban = (string)$account->iban;
if ('' === $iban) {
continue;

View File

@@ -40,8 +40,8 @@ class FixRecurringTransactions extends Command
{
use ShowsFriendlyMessages;
protected $description = 'Fixes recurring transactions with the wrong transaction type.';
protected $signature = 'firefly-iii:fix-recurring-transactions';
protected $description = 'Fixes recurring transactions with the wrong transaction type.';
protected $signature = 'firefly-iii:fix-recurring-transactions';
private int $count = 0;
private RecurringRepositoryInterface $recurringRepos;
private UserRepositoryInterface $userRepos;

View File

@@ -54,8 +54,8 @@ class CreateDatabase extends Command
return 0;
}
// try to set up a raw connection:
$exists = false;
$dsn = sprintf('mysql:host=%s;port=%d;charset=utf8mb4', env('DB_HOST', 'localhost'), env('DB_PORT', '3306'));
$exists = false;
$dsn = sprintf('mysql:host=%s;port=%d;charset=utf8mb4', env('DB_HOST', 'localhost'), env('DB_PORT', '3306'));
if ('' !== env('DB_SOCKET', '')) {
$dsn = sprintf('mysql:unix_socket=%s;charset=utf8mb4', env('DB_SOCKET', ''));
@@ -79,7 +79,7 @@ class CreateDatabase extends Command
// only continue when no error.
// with PDO, try to list DB's (
/** @var array $stmt */
$stmt = $pdo->query('SHOW DATABASES;');
$stmt = $pdo->query('SHOW DATABASES;');
// slightly more complex but less error-prone.
foreach ($stmt as $row) {
$name = $row['Database'] ?? false;

View File

@@ -42,7 +42,7 @@ class CreateFirstUser extends Command
protected $description = 'Creates a new user and gives admin rights. Outputs the password on the command line. Strictly for testing.';
protected $signature = 'firefly-iii:create-first-user {email}';
protected $signature = 'firefly-iii:create-first-user {email}';
private UserRepositoryInterface $repository;
/**

View File

@@ -53,8 +53,8 @@ class ForceDecimalSize extends Command
{
use ShowsFriendlyMessages;
protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';
protected $signature = 'firefly-iii:force-decimal-size';
protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';
protected $signature = 'firefly-iii:force-decimal-size';
private string $cast;
private array $classes
= [
@@ -260,7 +260,7 @@ class ForceDecimalSize extends Command
continue;
}
// fix $field by rounding it down correctly.
$pow = 10** $currency->decimal_places;
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
$this->friendlyInfo(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct));
Account::find($account->id)->update([$field => $correct]);
@@ -313,7 +313,7 @@ class ForceDecimalSize extends Command
continue;
}
// fix $field by rounding it down correctly.
$pow = 10** $currency->decimal_places;
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
$this->friendlyWarning(sprintf('%s #%d has %s with value "%s", this has been corrected to "%s".', $table, $item->id, $field, $value, $correct));
$class::find($item->id)->update([$field => $correct]);
@@ -366,7 +366,7 @@ class ForceDecimalSize extends Command
continue;
}
// fix $field by rounding it down correctly.
$pow = 10** $currency->decimal_places;
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
$this->friendlyWarning(
sprintf('Piggy bank event #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
@@ -421,7 +421,7 @@ class ForceDecimalSize extends Command
continue;
}
// fix $field by rounding it down correctly.
$pow = 10** $currency->decimal_places;
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
$this->friendlyWarning(
sprintf('Piggy bank repetition #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
@@ -475,7 +475,7 @@ class ForceDecimalSize extends Command
continue;
}
// fix $field by rounding it down correctly.
$pow = 10** $currency->decimal_places;
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
$this->friendlyWarning(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct));
PiggyBank::find($item->id)->update([$field => $correct]);
@@ -512,7 +512,7 @@ class ForceDecimalSize extends Command
continue;
}
// fix $field by rounding it down correctly.
$pow = (float)10** $currency->decimal_places;
$pow = (float)10 ** $currency->decimal_places;
$correct = bcdiv((string)round((float)$value * $pow), (string)$pow, 12);
$this->friendlyWarning(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct));
Transaction::find($item->id)->update(['amount' => $correct]);
@@ -539,7 +539,7 @@ class ForceDecimalSize extends Command
continue;
}
// fix $field by rounding it down correctly.
$pow = (float)10** $currency->decimal_places;
$pow = (float)10 ** $currency->decimal_places;
$correct = bcdiv((string)round((float)$value * $pow), (string)$pow, 12);
$this->friendlyWarning(
sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)

View File

@@ -67,13 +67,13 @@ class ScanAttachments extends Command
$decryptedContent = $encryptedContent;
}
$tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII');
if(false === $tempFileName) {
if (false === $tempFileName) {
app('log')->error(sprintf('Could not create temporary file for attachment #%d', $attachment->id));
exit(1);
}
file_put_contents($tempFileName, $decryptedContent);
$attachment->md5 = (string) md5_file($tempFileName);
$attachment->mime = (string) mime_content_type($tempFileName);
$attachment->md5 = (string)md5_file($tempFileName);
$attachment->mime = (string)mime_content_type($tempFileName);
$attachment->save();
$this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id));
}

View File

@@ -61,15 +61,15 @@ class UpgradeFireflyInstructions extends Command
*/
private function updateInstructions(): void
{
$version = (string) config('firefly.version');
$version = (string)config('firefly.version');
/** @var array $config */
$config = config('upgrade.text.upgrade');
$text = '';
$config = config('upgrade.text.upgrade');
$text = '';
/** @var string $compare */
foreach (array_keys($config) as $compare) {
// if string starts with:
if (str_starts_with($version, $compare)) {
$text = (string) $config[$compare];
$text = (string)$config[$compare];
}
}
@@ -175,15 +175,15 @@ class UpgradeFireflyInstructions extends Command
*/
private function installInstructions(): void
{
$version = (string) config('firefly.version');
$version = (string)config('firefly.version');
/** @var array $config */
$config = config('upgrade.text.install');
$text = '';
$config = config('upgrade.text.install');
$text = '';
/** @var string $compare */
foreach (array_keys($config) as $compare) {
// if string starts with:
if (str_starts_with($version, $compare)) {
$text = (string) $config[$compare];
$text = (string)$config[$compare];
}
}
$this->newLine();

View File

@@ -27,9 +27,7 @@ namespace FireflyIII\Console\Commands\System;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command;
use Illuminate\Database\QueryException;
use Illuminate\Filesystem\FilesystemAdapter;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemReader;
use Storage;
/**

View File

@@ -50,7 +50,7 @@ class ApplyRules extends Command
protected $description = 'This command will apply your rules and rule groups on a selection of your transactions.';
protected $signature
protected $signature
= 'firefly-iii:apply-rules
{--user=1 : The user ID.}
{--token= : The user\'s access token.}
@@ -297,7 +297,7 @@ class ApplyRules extends Command
if (null !== $endString && '' !== $endString) {
$inputEnd = Carbon::createFromFormat('Y-m-d', $endString);
}
if(false === $inputEnd || false === $inputStart) {
if (false === $inputEnd || false === $inputStart) {
Log::error('Could not parse start or end date in verifyInputDate().');
return;
}

View File

@@ -66,7 +66,7 @@ class Cron extends Command
} catch (InvalidArgumentException $e) {
$this->friendlyError(sprintf('"%s" is not a valid date', $this->option('date')));
}
$force = (bool) $this->option('force'); // @phpstan-ignore-line
$force = (bool)$this->option('force'); // @phpstan-ignore-line
/*
* Fire exchange rates cron job.

View File

@@ -46,8 +46,8 @@ class AccountCurrencies extends Command
public const string CONFIG_NAME = '480_account_currencies';
protected $description = 'Give all accounts proper currency info.';
protected $signature = 'firefly-iii:account-currencies {--F|force : Force the execution of this command.}';
protected $description = 'Give all accounts proper currency info.';
protected $signature = 'firefly-iii:account-currencies {--F|force : Force the execution of this command.}';
private AccountRepositoryInterface $accountRepos;
private int $count;
private UserRepositoryInterface $userRepos;
@@ -109,14 +109,14 @@ class AccountCurrencies extends Command
*/
private function updateAccountCurrencies(): void
{
$users = $this->userRepos->all();
$users = $this->userRepos->all();
foreach ($users as $user) {
$this->updateCurrenciesForUser($user);
}
}
/**
* @param User $user
* @param User $user
*
* @throws FireflyException
*/

View File

@@ -51,8 +51,8 @@ class MigrateToGroups extends Command
use ShowsFriendlyMessages;
public const string CONFIG_NAME = '480_migrated_to_groups';
protected $description = 'Migrates a pre-4.7.8 transaction structure to the 4.7.8+ transaction structure.';
protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}';
protected $description = 'Migrates a pre-4.7.8 transaction structure to the 4.7.8+ transaction structure.';
protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}';
private JournalCLIRepositoryInterface $cliRepository;
private int $count;
private TransactionGroupFactory $groupFactory;

View File

@@ -169,7 +169,7 @@ class MigrateToRules extends Command
if ('MIGRATED_TO_RULES' === $bill->match) {
return;
}
$languageString = null !== $language->data && !is_array($language->data) ? (string)$language->data : 'en_US';
$languageString = null !== $language->data && !is_array($language->data) ? (string)$language->data : 'en_US';
// get match thing:
$match = implode(' ', explode(',', $bill->match));

View File

@@ -45,8 +45,8 @@ class OtherCurrenciesCorrections extends Command
use ShowsFriendlyMessages;
public const string CONFIG_NAME = '480_other_currencies';
protected $description = 'Update all journal currency information.';
protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}';
protected $description = 'Update all journal currency information.';
protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}';
private array $accountCurrencies;
private AccountRepositoryInterface $accountRepos;
private JournalCLIRepositoryInterface $cliRepos;

View File

@@ -42,8 +42,8 @@ class TransactionIdentifier extends Command
use ShowsFriendlyMessages;
public const string CONFIG_NAME = '480_transaction_identifier';
protected $description = 'Fixes transaction identifiers.';
protected $signature = 'firefly-iii:transaction-identifiers {--F|force : Force the execution of this command.}';
protected $description = 'Fixes transaction identifiers.';
protected $signature = 'firefly-iii:transaction-identifiers {--F|force : Force the execution of this command.}';
private JournalCLIRepositoryInterface $cliRepository;
private int $count;

View File

@@ -43,8 +43,8 @@ class TransferCurrenciesCorrections extends Command
use ShowsFriendlyMessages;
public const string CONFIG_NAME = '480_transfer_currencies';
protected $description = 'Updates transfer currency information.';
protected $signature = 'firefly-iii:transfer-currencies {--F|force : Force the execution of this command.}';
protected $description = 'Updates transfer currency information.';
protected $signature = 'firefly-iii:transfer-currencies {--F|force : Force the execution of this command.}';
private array $accountCurrencies;
private AccountRepositoryInterface $accountRepos;
private JournalCLIRepositoryInterface $cliRepos;