mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-13 16:00:13 +00:00
Various code cleanup.
This commit is contained in:
@@ -25,7 +25,9 @@ use Storage;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CreateExportextends
|
* Class CreateExport
|
||||||
|
*
|
||||||
|
* Generates export from the command line.
|
||||||
*
|
*
|
||||||
* @package FireflyIII\Console\Commands
|
* @package FireflyIII\Console\Commands
|
||||||
*/
|
*/
|
||||||
@@ -61,6 +63,10 @@ class CreateExport extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five its fine.
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
|
*
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
@@ -51,6 +51,10 @@ class DecryptAttachment extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five its fine.
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
@@ -35,8 +35,10 @@ use Schema;
|
|||||||
/**
|
/**
|
||||||
* Class UpgradeDatabase
|
* Class UpgradeDatabase
|
||||||
*
|
*
|
||||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) // it just touches a lot of things.
|
* Upgrade user database.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) // it just touches a lot of things.
|
||||||
* @package FireflyIII\Console\Commands
|
* @package FireflyIII\Console\Commands
|
||||||
*/
|
*/
|
||||||
class UpgradeDatabase extends Command
|
class UpgradeDatabase extends Command
|
||||||
@@ -138,6 +140,9 @@ class UpgradeDatabase extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Each (asset) account must have a reference to a preferred currency. If the account does not have one, it's forced upon the account.
|
* Each (asset) account must have a reference to a preferred currency. If the account does not have one, it's forced upon the account.
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's seven but it can't really be helped.
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
public function updateAccountCurrencies(): void
|
public function updateAccountCurrencies(): void
|
||||||
{
|
{
|
||||||
@@ -192,6 +197,8 @@ class UpgradeDatabase extends Command
|
|||||||
*
|
*
|
||||||
* Both source and destination must match the respective currency preference of the related asset account.
|
* Both source and destination must match the respective currency preference of the related asset account.
|
||||||
* So FF3 must verify all transactions.
|
* So FF3 must verify all transactions.
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
public function updateOtherCurrencies(): void
|
public function updateOtherCurrencies(): void
|
||||||
{
|
{
|
||||||
@@ -353,6 +360,12 @@ class UpgradeDatabase extends Command
|
|||||||
*
|
*
|
||||||
* The transaction that is sent to this function MUST be the source transaction (amount negative).
|
* The transaction that is sent to this function MUST be the source transaction (amount negative).
|
||||||
*
|
*
|
||||||
|
* Method is long and complex bit I'm taking it for granted.
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
|
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
*
|
||||||
* @param Transaction $transaction
|
* @param Transaction $transaction
|
||||||
*/
|
*/
|
||||||
private function updateTransactionCurrency(Transaction $transaction): void
|
private function updateTransactionCurrency(Transaction $transaction): void
|
||||||
|
@@ -16,9 +16,17 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
|||||||
use Log;
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait VerifiesAccessToken
|
||||||
|
*
|
||||||
|
* Verifies user access token for sensitive commands.
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Console\Commands
|
||||||
|
*/
|
||||||
trait VerifiesAccessToken
|
trait VerifiesAccessToken
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* Abstract method to make sure trait knows about method "option".
|
||||||
* @param null $key
|
* @param null $key
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -26,6 +34,8 @@ trait VerifiesAccessToken
|
|||||||
abstract public function option($key = null);
|
abstract public function option($key = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns false when given token does not match given user token.
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function verifyAccessToken(): bool
|
protected function verifyAccessToken(): bool
|
||||||
|
@@ -34,6 +34,8 @@ use stdClass;
|
|||||||
/**
|
/**
|
||||||
* Class VerifyDatabase
|
* Class VerifyDatabase
|
||||||
*
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||||
|
*
|
||||||
* @package FireflyIII\Console\Commands
|
* @package FireflyIII\Console\Commands
|
||||||
*/
|
*/
|
||||||
class VerifyDatabase extends Command
|
class VerifyDatabase extends Command
|
||||||
@@ -72,44 +74,23 @@ class VerifyDatabase extends Command
|
|||||||
$this->reportObject('budget');
|
$this->reportObject('budget');
|
||||||
$this->reportObject('category');
|
$this->reportObject('category');
|
||||||
$this->reportObject('tag');
|
$this->reportObject('tag');
|
||||||
|
|
||||||
// accounts with no transactions.
|
|
||||||
$this->reportAccounts();
|
$this->reportAccounts();
|
||||||
// budgets with no limits
|
|
||||||
$this->reportBudgetLimits();
|
$this->reportBudgetLimits();
|
||||||
// budgets with no transactions
|
|
||||||
|
|
||||||
// sum of transactions is not zero.
|
|
||||||
$this->reportSum();
|
$this->reportSum();
|
||||||
// any deleted transaction journals that have transactions that are NOT deleted:
|
|
||||||
$this->reportJournals();
|
$this->reportJournals();
|
||||||
// deleted transactions that are connected to a not deleted journal.
|
|
||||||
$this->reportTransactions();
|
$this->reportTransactions();
|
||||||
// deleted accounts that still have not deleted transactions or journals attached to them.
|
|
||||||
$this->reportDeletedAccounts();
|
$this->reportDeletedAccounts();
|
||||||
|
|
||||||
// report on journals with no transactions at all.
|
|
||||||
$this->reportNoTransactions();
|
$this->reportNoTransactions();
|
||||||
|
|
||||||
// transfers with budgets.
|
|
||||||
$this->reportTransfersBudgets();
|
$this->reportTransfersBudgets();
|
||||||
|
|
||||||
// report on journals with the wrong types of accounts.
|
|
||||||
$this->reportIncorrectJournals();
|
$this->reportIncorrectJournals();
|
||||||
|
|
||||||
// report (and fix) piggy banks
|
|
||||||
$this->repairPiggyBanks();
|
$this->repairPiggyBanks();
|
||||||
|
|
||||||
// create default link types if necessary
|
|
||||||
$this->createLinkTypes();
|
$this->createLinkTypes();
|
||||||
|
|
||||||
// create user access tokens, if not present already.
|
|
||||||
$this->createAccessTokens();
|
$this->createAccessTokens();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Create user access tokens, if not present already.
|
||||||
*/
|
*/
|
||||||
private function createAccessTokens()
|
private function createAccessTokens()
|
||||||
{
|
{
|
||||||
@@ -126,7 +107,7 @@ class VerifyDatabase extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Create default link types if necessary.
|
||||||
*/
|
*/
|
||||||
private function createLinkTypes()
|
private function createLinkTypes()
|
||||||
{
|
{
|
||||||
@@ -150,7 +131,7 @@ class VerifyDatabase extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure there are only transfers linked to piggy bank events.
|
* Eeport (and fix) piggy banks. Make sure there are only transfers linked to piggy bank events.
|
||||||
*/
|
*/
|
||||||
private function repairPiggyBanks(): void
|
private function repairPiggyBanks(): void
|
||||||
{
|
{
|
||||||
|
@@ -16,6 +16,9 @@ namespace FireflyIII\Console;
|
|||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File to make sure commnds work.
|
||||||
|
*/
|
||||||
class Kernel extends ConsoleKernel
|
class Kernel extends ConsoleKernel
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +47,7 @@ class Kernel extends ConsoleKernel
|
|||||||
* Define the application's command schedule.
|
* Define the application's command schedule.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||||
*
|
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
|
@@ -67,6 +67,7 @@ class Handler extends ExceptionHandler
|
|||||||
*
|
*
|
||||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||||
*
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five its fine.
|
||||||
* @param \Exception $exception
|
* @param \Exception $exception
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
@@ -31,6 +31,7 @@ use Steam;
|
|||||||
*
|
*
|
||||||
* Class Entry
|
* Class Entry
|
||||||
* @SuppressWarnings(PHPMD.LongVariable)
|
* @SuppressWarnings(PHPMD.LongVariable)
|
||||||
|
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||||
*
|
*
|
||||||
* @package FireflyIII\Export\Entry
|
* @package FireflyIII\Export\Entry
|
||||||
*/
|
*/
|
||||||
@@ -84,40 +85,12 @@ final class Entry
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $object
|
|
||||||
*
|
|
||||||
* @return Entry
|
|
||||||
*/
|
|
||||||
public static function fromObject($object): Entry
|
|
||||||
{
|
|
||||||
$entry = new self;
|
|
||||||
$entry->journal_id = $object->transaction_journal_id;
|
|
||||||
$entry->description = Steam::decrypt(intval($object->journal_encrypted), $object->journal_description);
|
|
||||||
$entry->amount = $object->amount;
|
|
||||||
$entry->date = $object->date;
|
|
||||||
$entry->transaction_type = $object->transaction_type;
|
|
||||||
$entry->currency_code = $object->transaction_currency_code;
|
|
||||||
$entry->asset_account_id = $object->account_id;
|
|
||||||
$entry->asset_account_name = Steam::decrypt(intval($object->account_name_encrypted), $object->account_name);
|
|
||||||
$entry->opposing_account_id = $object->opposing_account_id;
|
|
||||||
$entry->opposing_account_name = Steam::decrypt(intval($object->opposing_account_encrypted), $object->opposing_account_name);
|
|
||||||
$entry->category_id = $object->category_id ?? '';
|
|
||||||
$entry->category_name = $object->category_name ?? '';
|
|
||||||
$entry->budget_id = $object->budget_id ?? '';
|
|
||||||
$entry->budget_name = $object->budget_name ?? '';
|
|
||||||
|
|
||||||
// update description when transaction description is different:
|
|
||||||
if (!is_null($object->description) && $object->description !== $entry->description) {
|
|
||||||
$entry->description = $entry->description . ' (' . $object->description . ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a given transaction (as collected by the collector) into an export entry.
|
* Converts a given transaction (as collected by the collector) into an export entry.
|
||||||
*
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // complex but little choice.
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped
|
||||||
|
*
|
||||||
* @param Transaction $transaction
|
* @param Transaction $transaction
|
||||||
*
|
*
|
||||||
* @return Entry
|
* @return Entry
|
||||||
|
@@ -34,6 +34,8 @@ use ZipArchive;
|
|||||||
/**
|
/**
|
||||||
* Class ExpandedProcessor
|
* Class ExpandedProcessor
|
||||||
*
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) // its doing a lot.
|
||||||
|
*
|
||||||
* @package FireflyIII\Export
|
* @package FireflyIII\Export
|
||||||
*/
|
*/
|
||||||
class ExpandedProcessor implements ProcessorInterface
|
class ExpandedProcessor implements ProcessorInterface
|
||||||
@@ -84,7 +86,10 @@ class ExpandedProcessor implements ProcessorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Collects all transaction journals.
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
public function collectJournals(): bool
|
public function collectJournals(): bool
|
||||||
{
|
{
|
||||||
@@ -102,6 +107,7 @@ class ExpandedProcessor implements ProcessorInterface
|
|||||||
$opposingIds = $transactions->pluck('opposing_account_id')->toArray();
|
$opposingIds = $transactions->pluck('opposing_account_id')->toArray();
|
||||||
$notes = $this->getNotes($ids);
|
$notes = $this->getNotes($ids);
|
||||||
$tags = $this->getTags($ids);
|
$tags = $this->getTags($ids);
|
||||||
|
/** @var array $ibans */
|
||||||
$ibans = $this->getIbans($assetIds) + $this->getIbans($opposingIds);
|
$ibans = $this->getIbans($assetIds) + $this->getIbans($opposingIds);
|
||||||
$currencies = $this->getAccountCurrencies($ibans);
|
$currencies = $this->getAccountCurrencies($ibans);
|
||||||
$transactions->each(
|
$transactions->each(
|
||||||
|
@@ -145,6 +145,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
|||||||
* @param Carbon $date
|
* @param Carbon $date
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // not that long
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
private function getAuditReport(Account $account, Carbon $date): array
|
private function getAuditReport(Account $account, Carbon $date): array
|
||||||
{
|
{
|
||||||
@@ -175,9 +178,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
|||||||
$transaction->currency = $currency;
|
$transaction->currency = $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Reverse set again.
|
|
||||||
*/
|
|
||||||
$return = [
|
$return = [
|
||||||
'journals' => $journals->reverse(),
|
'journals' => $journals->reverse(),
|
||||||
'exists' => $journals->count() > 0,
|
'exists' => $journals->count() > 0,
|
||||||
|
Reference in New Issue
Block a user