Clean up various code.

This commit is contained in:
James Cole 2023-12-22 17:28:42 +01:00
parent e8890ada7c
commit 067d160c13
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
33 changed files with 331 additions and 699 deletions

View File

@ -470,16 +470,16 @@
},
{
"name": "sebastian/diff",
"version": "5.0.3",
"version": "5.1.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b"
"reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b",
"reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/fbf413a49e54f6b9b17e12d900ac7f6101591b7f",
"reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f",
"shasum": ""
},
"require": {
@ -492,7 +492,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "5.0-dev"
"dev-main": "5.1-dev"
}
},
"autoload": {
@ -525,7 +525,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/diff/issues",
"security": "https://github.com/sebastianbergmann/diff/security/policy",
"source": "https://github.com/sebastianbergmann/diff/tree/5.0.3"
"source": "https://github.com/sebastianbergmann/diff/tree/5.1.0"
},
"funding": [
{
@ -533,7 +533,7 @@
"type": "github"
}
],
"time": "2023-05-01T07:48:21+00:00"
"time": "2023-12-22T10:55:06+00:00"
},
{
"name": "symfony/console",

View File

@ -70,8 +70,8 @@
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
<properties>
<!-- TODO we want to be at a value of 40. But we start high, and drop the bar slowly. -->
<property name="minimum" value="100"/>
<!-- 75 seems like a nice number. Shorter isn't always feasible and there are a few exceptions already -->
<property name="minimum" value="75"/>
<property name="ignore-whitespace" value="true"/>
</properties>
</rule>

View File

@ -146,13 +146,7 @@ class BasicController extends Controller
// collect income of user using the new group collector.
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setRange($start, $end)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes([TransactionType::DEPOSIT])
;
$collector->setRange($start, $end)->setPage($this->parameters->get('page'))->setTypes([TransactionType::DEPOSIT]);
$set = $collector->getExtractedJournals();
@ -171,13 +165,7 @@ class BasicController extends Controller
// collect expenses of user using the new group collector.
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setRange($start, $end)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes([TransactionType::WITHDRAWAL])
;
$collector->setRange($start, $end)->setPage($this->parameters->get('page'))->setTypes([TransactionType::WITHDRAWAL]);
$set = $collector->getExtractedJournals();
/** @var array $transactionJournal */

View File

@ -62,74 +62,14 @@ class UpdateRequest extends FormRequest
public function getAll(): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
$this->integerFields = [
'order',
'currency_id',
'foreign_currency_id',
'transaction_journal_id',
'source_id',
'destination_id',
'budget_id',
'category_id',
'bill_id',
'recurrence_id',
];
$this->dateFields = [
'date',
'interest_date',
'book_date',
'process_date',
'due_date',
'payment_date',
'invoice_date',
];
$this->textareaFields = [
'notes',
];
$this->floatFields = [ // not really floats, for validation.
'amount',
'foreign_amount',
];
$this->stringFields = [
'type',
'currency_code',
'foreign_currency_code',
'description',
'source_name',
'source_iban',
'source_number',
'source_bic',
'destination_name',
'destination_iban',
'destination_number',
'destination_bic',
'budget_name',
'category_name',
'bill_name',
'internal_reference',
'external_id',
'bunq_payment_id',
'sepa_cc',
'sepa_ct_op',
'sepa_ct_id',
'sepa_db',
'sepa_country',
'sepa_ep',
'sepa_ci',
'sepa_batch_id',
'external_url',
];
$this->booleanFields = [
'reconciled',
];
$this->arrayFields = [
'tags',
];
$this->integerFields = ['order', 'currency_id', 'foreign_currency_id', 'transaction_journal_id', 'source_id', 'destination_id', 'budget_id', 'category_id', 'bill_id', 'recurrence_id'];
$this->dateFields = ['date', 'interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date'];
$this->textareaFields = ['notes'];
// not really floats, for validation.
$this->floatFields = ['amount', 'foreign_amount'];
$this->stringFields = ['type', 'currency_code', 'foreign_currency_code', 'description', 'source_name', 'source_iban', 'source_number', 'source_bic', 'destination_name', 'destination_iban', 'destination_number', 'destination_bic', 'budget_name', 'category_name', 'bill_name', 'internal_reference', 'external_id', 'bunq_payment_id', 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id', 'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id', 'external_url'];
$this->booleanFields = ['reconciled'];
$this->arrayFields = ['tags'];
$data = [];
if ($this->has('transactions')) {
$data['transactions'] = $this->getTransactionData();

View File

@ -240,7 +240,7 @@ class BasicController extends Controller
}
/**
* @throws \Exception
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function getLeftToSpendInfo(Carbon $start, Carbon $end): array
{

View File

@ -47,64 +47,7 @@ class FixPostgresSequences extends Command
return 0;
}
$this->friendlyLine('Going to verify PostgreSQL table sequences.');
$tablesToCheck = [
'2fa_tokens',
'account_meta',
'account_types',
'accounts',
'attachments',
'auto_budgets',
'available_budgets',
'bills',
'budget_limits',
'budget_transaction',
'budget_transaction_journal',
'budgets',
'categories',
'category_transaction',
'category_transaction_journal',
'configuration',
'currency_exchange_rates',
'failed_jobs',
'group_journals',
'jobs',
'journal_links',
'journal_meta',
'limit_repetitions',
'link_types',
'locations',
'migrations',
'notes',
'oauth_clients',
'oauth_personal_access_clients',
'object_groups',
'permissions',
'piggy_bank_events',
'piggy_bank_repetitions',
'piggy_banks',
'preferences',
'recurrences',
'recurrences_meta',
'recurrences_repetitions',
'recurrences_transactions',
'roles',
'rt_meta',
'rule_actions',
'rule_groups',
'rule_triggers',
'rules',
'tag_transaction_journal',
'tags',
'transaction_currencies',
'transaction_groups',
'transaction_journals',
'transaction_types',
'transactions',
'users',
'webhook_attempts',
'webhook_messages',
'webhooks',
];
$tablesToCheck = ['2fa_tokens', 'account_meta', 'account_types', 'accounts', 'attachments', 'auto_budgets', 'available_budgets', 'bills', 'budget_limits', 'budget_transaction', 'budget_transaction_journal', 'budgets', 'categories', 'category_transaction', 'category_transaction_journal', 'configuration', 'currency_exchange_rates', 'failed_jobs', 'group_journals', 'jobs', 'journal_links', 'journal_meta', 'limit_repetitions', 'link_types', 'locations', 'migrations', 'notes', 'oauth_clients', 'oauth_personal_access_clients', 'object_groups', 'permissions', 'piggy_bank_events', 'piggy_bank_repetitions', 'piggy_banks', 'preferences', 'recurrences', 'recurrences_meta', 'recurrences_repetitions', 'recurrences_transactions', 'roles', 'rt_meta', 'rule_actions', 'rule_groups', 'rule_triggers', 'rules', 'tag_transaction_journal', 'tags', 'transaction_currencies', 'transaction_groups', 'transaction_journals', 'transaction_types', 'transactions', 'users', 'webhook_attempts', 'webhook_messages', 'webhooks'];
foreach ($tablesToCheck as $tableToCheck) {
$this->friendlyLine(sprintf('Checking the next id sequence for table "%s".', $tableToCheck));

View File

@ -209,6 +209,9 @@ class MigrateToGroups extends Command
return $set->first();
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function generateTransaction(TransactionJournal $journal, Transaction $transaction): array
{
app('log')->debug(sprintf('Now going to add transaction #%d to the array.', $transaction->id));

View File

@ -182,9 +182,14 @@ class TransactionJournalFactory
}
/**
* TODO typeOverrule: the account validator may have another opinion on the transaction type. not sure what to do
* with this.
*
* @throws DuplicateTransactionException
* @throws FireflyException
* */
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function createJournal(NullArrayObject $row): ?TransactionJournal
{
$row['import_hash_v2'] = $this->hashArray($row);
@ -214,9 +219,6 @@ class TransactionJournalFactory
return null;
}
// typeOverrule: the account validator may have another opinion on the transaction type.
// not sure what to do with this.
/** create or get source and destination accounts */
$sourceInfo = [
'id' => $row['source_id'],
@ -237,9 +239,7 @@ class TransactionJournalFactory
];
app('log')->debug('Source info:', $sourceInfo);
app('log')->debug('Destination info:', $destInfo);
app('log')->debug('Now calling getAccount for the source.');
$sourceAccount = $this->getAccount($type->type, 'source', $sourceInfo);
app('log')->debug('Now calling getAccount for the destination.');
$destinationAccount = $this->getAccount($type->type, 'destination', $destInfo);
app('log')->debug('Done with getAccount(2x)');
@ -285,15 +285,12 @@ class TransactionJournalFactory
try {
$negative = $transactionFactory->createNegative((string) $row['amount'], (string) $row['foreign_amount']);
} catch (FireflyException $e) {
app('log')->error('Exception creating negative transaction.');
app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString());
app('log')->error(sprintf('Exception creating negative transaction: %s', $e->getMessage()));
$this->forceDeleteOnError(new Collection([$journal]));
throw new FireflyException($e->getMessage(), 0, $e);
}
// and the destination one:
/** @var TransactionFactory $transactionFactory */
$transactionFactory = app(TransactionFactory::class);
$transactionFactory->setUser($this->user);
@ -307,37 +304,19 @@ class TransactionJournalFactory
try {
$transactionFactory->createPositive((string) $row['amount'], (string) $row['foreign_amount']);
} catch (FireflyException $e) {
app('log')->error('Exception creating positive transaction.');
app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString());
app('log')->warning('Delete negative transaction.');
app('log')->error(sprintf('Exception creating positive transaction: %s', $e->getMessage()));
$this->forceTrDelete($negative);
$this->forceDeleteOnError(new Collection([$journal]));
throw new FireflyException($e->getMessage(), 0, $e);
}
// verify that journal has two transactions. Otherwise, delete and cancel.
$journal->completed = true;
$journal->save();
// Link all other data to the journal.
// Link budget
$this->storeBudget($journal, $row);
// Link category
$this->storeCategory($journal, $row);
// Set notes
$this->storeNotes($journal, $row['notes']);
// Set piggy bank
$this->storePiggyEvent($journal, $row);
// Set tags
$this->storeTags($journal, $row['tags']);
// set all meta fields
$this->storeMetaFields($journal, $row);
return $journal;
@ -348,7 +327,13 @@ class TransactionJournalFactory
$dataRow = $row->getArrayCopy();
unset($dataRow['import_hash_v2'], $dataRow['original_source']);
try {
$json = json_encode($dataRow, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
app('log')->error(sprintf('Could not encode dataRow: %s', $e->getMessage()));
$json = microtime();
}
$hash = hash('sha256', $json);
app('log')->debug(sprintf('The hash is: %s', $hash), $dataRow);

View File

@ -152,22 +152,7 @@ class EditController extends Controller
$request->session()->flash('preFilled', $preFilled);
return view(
'accounts.edit',
compact(
'account',
'currency',
'subTitle',
'subTitleIcon',
'locations',
'liabilityDirections',
'objectType',
'roles',
'preFilled',
'liabilityTypes',
'interestPeriods'
)
);
return view('accounts.edit', compact('account', 'currency', 'subTitle', 'subTitleIcon', 'locations', 'liabilityDirections', 'objectType', 'roles', 'preFilled', 'liabilityTypes', 'interestPeriods'));
}
/**

View File

@ -44,11 +44,8 @@ class ExpenseReportController extends Controller
use AugumentData;
use TransactionCalculation;
/** @var AccountRepositoryInterface The account repository */
protected $accountRepository;
/** @var GeneratorInterface Chart generation methods. */
protected $generator;
protected AccountRepositoryInterface $accountRepository;
protected GeneratorInterface $generator;
/**
* ExpenseReportController constructor.
@ -71,7 +68,8 @@ class ExpenseReportController extends Controller
*
* TODO this chart is not multi currency aware.
*
* */
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function mainChart(Collection $accounts, Collection $expense, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties();
@ -89,9 +87,8 @@ class ExpenseReportController extends Controller
$chartData = [];
$currentStart = clone $start;
$combined = $this->combineAccounts($expense);
// make "all" set:
$all = new Collection();
foreach ($combined as $name => $combination) {
foreach ($combined as $combination) {
$all = $all->merge($combination);
}

View File

@ -45,8 +45,7 @@ class ReportController extends Controller
use BasicDataSupport;
use ChartGeneration;
/** @var GeneratorInterface Chart generation methods. */
protected $generator;
protected GeneratorInterface $generator;
/**
* ReportController constructor.
@ -133,7 +132,8 @@ class ReportController extends Controller
/**
* Shows income and expense, debit/credit: operations.
*
* */
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function operations(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
// chart properties for cache:
@ -150,11 +150,8 @@ class ReportController extends Controller
$titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$ids = $accounts->pluck('id')->toArray();
// get journals for entire period:
$data = [];
$chartData = [
];
$chartData = [];
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@ -186,18 +183,7 @@ class ReportController extends Controller
// deposit = incoming
// transfer or reconcile or opening balance, and these accounts are the destination.
if (
TransactionType::DEPOSIT === $journal['transaction_type_type']
|| (
(
TransactionType::TRANSFER === $journal['transaction_type_type']
|| TransactionType::RECONCILIATION === $journal['transaction_type_type']
|| TransactionType::OPENING_BALANCE === $journal['transaction_type_type']
)
&& in_array($journal['destination_account_id'], $ids, true)
)
) {
if (TransactionType::DEPOSIT === $journal['transaction_type_type'] || ((TransactionType::TRANSFER === $journal['transaction_type_type'] || TransactionType::RECONCILIATION === $journal['transaction_type_type'] || TransactionType::OPENING_BALANCE === $journal['transaction_type_type']) && in_array($journal['destination_account_id'], $ids, true))) {
$key = 'earned';
}
$data[$currencyId][$period][$key] = bcadd($data[$currencyId][$period][$key], $amount);

View File

@ -48,6 +48,8 @@ class BoxController extends Controller
* 0) If the user has available amount this period and has overspent: overspent box.
* 1) If the user has available amount this period and has NOT overspent: left to spend box.
* 2) if the user has no available amount set this period: spent per day
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function available(): JsonResponse
{

View File

@ -68,8 +68,6 @@ class PreferencesController extends Controller
{
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$isDocker = env('IS_DOCKER', false);
// group accounts
$groupedAccounts = [];
/** @var Account $account */
@ -141,27 +139,7 @@ class PreferencesController extends Controller
$slackUrl = '';
}
return view(
'preferences.index',
compact(
'language',
'groupedAccounts',
'isDocker',
'frontPageAccounts',
'languages',
'darkMode',
'availableDarkModes',
'notifications',
'slackUrl',
'locales',
'locale',
'tjOptionalFields',
'viewRange',
'customFiscalYear',
'listPageSize',
'fiscalYearStart'
)
);
return view('preferences.index', compact('language', 'groupedAccounts', 'isDocker', 'frontPageAccounts', 'languages', 'darkMode', 'availableDarkModes', 'notifications', 'slackUrl', 'locales', 'locale', 'tjOptionalFields', 'viewRange', 'customFiscalYear', 'listPageSize', 'fiscalYearStart'));
}
/**
@ -170,6 +148,8 @@ class PreferencesController extends Controller
* @return Redirector|RedirectResponse
*
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function postIndex(Request $request)
{

View File

@ -120,6 +120,8 @@ class CreateController extends Controller
/**
* @return Factory|\Illuminate\Contracts\View\View
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function createFromJournal(Request $request, TransactionJournal $journal)
{

View File

@ -155,6 +155,8 @@ class CategoryController extends Controller
/**
* @return Factory|View
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function accounts(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{
@ -355,6 +357,8 @@ class CategoryController extends Controller
/**
* @return Factory|View
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function categories(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{

View File

@ -41,11 +41,8 @@ class DoubleController extends Controller
{
use AugumentData;
/** @var AccountRepositoryInterface The account repository */
protected $accountRepository;
/** @var OperationsRepositoryInterface */
private $opsRepository;
protected AccountRepositoryInterface $accountRepository;
private OperationsRepositoryInterface $opsRepository;
/**
* Constructor for ExpenseController
@ -167,6 +164,8 @@ class DoubleController extends Controller
/**
* @return Factory|View
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function operations(Collection $accounts, Collection $double, Carbon $start, Carbon $end)
{

View File

@ -147,6 +147,8 @@ class TagController extends Controller
/**
* @return Factory|View
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function accounts(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{
@ -347,6 +349,8 @@ class TagController extends Controller
/**
* @return Factory|View
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function tags(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{

View File

@ -47,6 +47,8 @@ class RecurrenceFormRequest extends FormRequest
* Get the data required by the controller.
*
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getAll(): array
{

View File

@ -54,6 +54,8 @@ class BudgetServiceProvider extends ServiceProvider
/**
* Register the application services.
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function register(): void
{

View File

@ -181,7 +181,6 @@ class CreditRecalculateService
}
$startOfDebt = $this->repository->getOpeningBalanceAmount($account) ?? '0';
$leftOfDebt = app('steam')->positive($startOfDebt);
$currency = $this->repository->getAccountCurrency($account);
app('log')->debug(sprintf('Start of debt is "%s", so initial left of debt is "%s"', app('steam')->bcround($startOfDebt, 2), app('steam')->bcround($leftOfDebt, 2)));
/** @var AccountMetaFactory $factory */
@ -243,6 +242,9 @@ class CreditRecalculateService
app('log')->debug('Opening balance is valid');
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function processTransaction(Account $account, string $direction, Transaction $transaction, string $leftOfDebt): string
{
$journal = $transaction->transactionJournal;

View File

@ -44,6 +44,11 @@ class StandardWebhookSender implements WebhookSenderInterface
return $this->version;
}
/**
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function send(): void
{
// have the signature generator generate a signature. If it fails, the error thrown will

View File

@ -92,9 +92,6 @@ class Amount
return $user->currencies()->orderBy('code', 'ASC')->get();
}
/**
* @throws FireflyException
*/
public function getDefaultCurrency(): TransactionCurrency
{
/** @var User $user */

View File

@ -577,39 +577,12 @@ class ExportDataGenerator
$recurringRepos->setUser($this->user);
$header = [
// recurrence:
'user_id',
'recurrence_id',
'row_contains',
'created_at',
'updated_at',
'type',
'title',
'description',
'first_date',
'repeat_until',
'latest_date',
'repetitions',
'apply_rules',
'active',
'user_id', 'recurrence_id', 'row_contains', 'created_at', 'updated_at', 'type', 'title', 'description', 'first_date', 'repeat_until', 'latest_date', 'repetitions', 'apply_rules', 'active',
// repetition info:
'type',
'moment',
'skip',
'weekend',
'type', 'moment', 'skip', 'weekend',
// transactions + meta:
'currency_code',
'foreign_currency_code',
'source_name',
'source_type',
'destination_name',
'destination_type',
'amount',
'foreign_amount',
'category',
'budget',
'piggy_bank',
'tags',
'currency_code', 'foreign_currency_code', 'source_name', 'source_type', 'destination_name', 'destination_type', 'amount', 'foreign_amount', 'category', 'budget', 'piggy_bank', 'tags',
];
$records = [];
$recurrences = $recurringRepos->getAll();
@ -618,20 +591,9 @@ class ExportDataGenerator
foreach ($recurrences as $recurrence) {
// add recurrence:
$records[] = [
$this->user->id,
$recurrence->id,
$this->user->id, $recurrence->id,
'recurrence',
$recurrence->created_at->toAtomString(),
$recurrence->updated_at->toAtomString(),
$recurrence->transactionType->type,
$recurrence->title,
$recurrence->description,
$recurrence->first_date?->format('Y-m-d'),
$recurrence->repeat_until?->format('Y-m-d'),
$recurrence->latest_date?->format('Y-m-d'),
$recurrence->repetitions,
$recurrence->apply_rules,
$recurrence->active,
$recurrence->created_at->toAtomString(), $recurrence->updated_at->toAtomString(), $recurrence->transactionType->type, $recurrence->title, $recurrence->description, $recurrence->first_date?->format('Y-m-d'), $recurrence->repeat_until?->format('Y-m-d'), $recurrence->latest_date?->format('Y-m-d'), $recurrence->repetitions, $recurrence->apply_rules, $recurrence->active,
];
// add new row for each repetition
@ -642,23 +604,10 @@ class ExportDataGenerator
$this->user->id,
$recurrence->id,
'repetition',
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null, null, null, null, null, null, null, null, null, null, null,
// repetition:
$repetition->repetition_type,
$repetition->repetition_moment,
$repetition->repetition_skip,
$repetition->weekend,
$repetition->repetition_type, $repetition->repetition_moment, $repetition->repetition_skip, $repetition->weekend,
];
}
@ -674,37 +623,13 @@ class ExportDataGenerator
$this->user->id,
$recurrence->id,
'transaction',
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null, null, null, null, null, null, null, null, null, null, null,
// repetition:
null,
null,
null,
null,
null, null, null, null,
// transaction:
$transaction->transactionCurrency->code,
$transaction->foreignCurrency?->code,
$transaction->sourceAccount->name,
$transaction->sourceAccount->accountType->type,
$transaction->destinationAccount->name,
$transaction->destinationAccount->accountType->type,
$transaction->amount,
$transaction->foreign_amount,
$categoryName,
$budgetId,
$piggyBankId,
implode(',', $tags),
$transaction->transactionCurrency->code, $transaction->foreignCurrency?->code, $transaction->sourceAccount->name, $transaction->sourceAccount->accountType->type, $transaction->destinationAccount->name, $transaction->destinationAccount->accountType->type, $transaction->amount, $transaction->foreign_amount, $categoryName, $budgetId, $piggyBankId, implode(',', $tags),
];
}
}
@ -739,31 +664,7 @@ class ExportDataGenerator
*/
private function exportRules(): string
{
$header = [
'user_id',
'rule_id',
'row_contains',
'created_at',
'updated_at',
'group_id',
'group_name',
'title',
'description',
'order',
'active',
'stop_processing',
'strict',
'trigger_type',
'trigger_value',
'trigger_order',
'trigger_active',
'trigger_stop_processing',
'action_type',
'action_value',
'action_order',
'action_active',
'action_stop_processing',
];
$header = ['user_id', 'rule_id', 'row_contains', 'created_at', 'updated_at', 'group_id', 'title', 'description', 'order', 'active', 'stop_processing', 'strict', 'trigger_type', 'trigger_value', 'trigger_order', 'trigger_active', 'trigger_stop_processing', 'action_type', 'action_value', 'action_order', 'action_active', 'action_stop_processing'];
$ruleRepos = app(RuleRepositoryInterface::class);
$ruleRepos->setUser($this->user);
$rules = $ruleRepos->getAll();
@ -772,19 +673,9 @@ class ExportDataGenerator
/** @var Rule $rule */
foreach ($rules as $rule) {
$records[] = [
$this->user->id,
$rule->id,
$this->user->id, $rule->id,
'rule',
$rule->created_at->toAtomString(),
$rule->updated_at->toAtomString(),
$rule->ruleGroup->id,
$rule->ruleGroup->title,
$rule->title,
$rule->description,
$rule->order,
$rule->active,
$rule->stop_processing,
$rule->strict,
$rule->created_at->toAtomString(), $rule->updated_at->toAtomString(), $rule->ruleGroup->id, $rule->ruleGroup->title, $rule->title, $rule->description, $rule->order, $rule->active, $rule->stop_processing, $rule->strict,
];
/** @var RuleTrigger $trigger */
@ -793,21 +684,8 @@ class ExportDataGenerator
$this->user->id,
$rule->id,
'trigger',
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
$trigger->trigger_type,
$trigger->trigger_value,
$trigger->order,
$trigger->active,
$trigger->stop_processing,
null, null, null, null, null, null, null, null, null, null,
$trigger->trigger_type, $trigger->trigger_value, $trigger->order, $trigger->active, $trigger->stop_processing,
];
}
@ -817,26 +695,8 @@ class ExportDataGenerator
$this->user->id,
$rule->id,
'action',
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
$action->action_type,
$action->action_value,
$action->order,
$action->active,
$action->stop_processing,
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
$action->action_type, $action->action_value, $action->order, $action->active, $action->stop_processing,
];
}
}
@ -927,34 +787,7 @@ class ExportDataGenerator
private function exportTransactions(): string
{
// TODO better place for keys?
$header = [
'user_id',
'group_id',
'journal_id',
'created_at',
'updated_at',
'group_title',
'type',
'amount',
'foreign_amount',
'currency_code',
'foreign_currency_code',
'description',
'date',
'source_name',
'source_iban',
'source_type',
'destination_name',
'destination_iban',
'destination_type',
'reconciled',
'category',
'budget',
'bill',
'tags',
'notes',
// all optional meta fields:
];
$header = ['user_id', 'group_id', 'journal_id', 'created_at', 'updated_at', 'group_title', 'type', 'amount', 'foreign_amount', 'currency_code', 'foreign_currency_code', 'description', 'date', 'source_name', 'source_iban', 'source_type', 'destination_name', 'destination_iban', 'destination_type', 'reconciled', 'category', 'budget', 'bill', 'tags', 'notes'];
$metaFields = config('firefly.journal_meta_fields');
$header = array_merge($header, $metaFields);
@ -980,65 +813,21 @@ class ExportDataGenerator
foreach ($journals as $journal) {
$metaData = $repository->getMetaFields($journal['transaction_journal_id'], $metaFields);
$records[] = [
$journal['user_id'],
$journal['transaction_group_id'],
$journal['transaction_journal_id'],
$journal['created_at']->toAtomString(),
$journal['updated_at']->toAtomString(),
$journal['transaction_group_title'],
$journal['transaction_type_type'],
$journal['amount'],
$journal['foreign_amount'],
$journal['currency_code'],
$journal['foreign_currency_code'],
$journal['description'],
$journal['date']->toAtomString(),
$journal['source_account_name'],
$journal['source_account_iban'],
$journal['source_account_type'],
$journal['destination_account_name'],
$journal['destination_account_iban'],
$journal['destination_account_type'],
$journal['reconciled'],
$journal['category_name'],
$journal['budget_name'],
$journal['bill_name'],
$journal['user_id'], $journal['transaction_group_id'], $journal['transaction_journal_id'], $journal['created_at']->toAtomString(), $journal['updated_at']->toAtomString(), $journal['transaction_group_title'], $journal['transaction_type_type'], $journal['amount'], $journal['foreign_amount'], $journal['currency_code'], $journal['foreign_currency_code'], $journal['description'], $journal['date']->toAtomString(), $journal['source_account_name'], $journal['source_account_iban'], $journal['source_account_type'], $journal['destination_account_name'], $journal['destination_account_iban'], $journal['destination_account_type'], $journal['reconciled'], $journal['category_name'], $journal['budget_name'], $journal['bill_name'],
$this->mergeTags($journal['tags']),
$this->clearStringKeepNewlines($journal['notes']),
// export also the optional fields (ALL)
// sepa
$metaData['sepa_cc'],
$metaData['sepa_ct_op'],
$metaData['sepa_ct_id'],
$metaData['sepa_db'],
$metaData['sepa_country'],
$metaData['sepa_ep'],
$metaData['sepa_ci'],
$metaData['sepa_batch_id'],
$metaData['external_url'],
$metaData['sepa_cc'], $metaData['sepa_ct_op'], $metaData['sepa_ct_id'], $metaData['sepa_db'], $metaData['sepa_country'], $metaData['sepa_ep'], $metaData['sepa_ci'], $metaData['sepa_batch_id'], $metaData['external_url'],
// dates
$metaData['interest_date'],
$metaData['book_date'],
$metaData['process_date'],
$metaData['due_date'],
$metaData['payment_date'],
$metaData['invoice_date'],
$metaData['interest_date'], $metaData['book_date'], $metaData['process_date'], $metaData['due_date'], $metaData['payment_date'], $metaData['invoice_date'],
// others
$metaData['recurrence_id'],
$metaData['internal_reference'],
$metaData['bunq_payment_id'],
$metaData['import_hash'],
$metaData['import_hash_v2'],
$metaData['external_id'],
$metaData['original_source'],
$metaData['recurrence_id'], $metaData['internal_reference'], $metaData['bunq_payment_id'], $metaData['import_hash'], $metaData['import_hash_v2'], $metaData['external_id'], $metaData['original_source'],
// recurring transactions
$metaData['recurrence_total'],
$metaData['recurrence_count'],
$metaData['recurrence_total'], $metaData['recurrence_count'],
];
}

View File

@ -156,6 +156,8 @@ trait ModelInformation
/**
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function getTriggersForJournal(TransactionJournal $journal): array
{

View File

@ -215,6 +215,8 @@ class Steam
/**
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function balanceInRangeConverted(Account $account, Carbon $start, Carbon $end, TransactionCurrency $native): array
{
@ -317,22 +319,36 @@ class Steam
}
/**
* selection of transactions
* 1: all normal transactions. No foreign currency info. In $currency. Need conversion.
* 2: all normal transactions. No foreign currency info. In $native. Need NO conversion.
* 3: all normal transactions. No foreign currency info. In neither currency. Need conversion.
* Then, select everything with foreign currency info:
* 4. All transactions with foreign currency info in $native. Normal currency value is ignored. Do not need
* conversion.
* 5. All transactions with foreign currency info NOT in $native, but currency info in $currency. Need conversion.
* 6. All transactions with foreign currency info NOT in $native, and currency info NOT in $currency. Need
* conversion.
*
* Gets balance at the end of current month by default. Returns the balance converted
* to the indicated currency ($native).
*
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function balanceConverted(Account $account, Carbon $date, TransactionCurrency $native): string
{
// app('log')->debug(sprintf('Now in balanceConverted (%s) for account #%d, converting to %s', $date->format('Y-m-d'), $account->id, $native->code));
app('log')->debug(sprintf('Now in balanceConverted (%s) for account #%d, converting to %s', $date->format('Y-m-d'), $account->id, $native->code));
$cache = new CacheProperties();
$cache->addProperty($account->id);
$cache->addProperty('balance');
$cache->addProperty($date);
$cache->addProperty($native->id);
if ($cache->has()) {
// Log::debug('Cached!');
// return $cache->get();
Log::debug('Cached!');
return $cache->get();
}
/** @var AccountRepositoryInterface $repository */
@ -344,20 +360,9 @@ class Steam
return $this->balance($account, $date);
}
/**
* selection of transactions
* 1: all normal transactions. No foreign currency info. In $currency. Need conversion.
* 2: all normal transactions. No foreign currency info. In $native. Need NO conversion.
* 3: all normal transactions. No foreign currency info. In neither currency. Need conversion.
* Then, select everything with foreign currency info:
* 4. All transactions with foreign currency info in $native. Normal currency value is ignored. Do not need conversion.
* 5. All transactions with foreign currency info NOT in $native, but currency info in $currency. Need conversion.
* 6. All transactions with foreign currency info NOT in $native, and currency info NOT in $currency. Need conversion.
*/
$new = [];
$existing = [];
// 1
$new[] = $account->transactions()
$new[] = $account->transactions() // 1
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $currency->id)
@ -365,8 +370,7 @@ class Steam
->get(['transaction_journals.date', 'transactions.amount'])->toArray()
;
app('log')->debug(sprintf('%d transaction(s) in set #1', count($new[0])));
// 2
$existing[] = $account->transactions()
$existing[] = $account->transactions() // 2
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $native->id)
@ -374,8 +378,7 @@ class Steam
->get(['transactions.amount'])->toArray()
;
app('log')->debug(sprintf('%d transaction(s) in set #2', count($existing[0])));
// 3
$new[] = $account->transactions()
$new[] = $account->transactions() // 3
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', '!=', $currency->id)
@ -384,8 +387,7 @@ class Steam
->get(['transaction_journals.date', 'transactions.amount'])->toArray()
;
app('log')->debug(sprintf('%d transactions in set #3', count($new[1])));
// 4
$existing[] = $account->transactions()
$existing[] = $account->transactions() // 4
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.foreign_currency_id', $native->id)
@ -393,8 +395,7 @@ class Steam
->get(['transactions.foreign_amount'])->toArray()
;
app('log')->debug(sprintf('%d transactions in set #4', count($existing[1])));
// 5
$new[] = $account->transactions()
$new[] = $account->transactions()// 5
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $currency->id)
@ -403,8 +404,7 @@ class Steam
->get(['transaction_journals.date', 'transactions.amount'])->toArray()
;
app('log')->debug(sprintf('%d transactions in set #5', count($new[2])));
// 6
$new[] = $account->transactions()
$new[] = $account->transactions()// 6
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', '!=', $currency->id)

View File

@ -49,6 +49,9 @@ class ConvertToTransfer implements ActionInterface
$this->action = $action;
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function actOnArray(array $journal): bool
{
// make object from array (so the data is fresh).

View File

@ -51,24 +51,23 @@ class BillTransformer extends AbstractTransformer
/**
* Transform the bill.
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function transform(Bill $bill): array
{
$paidData = $this->paidData($bill);
$lastPaidDate = $this->getLastPaidDate($paidData);
// both params can be NULL, so just in case they are, add some wide margins:
$start = $this->parameters->get('start') ?? today()->subYears(10);
$end = $this->parameters->get('end') ?? today()->addYears(10);
$payDates = $this->calculator->getPayDates($start, $end, $bill->date, $bill->repeat_freq, $bill->skip, $lastPaidDate);
$currency = $bill->transactionCurrency;
$notes = $this->repository->getNoteText($bill);
$notes = '' === $notes ? null : $notes;
$this->repository->setUser($bill->user);
$objectGroupId = null;
$objectGroupOrder = null;
$objectGroupTitle = null;
$this->repository->setUser($bill->user);
/** @var null|ObjectGroup $objectGroup */
$objectGroup = $bill->objectGroups->first();

View File

@ -138,6 +138,9 @@ class TransactionGroupTransformer extends AbstractTransformer
return $result;
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function transformTransaction(array $transaction): array
{
$row = new NullArrayObject($transaction);
@ -317,6 +320,8 @@ class TransactionGroupTransformer extends AbstractTransformer
/**
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function transformJournal(TransactionJournal $journal): array
{

View File

@ -47,6 +47,11 @@ class BillTransformer extends AbstractTransformer
private array $notes;
private array $paidDates;
/**
* @throws \FireflyIII\Exceptions\FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function collectMetaData(Collection $objects): void
{
$currencies = [];
@ -55,7 +60,6 @@ class BillTransformer extends AbstractTransformer
$this->groups = [];
$this->paidDates = [];
// start with currencies:
/** @var Bill $object */
foreach ($objects as $object) {
$id = $object->transaction_currency_id;
@ -63,8 +67,6 @@ class BillTransformer extends AbstractTransformer
$currencies[$id] ??= TransactionCurrency::find($id);
}
$this->currencies = $currencies;
// continue with notes
$notes = Note::whereNoteableType(Bill::class)->whereIn('noteable_id', array_keys($bills))->get();
/** @var Note $note */
@ -107,7 +109,6 @@ class BillTransformer extends AbstractTransformer
->where('transactions.amount', '<', 0)
->get(['transactions.id', 'transactions.transaction_journal_id', 'transactions.amount', 'transactions.foreign_amount', 'transactions.transaction_currency_id', 'transactions.foreign_currency_id'])
;
// convert to array for easy finding:
$transactions = [];
/** @var Transaction $transaction */

View File

@ -140,6 +140,8 @@ class TransactionGroupTransformer extends AbstractTransformer
/**
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function transformTransaction(array $transaction): array
{

View File

@ -115,6 +115,7 @@ class FireflyValidator extends Validator
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function validateIban(mixed $attribute, mixed $value): bool
{

View File

@ -386,6 +386,9 @@ class CreateMainTables extends Migration
}
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function createRuleTables(): void
{
if (!Schema::hasTable('rule_groups')) {

View File

@ -107,6 +107,7 @@ class UserGroups extends Migration
* Run the migrations.
*
* @SuppressWarnings(PHPMD.ShortMethodName)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function up(): void
{