Various code cleanup.

This commit is contained in:
James Cole 2023-12-01 05:15:59 +01:00
parent 271e4271eb
commit 5883dfbed8
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
13 changed files with 208 additions and 101 deletions

View File

@ -27,12 +27,12 @@
<description>Firefly III ruleset.</description>
<!-- Import the entire controversial code rule set -->
<rule ref="rulesets/controversial.xml">
<exclude name="CamelCasePropertyName" />
<exclude name="CamelCasePropertyName"/>
</rule>
<!-- clean code -->
<!-- <rule ref="rulesets/codesize.xml" /> -->
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/unusedcode.xml"/>
<rule ref="rulesets/design.xml/NumberOfChildren">
@ -49,11 +49,9 @@
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName">
<properties>
<!-- TODO we want to be at minimum 3. But we start low, and raise the bar slowly. -->
<property name="minimum" value="1"/>
<property name="minimum" value="3"/>
</properties>
</rule>
@ -73,22 +71,22 @@
<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="2000"/>
<property name="minimum" value="1000"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList">
<properties>
<!-- TODO we want to be at a value of 4. But we start high, and drop the bar slowly. -->
<property name="minimum" value="12"/>
<!-- 5 is fine. 6 is excessive, but I have just one of those. At the end of the day, I still need all params. -->
<property name="minimum" value="5"/>
</properties>
</rule>
<!-- include clean code manually -->
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag" />
<rule ref="rulesets/cleancode.xml/ElseExpression" />
<rule ref="rulesets/cleancode.xml/MissingImport" />
<rule ref="rulesets/cleancode.xml/UndefinedVariable" />
<rule ref="rulesets/cleancode.xml/IfStatementAssignment" />
<rule ref="rulesets/cleancode.xml/DuplicatedArrayKey" />
<rule ref="rulesets/cleancode.xml/ErrorControlOperator" />
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
<rule ref="rulesets/cleancode.xml/ElseExpression"/>
<rule ref="rulesets/cleancode.xml/MissingImport"/>
<rule ref="rulesets/cleancode.xml/UndefinedVariable"/>
<rule ref="rulesets/cleancode.xml/IfStatementAssignment"/>
<rule ref="rulesets/cleancode.xml/DuplicatedArrayKey"/>
<rule ref="rulesets/cleancode.xml/ErrorControlOperator"/>
</ruleset>

View File

@ -0,0 +1,32 @@
<?php
/*
* SearchDirection.php
* Copyright (c) 2023 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Enums;
enum SearchDirection: int
{
case SOURCE = 1;
case DESTINATION = 2;
case BOTH = 3;
}

View File

@ -0,0 +1,37 @@
<?php
/*
* StringPosition.php
* Copyright (c) 2023 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Enums;
/**
* Class StringPosition
*
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
*/
enum StringPosition: int
{
case STARTS = 1;
case ENDS = 2;
case CONTAINS = 3;
case IS = 4;
}

View File

@ -429,6 +429,9 @@ class BudgetController extends Controller
/**
* Shows a budget overview chart (spent and budgeted).
*
* Suppress warning because this method will be replaced by API calls.
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
* @param Budget $budget
* @param TransactionCurrency $currency
* @param Collection $accounts

View File

@ -151,6 +151,7 @@ class OperationsRepository implements OperationsRepositoryInterface
/**
* @inheritDoc
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumExpenses(
Carbon $start,
@ -158,7 +159,8 @@ class OperationsRepository implements OperationsRepositoryInterface
?Collection $accounts = null,
?Collection $expense = null,
?TransactionCurrency $currency = null
): array {
): array
{
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
return $this->groupByCurrency($journals, 'negative');
@ -173,6 +175,7 @@ class OperationsRepository implements OperationsRepositoryInterface
* @param string $type
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
private function getTransactionsForSum(
string $type,
@ -181,7 +184,8 @@ class OperationsRepository implements OperationsRepositoryInterface
?Collection $accounts = null,
?Collection $opposing = null,
?TransactionCurrency $currency = null
): array {
): array
{
$start->startOfDay();
$end->endOfDay();
@ -268,7 +272,8 @@ class OperationsRepository implements OperationsRepositoryInterface
'currency_code' => $journal['currency_code'],
'currency_decimal_places' => $journal['currency_decimal_places'],
];
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->$direction($journal['amount']));/** @phpstan-ignore-line */
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->$direction($journal['amount']));
/** @phpstan-ignore-line */
// also do foreign amount:
$foreignId = (int)$journal['foreign_currency_id'];
@ -290,6 +295,7 @@ class OperationsRepository implements OperationsRepositoryInterface
/**
* @inheritDoc
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumExpensesByDestination(
Carbon $start,
@ -297,7 +303,8 @@ class OperationsRepository implements OperationsRepositoryInterface
?Collection $accounts = null,
?Collection $expense = null,
?TransactionCurrency $currency = null
): array {
): array
{
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
return $this->groupByDirection($journals, 'destination', 'negative');
@ -352,6 +359,7 @@ class OperationsRepository implements OperationsRepositoryInterface
/**
* @inheritDoc
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumExpensesBySource(
Carbon $start,
@ -359,7 +367,8 @@ class OperationsRepository implements OperationsRepositoryInterface
?Collection $accounts = null,
?Collection $expense = null,
?TransactionCurrency $currency = null
): array {
): array
{
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
return $this->groupByDirection($journals, 'source', 'negative');
@ -367,6 +376,7 @@ class OperationsRepository implements OperationsRepositoryInterface
/**
* @inheritDoc
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumIncome(
Carbon $start,
@ -374,7 +384,8 @@ class OperationsRepository implements OperationsRepositoryInterface
?Collection $accounts = null,
?Collection $revenue = null,
?TransactionCurrency $currency = null
): array {
): array
{
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
return $this->groupByCurrency($journals, 'positive');
@ -382,6 +393,7 @@ class OperationsRepository implements OperationsRepositoryInterface
/**
* @inheritDoc
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumIncomeByDestination(
Carbon $start,
@ -389,7 +401,8 @@ class OperationsRepository implements OperationsRepositoryInterface
?Collection $accounts = null,
?Collection $revenue = null,
?TransactionCurrency $currency = null
): array {
): array
{
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
return $this->groupByDirection($journals, 'destination', 'positive');
@ -397,6 +410,7 @@ class OperationsRepository implements OperationsRepositoryInterface
/**
* @inheritDoc
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumIncomeBySource(
Carbon $start,
@ -404,7 +418,8 @@ class OperationsRepository implements OperationsRepositoryInterface
?Collection $accounts = null,
?Collection $revenue = null,
?TransactionCurrency $currency = null
): array {
): array
{
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
return $this->groupByDirection($journals, 'source', 'positive');

View File

@ -75,6 +75,7 @@ interface OperationsRepositoryInterface
* @param TransactionCurrency|null $currency
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumExpenses(
Carbon $start,
@ -95,6 +96,7 @@ interface OperationsRepositoryInterface
* @param TransactionCurrency|null $currency
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumExpensesByDestination(
Carbon $start,
@ -115,6 +117,7 @@ interface OperationsRepositoryInterface
* @param TransactionCurrency|null $currency
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumExpensesBySource(
Carbon $start,
@ -134,6 +137,7 @@ interface OperationsRepositoryInterface
* @param TransactionCurrency|null $currency
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumIncome(
Carbon $start,
@ -154,6 +158,7 @@ interface OperationsRepositoryInterface
* @param TransactionCurrency|null $currency
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumIncomeByDestination(
Carbon $start,
@ -174,6 +179,7 @@ interface OperationsRepositoryInterface
* @param TransactionCurrency|null $currency
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumIncomeBySource(
Carbon $start,

View File

@ -228,6 +228,7 @@ class OperationsRepository implements OperationsRepositoryInterface
* @param TransactionCurrency|null $currency
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumExpenses(
Carbon $start,
@ -235,7 +236,8 @@ class OperationsRepository implements OperationsRepositoryInterface
?Collection $accounts = null,
?Collection $budgets = null,
?TransactionCurrency $currency = null
): array {
): array
{
//app('log')->debug(sprintf('Now in %s', __METHOD__));
$start->startOfDay();
$end->endOfDay();

View File

@ -81,8 +81,9 @@ interface OperationsRepositoryInterface
* @param Collection|null $accounts
* @param Collection|null $budgets
* @param TransactionCurrency|null $currency
* @return array
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function sumExpenses(
Carbon $start,

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Support\Models;
use Carbon\Carbon;
use FireflyIII\Models\Bill;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
@ -36,9 +35,12 @@ class BillDateCalculator
* @param Carbon $earliest
* @param Carbon $latest
* @param Carbon $billStart
* @param string $period
* @param int $skip
* @param Carbon|null $lastPaid
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function getPayDates(Carbon $earliest, Carbon $latest, Carbon $billStart, string $period, int $skip, ?Carbon $lastPaid): array
{

View File

@ -72,6 +72,7 @@ trait CalculateXOccurrencesSince
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function getXMonthlyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
{
@ -115,6 +116,7 @@ trait CalculateXOccurrencesSince
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function getXNDomOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
{
@ -155,6 +157,7 @@ trait CalculateXOccurrencesSince
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function getXWeeklyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
{
@ -200,6 +203,7 @@ trait CalculateXOccurrencesSince
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function getXYearlyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
{

View File

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Support\Search;
use Carbon\Carbon;
use FireflyIII\Enums\SearchDirection;
use FireflyIII\Enums\StringPosition;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Account;
@ -55,6 +57,7 @@ use Gdbots\QueryParser\QueryParser;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use LogicException;
use PragmaRX\Random\Generators\StringGenerator;
use TypeError;
/**
@ -247,6 +250,7 @@ class OperatorQuerySearch implements SearchInterface
/**
*
* @throws FireflyException
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function updateCollector(string $operator, string $value, bool $prohibited): bool
{
@ -273,100 +277,100 @@ class OperatorQuerySearch implements SearchInterface
// all account related searches:
//
case 'account_is':
$this->searchAccount($value, 3, 4);
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::IS);
break;
case '-account_is':
$this->searchAccount($value, 3, 4, true);
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::IS, true);
break;
case 'account_contains':
$this->searchAccount($value, 3, 3);
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::CONTAINS);
break;
case '-account_contains':
$this->searchAccount($value, 3, 3, true);
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::CONTAINS, true);
break;
case 'account_ends':
$this->searchAccount($value, 3, 2);
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::ENDS);
break;
case '-account_ends':
$this->searchAccount($value, 3, 2, true);
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::ENDS, true);
break;
case 'account_starts':
$this->searchAccount($value, 3, 1);
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::STARTS);
break;
case '-account_starts':
$this->searchAccount($value, 3, 1, true);
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::STARTS, true);
break;
case 'account_nr_is':
$this->searchAccountNr($value, 3, 4);
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::IS);
break;
case '-account_nr_is':
$this->searchAccountNr($value, 3, 4, true);
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::IS, true);
break;
case 'account_nr_contains':
$this->searchAccountNr($value, 3, 3);
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::CONTAINS);
break;
case '-account_nr_contains':
$this->searchAccountNr($value, 3, 3, true);
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::CONTAINS, true);
break;
case 'account_nr_ends':
$this->searchAccountNr($value, 3, 2);
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::ENDS);
break;
case '-account_nr_ends':
$this->searchAccountNr($value, 3, 2, true);
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::ENDS, true);
break;
case 'account_nr_starts':
$this->searchAccountNr($value, 3, 1);
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::STARTS);
break;
case '-account_nr_starts':
$this->searchAccountNr($value, 3, 1, true);
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::STARTS, true);
break;
case 'source_account_starts':
$this->searchAccount($value, 1, 1);
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::STARTS);
break;
case '-source_account_starts':
$this->searchAccount($value, 1, 1, true);
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::STARTS, true);
break;
case 'source_account_ends':
$this->searchAccount($value, 1, 2);
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::ENDS);
break;
case '-source_account_ends':
$this->searchAccount($value, 1, 2, true);
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::ENDS, true);
break;
case 'source_account_is':
$this->searchAccount($value, 1, 4);
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::IS);
break;
case '-source_account_is':
$this->searchAccount($value, 1, 4, true);
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::IS, true);
break;
case 'source_account_nr_starts':
$this->searchAccountNr($value, 1, 1);
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::STARTS);
break;
case '-source_account_nr_starts':
$this->searchAccountNr($value, 1, 1, true);
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::STARTS, true);
break;
case 'source_account_nr_ends':
$this->searchAccountNr($value, 1, 2);
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::ENDS);
break;
case '-source_account_nr_ends':
$this->searchAccountNr($value, 1, 2, true);
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::ENDS, true);
break;
case 'source_account_nr_is':
$this->searchAccountNr($value, 1, 4);
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::IS);
break;
case '-source_account_nr_is':
$this->searchAccountNr($value, 1, 4, true);
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::IS, true);
break;
case 'source_account_nr_contains':
$this->searchAccountNr($value, 1, 3);
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::CONTAINS);
break;
case '-source_account_nr_contains':
$this->searchAccountNr($value, 1, 3, true);
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::CONTAINS, true);
break;
case 'source_account_contains':
$this->searchAccount($value, 1, 3);
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::CONTAINS);
break;
case '-source_account_contains':
$this->searchAccount($value, 1, 3, true);
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::CONTAINS, true);
break;
case 'source_account_id':
$account = $this->accountRepository->find((int)$value);
@ -405,52 +409,52 @@ class OperatorQuerySearch implements SearchInterface
$this->collector->excludeIds($parts);
break;
case 'destination_account_starts':
$this->searchAccount($value, 2, 1);
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::STARTS);
break;
case '-destination_account_starts':
$this->searchAccount($value, 2, 1, true);
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::STARTS, true);
break;
case 'destination_account_ends':
$this->searchAccount($value, 2, 2);
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::ENDS);
break;
case '-destination_account_ends':
$this->searchAccount($value, 2, 2, true);
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::ENDS, true);
break;
case 'destination_account_nr_starts':
$this->searchAccountNr($value, 2, 1);
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::STARTS);
break;
case '-destination_account_nr_starts':
$this->searchAccountNr($value, 2, 1, true);
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::STARTS, true);
break;
case 'destination_account_nr_ends':
$this->searchAccountNr($value, 2, 2);
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::ENDS);
break;
case '-destination_account_nr_ends':
$this->searchAccountNr($value, 2, 2, true);
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::ENDS, true);
break;
case 'destination_account_nr_is':
$this->searchAccountNr($value, 2, 4);
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::IS);
break;
case '-destination_account_nr_is':
$this->searchAccountNr($value, 2, 4, true);
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::IS, true);
break;
case 'destination_account_is':
$this->searchAccount($value, 2, 4);
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::IS);
break;
case '-destination_account_is':
$this->searchAccount($value, 2, 4, true);
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::IS, true);
break;
case 'destination_account_nr_contains':
$this->searchAccountNr($value, 2, 3);
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::CONTAINS);
break;
case '-destination_account_nr_contains':
$this->searchAccountNr($value, 2, 3, true);
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::CONTAINS, true);
break;
case 'destination_account_contains':
$this->searchAccount($value, 2, 3);
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::CONTAINS);
break;
case '-destination_account_contains':
$this->searchAccount($value, 2, 3, true);
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::CONTAINS, true);
break;
case 'destination_account_id':
$account = $this->accountRepository->find((int)$value);
@ -1359,13 +1363,13 @@ class OperatorQuerySearch implements SearchInterface
* searchDirection: 1 = source (default), 2 = destination, 3 = both
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
*
* @param string $value
* @param int $searchDirection
* @param int $stringPosition
* @param bool $prohibited
* @param string $value
* @param SearchDirection $searchDirection
* @param StringPosition $stringPosition
* @param bool $prohibited
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function searchAccount(string $value, int $searchDirection, int $stringPosition, bool $prohibited = false): void
private function searchAccount(string $value, SearchDirection $searchDirection, StringPosition $stringPosition, bool $prohibited = false): void
{
app('log')->debug(sprintf('searchAccount("%s", %d, %d)', $value, $stringPosition, $searchDirection));
@ -1377,7 +1381,7 @@ class OperatorQuerySearch implements SearchInterface
}
// search direction: for destination accounts
if (2 === $searchDirection) {
if (SearchDirection::DESTINATION === $searchDirection) { // destination
// destination can be
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE];
$collectorMethod = 'setDestinationAccounts';
@ -1386,7 +1390,7 @@ class OperatorQuerySearch implements SearchInterface
}
}
// either account could be:
if (3 === $searchDirection) {
if (SearchDirection::BOTH === $searchDirection) {
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE, AccountType::REVENUE];
$collectorMethod = 'setAccounts';
if ($prohibited) {
@ -1397,13 +1401,13 @@ class OperatorQuerySearch implements SearchInterface
$stringMethod = 'str_starts_with';
// string position: ends with:
if (2 === $stringPosition) {
if (StringPosition::ENDS === $stringPosition) {
$stringMethod = 'str_ends_with';
}
if (3 === $stringPosition) {
if (StringPosition::CONTAINS === $stringPosition) {
$stringMethod = 'str_contains';
}
if (4 === $stringPosition) {
if (StringPosition::IS === $stringPosition) {
$stringMethod = 'stringIsEqual';
}
@ -1437,13 +1441,13 @@ class OperatorQuerySearch implements SearchInterface
* searchDirection: 1 = source (default), 2 = destination, 3 = both
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
*
* @param string $value
* @param int $searchDirection
* @param int $stringPosition
* @param bool $prohibited
* @param string $value
* @param SearchDirection $searchDirection
* @param StringPosition $stringPosition
* @param bool $prohibited
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function searchAccountNr(string $value, int $searchDirection, int $stringPosition, bool $prohibited = false): void
private function searchAccountNr(string $value, SearchDirection $searchDirection, StringPosition $stringPosition, bool $prohibited = false): void
{
app('log')->debug(sprintf('searchAccountNr(%s, %d, %d)', $value, $searchDirection, $stringPosition));
@ -1455,7 +1459,7 @@ class OperatorQuerySearch implements SearchInterface
}
// search direction: for destination accounts
if (2 === $searchDirection) {
if (SearchDirection::DESTINATION === $searchDirection) {
// destination can be
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE];
$collectorMethod = 'setDestinationAccounts';
@ -1465,7 +1469,7 @@ class OperatorQuerySearch implements SearchInterface
}
// either account could be:
if (3 === $searchDirection) {
if (SearchDirection::BOTH === $searchDirection) {
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE, AccountType::REVENUE];
$collectorMethod = 'setAccounts';
if (true === $prohibited) {
@ -1477,13 +1481,13 @@ class OperatorQuerySearch implements SearchInterface
$stringMethod = 'str_starts_with';
// string position: ends with:
if (2 === $stringPosition) {
if (StringPosition::ENDS === $stringPosition) {
$stringMethod = 'str_ends_with';
}
if (3 === $stringPosition) {
if (StringPosition::CONTAINS === $stringPosition) {
$stringMethod = 'str_contains';
}
if (4 === $stringPosition) {
if (StringPosition::IS === $stringPosition) {
$stringMethod = 'stringIsEqual';
}

View File

@ -61,8 +61,8 @@ trait TransactionValidation
app('log')->debug(sprintf('Going to loop %d transaction(s)', count($transactions)));
/**
* @var int|null $index
* @var array $transaction
* @var int|null $index
* @var array $transaction
*/
foreach ($transactions as $index => $transaction) {
$transaction['user'] = $user;
@ -169,6 +169,7 @@ trait TransactionValidation
* @param array $destination
*
* @return void
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function sanityCheckReconciliation(Validator $validator, string $transactionType, int $index, array $source, array $destination): void
{
@ -204,6 +205,7 @@ trait TransactionValidation
* @param int $index
*
* @return void
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
private function sanityCheckForeignCurrency(
Validator $validator,
@ -211,7 +213,8 @@ trait TransactionValidation
array $transaction,
string $transactionType,
int $index
): void {
): void
{
app('log')->debug('Now in sanityCheckForeignCurrency()');
if (0 !== $validator->errors()->count()) {
app('log')->debug('Already have errors, return');
@ -377,8 +380,8 @@ trait TransactionValidation
$transactions = $this->getTransactionsArray($validator);
/**
* @var int|null $index
* @var array $transaction
* @var int|null $index
* @var array $transaction
*/
foreach ($transactions as $index => $transaction) {
if (!is_int($index)) {
@ -488,7 +491,7 @@ trait TransactionValidation
*/
private function getTransactionType(TransactionGroup $group, array $transactions): string
{
return $transactions[0]['type'] ?? strtolower((string) $group->transactionJournals()->first()?->transactionType->type);
return $transactions[0]['type'] ?? strtolower((string)$group->transactionJournals()->first()?->transactionType->type);
}
/**

View File

@ -28,7 +28,6 @@ use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Collection;
/**
* Class ExchangeRateSeeder
@ -109,6 +108,7 @@ class ExchangeRateSeeder extends Seeder
* @param float $rate
*
* @return void
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
private function addRate(User $user, TransactionCurrency $from, TransactionCurrency $to, string $date, float $rate): void
{