mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Various code cleanup.
This commit is contained in:
@@ -96,6 +96,7 @@ class CorrectOpeningBalanceCurrencies extends Command
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return int
|
||||
* @throws JsonException
|
||||
*/
|
||||
private function correctJournal(TransactionJournal $journal): int
|
||||
{
|
||||
@@ -146,7 +147,6 @@ class CorrectOpeningBalanceCurrencies extends Command
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
* @throws JsonException
|
||||
*/
|
||||
private function getCurrency(Account $account): TransactionCurrency
|
||||
{
|
||||
|
@@ -63,7 +63,7 @@ class CreateAccessTokens extends Command
|
||||
$users = $repository->all();
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$pref = app('preferences')->getForUser($user, 'access_token', null);
|
||||
$pref = app('preferences')->getForUser($user, 'access_token');
|
||||
if (null === $pref) {
|
||||
$token = $user->generateAccessToken();
|
||||
app('preferences')->setForUser($user, 'access_token', $token);
|
||||
|
@@ -57,7 +57,6 @@ class DeleteZeroAmount extends Command
|
||||
$start = microtime(true);
|
||||
$set = Transaction::where('amount', 0)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
|
||||
$set = array_unique($set);
|
||||
/** @var Collection $journals */
|
||||
$journals = TransactionJournal::whereIn('id', $set)->get();
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
|
@@ -67,14 +67,12 @@ class EnableCurrencies extends Command
|
||||
}
|
||||
|
||||
// get all from journals:
|
||||
/** @var Collection $journals */
|
||||
$journals = TransactionJournal::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
|
||||
foreach ($journals as $entry) {
|
||||
$found[] = (int)$entry->transaction_currency_id;
|
||||
}
|
||||
|
||||
// get all from transactions
|
||||
/** @var Collection $transactions */
|
||||
$transactions = Transaction::groupBy('transaction_currency_id', 'foreign_currency_id')->get(['transaction_currency_id', 'foreign_currency_id']);
|
||||
foreach ($transactions as $entry) {
|
||||
$found[] = (int)$entry->transaction_currency_id;
|
||||
@@ -82,7 +80,6 @@ class EnableCurrencies extends Command
|
||||
}
|
||||
|
||||
// get all from budget limits
|
||||
/** @var Collection $limits */
|
||||
$limits = BudgetLimit::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
|
||||
foreach ($limits as $entry) {
|
||||
$found[] = (int)$entry->transaction_currency_id;
|
||||
|
@@ -61,7 +61,7 @@ class FixFrontpageAccounts extends Command
|
||||
$users = User::get();
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$preference = Preferences::getForUser($user, 'frontPageAccounts', null);
|
||||
$preference = Preferences::getForUser($user, 'frontPageAccounts');
|
||||
if (null !== $preference) {
|
||||
$this->fixPreference($preference);
|
||||
}
|
||||
|
@@ -48,9 +48,6 @@ class FixPiggies extends Command
|
||||
*/
|
||||
protected $signature = 'firefly-iii:fix-piggies';
|
||||
|
||||
/** @var int */
|
||||
private $count;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@@ -58,8 +55,8 @@ class FixPiggies extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->count = 0;
|
||||
$start = microtime(true);
|
||||
$count = 0;
|
||||
$start = microtime(true);
|
||||
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get();
|
||||
|
||||
/** @var PiggyBankEvent $event */
|
||||
@@ -74,7 +71,7 @@ class FixPiggies extends Command
|
||||
if (null === $journal) {
|
||||
$event->transaction_journal_id = null;
|
||||
$event->save();
|
||||
$this->count++;
|
||||
$count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -84,14 +81,14 @@ class FixPiggies extends Command
|
||||
$event->transaction_journal_id = null;
|
||||
$event->save();
|
||||
$this->line(sprintf('Piggy bank #%d was referenced by an invalid event. This has been fixed.', $event->piggy_bank_id));
|
||||
$this->count++;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if (0 === $this->count) {
|
||||
if (0 === $count) {
|
||||
$this->line('All piggy bank events are correct.');
|
||||
}
|
||||
if (0 !== $this->count) {
|
||||
$this->line(sprintf('Fixed %d piggy bank event(s).', $this->count));
|
||||
if (0 !== $count) {
|
||||
$this->line(sprintf('Fixed %d piggy bank event(s).', $count));
|
||||
}
|
||||
|
||||
$end = round(microtime(true) - $start, 2);
|
||||
|
@@ -19,8 +19,6 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands;
|
||||
|
@@ -142,7 +142,6 @@ class Cron extends Command
|
||||
* @param bool $force
|
||||
* @param Carbon|null $date
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function autoBudgetCronJob(bool $force, ?Carbon $date): void
|
||||
{
|
||||
|
@@ -106,6 +106,7 @@ class AccountCurrencies extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
@@ -134,6 +135,8 @@ class AccountCurrencies extends Command
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $systemCurrencyCode
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function updateCurrenciesForUser(User $user, string $systemCurrencyCode): void
|
||||
{
|
||||
|
@@ -69,6 +69,7 @@ class AppendBudgetLimitPeriods extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -83,6 +83,7 @@ class BackToJournals extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isMigrated(): bool
|
||||
{
|
||||
@@ -93,6 +94,7 @@ class BackToJournals extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -67,7 +67,6 @@ class BudgetLimitCurrency extends Command
|
||||
/** @var BudgetLimit $budgetLimit */
|
||||
foreach ($budgetLimits as $budgetLimit) {
|
||||
if (null === $budgetLimit->transaction_currency_id) {
|
||||
/** @var Budget $budget */
|
||||
$budget = $budgetLimit->budget;
|
||||
if (null !== $budget) {
|
||||
$user = $budget->user;
|
||||
@@ -96,6 +95,7 @@ class BudgetLimitCurrency extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -93,6 +93,7 @@ class CCLiabilities extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -105,6 +105,7 @@ class MigrateAttachments extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -64,7 +64,6 @@ class MigrateJournalNotes extends Command
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$set = TransactionJournalMeta::whereName('notes')->get();
|
||||
/** @var TransactionJournalMeta $meta */
|
||||
foreach ($set as $meta) {
|
||||
@@ -104,6 +103,7 @@ class MigrateJournalNotes extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -79,6 +79,7 @@ class MigrateRecurrenceMeta extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
@@ -92,6 +93,7 @@ class MigrateRecurrenceMeta extends Command
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws \JsonException
|
||||
*/
|
||||
private function migrateMetaData(): int
|
||||
{
|
||||
@@ -110,6 +112,7 @@ class MigrateRecurrenceMeta extends Command
|
||||
* @param RecurrenceMeta $meta
|
||||
*
|
||||
* @return int
|
||||
* @throws \JsonException
|
||||
*/
|
||||
private function migrateEntry(RecurrenceMeta $meta): int
|
||||
{
|
||||
@@ -125,7 +128,7 @@ class MigrateRecurrenceMeta extends Command
|
||||
|
||||
if ('tags' === $meta->name) {
|
||||
$array = explode(',', $meta->value);
|
||||
$value = json_encode($array, JSON_THROW_ON_ERROR, 512);
|
||||
$value = json_encode($array, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
RecurrenceTransactionMeta::create(
|
||||
|
@@ -74,6 +74,7 @@ class MigrateRecurrenceType extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -72,6 +72,7 @@ class MigrateTagLocations extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -127,6 +127,7 @@ class MigrateToGroups extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isMigrated(): bool
|
||||
{
|
||||
|
@@ -119,6 +119,7 @@ class MigrateToRules extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -112,6 +112,7 @@ class OtherCurrenciesCorrections extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
@@ -161,7 +162,6 @@ class OtherCurrenciesCorrections extends Command
|
||||
|
||||
}
|
||||
|
||||
/** @var Account $account */
|
||||
$account = $leadTransaction->account;
|
||||
$currency = $this->getCurrency($account);
|
||||
if (null === $currency) {
|
||||
|
@@ -96,6 +96,7 @@ class RenameAccountMeta extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -120,6 +120,7 @@ class TransactionIdentifier extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
|
@@ -57,6 +57,7 @@ class UpgradeLiabilities extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
@@ -96,7 +97,7 @@ class UpgradeLiabilities extends Command
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Transaction
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function getSourceTransaction(TransactionJournal $journal): ?Transaction
|
||||
{
|
||||
@@ -106,7 +107,7 @@ class UpgradeLiabilities extends Command
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Transaction
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function getDestinationTransaction(TransactionJournal $journal): ?Transaction
|
||||
{
|
||||
|
@@ -90,7 +90,7 @@ class UpgradeFireflyInstructions extends Command
|
||||
$text = '';
|
||||
foreach (array_keys($config) as $compare) {
|
||||
// if string starts with:
|
||||
if (0 === strpos($version, $compare)) {
|
||||
if (str_starts_with($version, $compare)) {
|
||||
$text = $config[$compare];
|
||||
}
|
||||
}
|
||||
@@ -119,9 +119,7 @@ class UpgradeFireflyInstructions extends Command
|
||||
private function showLine(): void
|
||||
{
|
||||
$line = '+';
|
||||
for ($i = 0; $i < 78; ++$i) {
|
||||
$line .= '-';
|
||||
}
|
||||
$line .= str_repeat('-', 78);
|
||||
$line .= '+';
|
||||
$this->line($line);
|
||||
}
|
||||
@@ -163,7 +161,7 @@ class UpgradeFireflyInstructions extends Command
|
||||
$text = '';
|
||||
foreach (array_keys($config) as $compare) {
|
||||
// if string starts with:
|
||||
if (0 === strpos($version, $compare)) {
|
||||
if (str_starts_with($version, $compare)) {
|
||||
$text = $config[$compare];
|
||||
}
|
||||
}
|
||||
|
@@ -67,6 +67,7 @@ trait VerifiesAccessToken
|
||||
* Returns false when given token does not match given user token.
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function verifyAccessToken(): bool
|
||||
{
|
||||
@@ -81,7 +82,7 @@ trait VerifiesAccessToken
|
||||
|
||||
return false;
|
||||
}
|
||||
$accessToken = app('preferences')->getForUser($user, 'access_token', null);
|
||||
$accessToken = app('preferences')->getForUser($user, 'access_token');
|
||||
if (null === $accessToken) {
|
||||
Log::error(sprintf('User #%d has no access token, so cannot access command line options.', $userId));
|
||||
|
||||
|
Reference in New Issue
Block a user