mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Various code cleanup.
This commit is contained in:
@@ -44,8 +44,7 @@ EXIT_CODE=$?
|
||||
|
||||
cd $SCRIPT_DIR/..
|
||||
|
||||
echo "Exit code is $EXIT_CODE, but we ignore this for the time being."
|
||||
echo "Exit code is $EXIT_CODE."
|
||||
|
||||
# for the time being, exit 0
|
||||
#exit $EXIT_CODE
|
||||
exit 0
|
||||
exit $EXIT_CODE
|
||||
|
@@ -37,14 +37,14 @@
|
||||
|
||||
<rule ref="rulesets/design.xml/NumberOfChildren">
|
||||
<properties>
|
||||
<!-- TODO we want to be at minimum 15. But we start high, and drop the bar slowly. -->
|
||||
<property name="minimum" value="256"/>
|
||||
<!-- This is now at 32, which excludes the controllers but should prevent more monoliths. -->
|
||||
<property name="minimum" value="32"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
|
||||
<properties>
|
||||
<!-- TODO we want to be at maximum 13. But we start high, and drop the bar slowly. -->
|
||||
<property name="maximum" value="256"/>
|
||||
<!-- Leaving this at 28 excuses most current code but it can't get worse than that. -->
|
||||
<property name="maximum" value="28"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
@@ -58,14 +58,15 @@
|
||||
<!-- code size -->
|
||||
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
|
||||
<properties>
|
||||
<!-- TODO we want to be at report level 5. But we start high, and drop the bar slowly. -->
|
||||
<property name="reportLevel" value="500"/>
|
||||
<!-- Leave at 20. This means methods will be pretty complex before the system starts complaining. -->
|
||||
<property name="reportLevel" value="20"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/codesize.xml/NPathComplexity">
|
||||
<properties>
|
||||
<!-- TODO we want to be at a value of 128. But we start high, and drop the bar slowly. -->
|
||||
<property name="minimum" value="24062500"/>
|
||||
<!-- 2000 results in some pretty complex methods, but it's OK. -->
|
||||
<!-- They should not be much more complex than that though -->
|
||||
<property name="minimum" value="2000"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
|
||||
|
@@ -40,6 +40,9 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
* Class Controller.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.NumberOfChildren)
|
||||
*/
|
||||
abstract class Controller extends BaseController
|
||||
{
|
||||
|
@@ -71,7 +71,7 @@ class ShowController extends Controller
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$pageSize = $this->parameters->get('limit');
|
||||
@@ -101,7 +101,7 @@ class ShowController extends Controller
|
||||
* Show a currency.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function show(TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
/** @var User $user */
|
||||
@@ -129,7 +129,7 @@ class ShowController extends Controller
|
||||
* Show a currency.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function showDefault(): JsonResponse
|
||||
{
|
||||
/** @var User $user */
|
||||
|
@@ -68,7 +68,7 @@ class StoreController extends Controller
|
||||
* Store new currency.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function store(StoreRequest $request): JsonResponse
|
||||
{
|
||||
$currency = $this->repository->store($request->getAll());
|
||||
|
@@ -69,7 +69,7 @@ class UpdateController extends Controller
|
||||
* Disable a currency.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function disable(TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
// must be unused.
|
||||
@@ -133,7 +133,7 @@ class UpdateController extends Controller
|
||||
* Enable a currency.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function enable(TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
$this->repository->enable($currency);
|
||||
@@ -160,7 +160,7 @@ class UpdateController extends Controller
|
||||
* Update a currency.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function update(UpdateRequest $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
$data = $request->getAll();
|
||||
|
@@ -45,6 +45,9 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
* Class Controller
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.NumberOfChildren)
|
||||
*/
|
||||
class Controller extends BaseController
|
||||
{
|
||||
@@ -104,6 +107,8 @@ class Controller extends BaseController
|
||||
/**
|
||||
* TODO duplicate from V1 controller
|
||||
* Method to grab all parameters from the URL.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
private function getParameters(): ParameterBag
|
||||
{
|
||||
|
@@ -45,6 +45,8 @@ class GracefulNotFoundHandler extends ExceptionHandler
|
||||
* @param Request $request
|
||||
*
|
||||
* @throws \Throwable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function render($request, \Throwable $e): Response
|
||||
{
|
||||
|
@@ -65,11 +65,15 @@ class Handler extends ExceptionHandler
|
||||
];
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
* Render an exception into an HTTP response. It's complex but lucky for us, we never use it because
|
||||
* Firefly III never crashes.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @throws \Throwable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function render($request, \Throwable $e): Response
|
||||
{
|
||||
@@ -124,7 +128,7 @@ class Handler extends ExceptionHandler
|
||||
$errorCode = 500;
|
||||
$errorCode = $e instanceof MethodNotAllowedHttpException ? 405 : $errorCode;
|
||||
|
||||
$isDebug = (bool)config('app.debug', false);
|
||||
$isDebug = (bool) config('app.debug', false);
|
||||
if ($isDebug) {
|
||||
app('log')->debug(sprintf('Return JSON %s with debug.', get_class($e)));
|
||||
|
||||
@@ -181,7 +185,7 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function report(\Throwable $e): void
|
||||
{
|
||||
$doMailError = (bool)config('firefly.send_error_message');
|
||||
$doMailError = (bool) config('firefly.send_error_message');
|
||||
if ($this->shouldntReportLocal($e) || !$doMailError) {
|
||||
parent::report($e);
|
||||
|
||||
@@ -216,7 +220,7 @@ class Handler extends ExceptionHandler
|
||||
|
||||
// create job that will mail.
|
||||
$ipAddress = request()->ip() ?? '0.0.0.0';
|
||||
$job = new MailError($userData, (string)config('firefly.site_owner'), $ipAddress, $data);
|
||||
$job = new MailError($userData, (string) config('firefly.site_owner'), $ipAddress, $data);
|
||||
dispatch($job);
|
||||
|
||||
parent::report($e);
|
||||
|
@@ -68,7 +68,7 @@ class AccountFactory
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function findOrCreate(string $accountName, string $accountType): Account
|
||||
{
|
||||
app('log')->debug(sprintf('findOrCreate("%s", "%s")', $accountName, $accountType));
|
||||
@@ -100,7 +100,7 @@ class AccountFactory
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function create(array $data): Account
|
||||
{
|
||||
app('log')->debug('Now in AccountFactory::create()');
|
||||
@@ -171,7 +171,7 @@ class AccountFactory
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function createAccount(AccountType $type, array $data): Account
|
||||
{
|
||||
$this->accountRepository->resetAccountOrder();
|
||||
@@ -239,7 +239,7 @@ class AccountFactory
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function cleanMetaDataArray(Account $account, array $data): array
|
||||
{
|
||||
$currencyId = array_key_exists('currency_id', $data) ? (int)$data['currency_id'] : 0;
|
||||
|
@@ -43,7 +43,7 @@ class BillFactory
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function create(array $data): ?Bill
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__), $data);
|
||||
|
@@ -52,7 +52,9 @@ class RecurrenceFactory
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
public function create(array $data): Recurrence
|
||||
{
|
||||
try {
|
||||
@@ -77,7 +79,7 @@ class RecurrenceFactory
|
||||
$firstDate = $data['recurrence']['first_date'];
|
||||
}
|
||||
if (array_key_exists('nr_of_repetitions', $data['recurrence'])) {
|
||||
$repetitions = (int)$data['recurrence']['nr_of_repetitions'];
|
||||
$repetitions = (int) $data['recurrence']['nr_of_repetitions'];
|
||||
}
|
||||
if (array_key_exists('repeat_until', $data['recurrence'])) {
|
||||
$repeatUntil = $data['recurrence']['repeat_until'];
|
||||
@@ -114,7 +116,7 @@ class RecurrenceFactory
|
||||
$recurrence->save();
|
||||
|
||||
if (array_key_exists('notes', $data['recurrence'])) {
|
||||
$this->updateNote($recurrence, (string)$data['recurrence']['notes']);
|
||||
$this->updateNote($recurrence, (string) $data['recurrence']['notes']);
|
||||
}
|
||||
|
||||
$this->createRepetitions($recurrence, $data['repetitions'] ?? []);
|
||||
|
@@ -49,7 +49,7 @@ class TransactionGroupFactory
|
||||
*
|
||||
* @throws DuplicateTransactionException
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function create(array $data): TransactionGroup
|
||||
{
|
||||
app('log')->debug('Now in TransactionGroupFactory::create()');
|
||||
|
@@ -91,7 +91,7 @@ class TransactionJournalFactory
|
||||
*
|
||||
* @throws DuplicateTransactionException
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function create(array $data): Collection
|
||||
{
|
||||
app('log')->debug('Now in TransactionJournalFactory::create()');
|
||||
@@ -344,7 +344,7 @@ class TransactionJournalFactory
|
||||
* If this transaction already exists, throw an error.
|
||||
*
|
||||
* @throws DuplicateTransactionException
|
||||
* */
|
||||
*/
|
||||
private function errorIfDuplicate(string $hash): void
|
||||
{
|
||||
app('log')->debug(sprintf('In errorIfDuplicate(%s)', $hash));
|
||||
@@ -442,7 +442,7 @@ class TransactionJournalFactory
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function getCurrencyByAccount(string $type, ?TransactionCurrency $currency, Account $source, Account $destination): TransactionCurrency
|
||||
{
|
||||
app('log')->debug('Now in getCurrencyByAccount()');
|
||||
@@ -455,7 +455,7 @@ class TransactionJournalFactory
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function getCurrency(?TransactionCurrency $currency, Account $account): TransactionCurrency
|
||||
{
|
||||
app('log')->debug('Now in getCurrency()');
|
||||
@@ -489,7 +489,7 @@ class TransactionJournalFactory
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function getForeignByAccount(string $type, ?TransactionCurrency $foreignCurrency, Account $destination): ?TransactionCurrency
|
||||
{
|
||||
if (TransactionType::TRANSFER === $type) {
|
||||
|
@@ -45,7 +45,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
* Generates the report.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function generate(): string
|
||||
{
|
||||
$auditData = [];
|
||||
@@ -110,7 +110,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
* Get the audit report.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function getAuditReport(Account $account, Carbon $date): array
|
||||
{
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
|
@@ -115,7 +115,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function runWebhook(Webhook $webhook): void
|
||||
{
|
||||
app('log')->debug(sprintf('Now in runWebhook(#%d)', $webhook->id));
|
||||
@@ -128,7 +128,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function generateMessage(Webhook $webhook, Model $model): void
|
||||
{
|
||||
$class = get_class($model);
|
||||
|
@@ -67,7 +67,9 @@ class EditController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit account overview.
|
||||
* Edit account overview. It's complex, but it just has a lot of if/then/else.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*
|
||||
* @return Factory|Redirector|RedirectResponse|View
|
||||
*/
|
||||
|
@@ -146,7 +146,7 @@ class ReconcileController extends Controller
|
||||
* @return Redirector|RedirectResponse
|
||||
*
|
||||
* @throws DuplicateTransactionException
|
||||
* */
|
||||
*/
|
||||
public function submit(ReconciliationStoreRequest $request, Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
if (!$this->isEditableAccount($account)) {
|
||||
@@ -188,7 +188,7 @@ class ReconcileController extends Controller
|
||||
* Creates a reconciliation group.
|
||||
*
|
||||
* @throws DuplicateTransactionException
|
||||
* */
|
||||
*/
|
||||
private function createReconciliation(Account $account, Carbon $start, Carbon $end, string $difference): string
|
||||
{
|
||||
if (!$this->isEditableAccount($account)) {
|
||||
|
@@ -76,8 +76,7 @@ class AccountController extends Controller
|
||||
* Shows the balances for all the user's expense accounts (on the front page).
|
||||
*
|
||||
* This chart is (multi) currency aware.
|
||||
*
|
||||
* */
|
||||
*/
|
||||
public function expenseAccounts(): JsonResponse
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
@@ -380,7 +379,7 @@ class AccountController extends Controller
|
||||
* Shows overview of account during a single period.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function period(Account $account, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$chartData = [];
|
||||
@@ -416,7 +415,7 @@ class AccountController extends Controller
|
||||
* TODO this chart is not multi currency aware.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function report(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
return response()->json($this->accountBalanceChart($accounts, $start, $end));
|
||||
@@ -426,8 +425,7 @@ class AccountController extends Controller
|
||||
* Shows the balances for all the user's revenue accounts.
|
||||
*
|
||||
* This chart is multi-currency aware.
|
||||
*
|
||||
* */
|
||||
*/
|
||||
public function revenueAccounts(): JsonResponse
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
@@ -517,7 +515,7 @@ class AccountController extends Controller
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function periodByCurrency(Carbon $start, Carbon $end, Account $account, TransactionCurrency $currency): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in periodByCurrency("%s", "%s", %s, "%s")', $start->format('Y-m-d'), $end->format('Y-m-d'), $account->id, $currency->code));
|
||||
|
@@ -32,6 +32,9 @@ use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
/**
|
||||
* Class Controller.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.NumberOfChildren)
|
||||
*/
|
||||
abstract class Controller extends BaseController
|
||||
{
|
||||
|
@@ -65,7 +65,7 @@ class ReconcileController extends Controller
|
||||
* Overview of reconciliation.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function overview(Request $request, Account $account = null, Carbon $start = null, Carbon $end = null): JsonResponse
|
||||
{
|
||||
$startBalance = $request->get('startBalance');
|
||||
@@ -165,7 +165,7 @@ class ReconcileController extends Controller
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function transactions(Account $account, Carbon $start = null, Carbon $end = null)
|
||||
{
|
||||
if (null === $start || null === $end) {
|
||||
|
@@ -59,6 +59,8 @@ class RecurrenceController extends Controller
|
||||
/**
|
||||
* Shows all events for a repetition. Used in calendar.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function events(Request $request): JsonResponse
|
||||
|
@@ -74,7 +74,7 @@ class IndexController extends Controller
|
||||
* @return Factory|View
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->cleanupObjectGroups();
|
||||
|
@@ -66,7 +66,7 @@ class ShowController extends Controller
|
||||
* @return Factory|View
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function show(PiggyBank $piggyBank)
|
||||
{
|
||||
/** @var Carbon $end */
|
||||
|
@@ -150,6 +150,7 @@ class PreferencesController extends Controller
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
public function postIndex(Request $request)
|
||||
{
|
||||
|
@@ -66,7 +66,7 @@ class BudgetController extends Controller
|
||||
* @return Factory|View
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function accountPerBudget(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||
{
|
||||
/** @var BudgetReportGenerator $generator */
|
||||
@@ -257,7 +257,7 @@ class BudgetController extends Controller
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function general(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
/** @var BudgetReportGenerator $generator */
|
||||
|
@@ -85,6 +85,8 @@ use Laravel\Passport\Events\AccessTokenCreated;
|
||||
|
||||
/**
|
||||
* Class EventServiceProvider.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
@@ -75,6 +75,8 @@ use Illuminate\Support\ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class FireflyServiceProvider.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class FireflyServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
@@ -221,7 +221,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function getCashAccount(): Account
|
||||
{
|
||||
/** @var AccountType $type */
|
||||
@@ -342,7 +342,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function getReconciliation(Account $account): ?Account
|
||||
{
|
||||
if (AccountType::ASSET !== $account->accountType->type) {
|
||||
@@ -617,7 +617,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function store(array $data): Account
|
||||
{
|
||||
/** @var AccountFactory $factory */
|
||||
@@ -629,7 +629,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function update(Account $account, array $data): Account
|
||||
{
|
||||
/** @var AccountUpdateService $service */
|
||||
|
@@ -42,7 +42,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function getAccountReport(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$yesterday = clone $start;
|
||||
@@ -109,7 +109,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): array
|
||||
{
|
||||
// get all expenses for the given accounts in the given period!
|
||||
@@ -140,7 +140,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): array
|
||||
{
|
||||
// get all incomes for the given accounts in the given period!
|
||||
@@ -175,7 +175,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function groupExpenseByDestination(array $array): array
|
||||
{
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
@@ -235,7 +235,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function groupIncomeBySource(array $array): array
|
||||
{
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
|
@@ -218,6 +218,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
private function getTransactionsForSum(
|
||||
string $type,
|
||||
|
@@ -421,8 +421,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
/**
|
||||
* Given the date in $date, this method will return a moment in the future where the bill is expected to be paid.
|
||||
*
|
||||
* */
|
||||
*/
|
||||
public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
@@ -463,7 +462,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function store(array $data): Bill
|
||||
{
|
||||
/** @var BillFactory $factory */
|
||||
@@ -643,7 +642,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function update(Bill $bill, array $data): Bill
|
||||
{
|
||||
/** @var BillUpdateService $service */
|
||||
|
@@ -261,7 +261,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function store(array $data): BudgetLimit
|
||||
{
|
||||
// if no currency has been provided, use the user's default currency:
|
||||
@@ -316,7 +316,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function update(BudgetLimit $budgetLimit, array $data): BudgetLimit
|
||||
{
|
||||
$budgetLimit->amount = array_key_exists('amount', $data) ? $data['amount'] : $budgetLimit->amount;
|
||||
|
@@ -97,7 +97,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
app('log')->debug(sprintf('Budget limit #%d', $limit->id));
|
||||
$currency = $limit->transactionCurrency;
|
||||
$return[$currency->id] ??= [
|
||||
'id' => (string)$currency->id,
|
||||
'id' => (string) $currency->id,
|
||||
'name' => $currency->name,
|
||||
'symbol' => $currency->symbol,
|
||||
'code' => $currency->code,
|
||||
@@ -120,12 +120,12 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
$total = $limit->start_date->diffInDays($limit->end_date) + 1; // include the day itself.
|
||||
$days = $this->daysInOverlap($limit, $start, $end);
|
||||
$amount = bcmul(bcdiv($limit->amount, (string)$total), (string)$days);
|
||||
$amount = bcmul(bcdiv($limit->amount, (string) $total), (string) $days);
|
||||
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount);
|
||||
app('log')->debug(
|
||||
sprintf(
|
||||
'Amount per day: %s (%s over %d days). Total amount for %d days: %s',
|
||||
bcdiv($limit->amount, (string)$total),
|
||||
bcdiv($limit->amount, (string) $total),
|
||||
$limit->amount,
|
||||
$total,
|
||||
$days,
|
||||
@@ -171,7 +171,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
app('log')->debug(sprintf('Budget limit #%d', $limit->id));
|
||||
$currency = $limit->transactionCurrency;
|
||||
$return[$currency->id] ??= [
|
||||
'id' => (string)$currency->id,
|
||||
'id' => (string) $currency->id,
|
||||
'name' => $currency->name,
|
||||
'symbol' => $currency->symbol,
|
||||
'code' => $currency->code,
|
||||
@@ -194,12 +194,12 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
$total = $limit->start_date->diffInDays($limit->end_date) + 1; // include the day itself.
|
||||
$days = $this->daysInOverlap($limit, $start, $end);
|
||||
$amount = bcmul(bcdiv($limit->amount, (string)$total), (string)$days);
|
||||
$amount = bcmul(bcdiv($limit->amount, (string) $total), (string) $days);
|
||||
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount);
|
||||
app('log')->debug(
|
||||
sprintf(
|
||||
'Amount per day: %s (%s over %d days). Total amount for %d days: %s',
|
||||
bcdiv($limit->amount, (string)$total),
|
||||
bcdiv($limit->amount, (string) $total),
|
||||
$limit->amount,
|
||||
$total,
|
||||
$days,
|
||||
@@ -233,7 +233,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function update(Budget $budget, array $data): Budget
|
||||
{
|
||||
app('log')->debug('Now in update()');
|
||||
@@ -248,7 +248,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$budget->active = $data['active'];
|
||||
}
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->setNoteText($budget, (string)$data['notes']);
|
||||
$this->setNoteText($budget, (string) $data['notes']);
|
||||
}
|
||||
$budget->save();
|
||||
|
||||
@@ -310,8 +310,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
foreach ($budgets as $budget) {
|
||||
\DB::table('budget_transaction')->where('budget_id', $budget->id)->delete();
|
||||
\DB::table('budget_transaction_journal')->where('budget_id', $budget->id)->delete();
|
||||
RecurrenceTransactionMeta::where('name', 'budget_id')->where('value', (string)$budget->id)->delete();
|
||||
RuleAction::where('action_type', 'set_budget')->where('action_value', (string)$budget->id)->delete();
|
||||
RecurrenceTransactionMeta::where('name', 'budget_id')->where('value', (string) $budget->id)->delete();
|
||||
RuleAction::where('action_type', 'set_budget')->where('action_value', (string) $budget->id)->delete();
|
||||
$budget->delete();
|
||||
}
|
||||
}
|
||||
@@ -335,7 +335,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
app('log')->debug('Now in findBudget()');
|
||||
app('log')->debug(sprintf('Searching for budget with ID #%d...', $budgetId));
|
||||
$result = $this->find((int)$budgetId);
|
||||
$result = $this->find((int) $budgetId);
|
||||
if (null === $result && null !== $budgetName && '' !== $budgetName) {
|
||||
app('log')->debug(sprintf('Searching for budget with name %s...', $budgetName));
|
||||
$result = $this->findByName($budgetName);
|
||||
@@ -471,9 +471,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
'id' => (string)$currencyId,
|
||||
'id' => (string) $currencyId,
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'code' => $journal['currency_code'],
|
||||
@@ -483,10 +483,10 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
|
||||
|
||||
// also do foreign amount:
|
||||
$foreignId = (int)$journal['foreign_currency_id'];
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
if (0 !== $foreignId) {
|
||||
$array[$foreignId] ??= [
|
||||
'id' => (string)$foreignId,
|
||||
'id' => (string) $foreignId,
|
||||
'name' => $journal['foreign_currency_name'],
|
||||
'symbol' => $journal['foreign_currency_symbol'],
|
||||
'code' => $journal['foreign_currency_code'],
|
||||
@@ -533,9 +533,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
'id' => (string)$currencyId,
|
||||
'id' => (string) $currencyId,
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'code' => $journal['currency_code'],
|
||||
@@ -545,10 +545,10 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
|
||||
|
||||
// also do foreign amount:
|
||||
$foreignId = (int)$journal['foreign_currency_id'];
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
if (0 !== $foreignId) {
|
||||
$array[$foreignId] ??= [
|
||||
'id' => (string)$foreignId,
|
||||
'id' => (string) $foreignId,
|
||||
'name' => $journal['foreign_currency_name'],
|
||||
'symbol' => $journal['foreign_currency_symbol'],
|
||||
'code' => $journal['foreign_currency_code'],
|
||||
@@ -564,7 +564,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
public function store(array $data): Budget
|
||||
{
|
||||
$order = $this->getMaxOrder();
|
||||
@@ -588,7 +590,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
// set notes
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->setNoteText($newBudget, (string)$data['notes']);
|
||||
$this->setNoteText($newBudget, (string) $data['notes']);
|
||||
}
|
||||
|
||||
if (!array_key_exists('auto_budget_type', $data) || !array_key_exists('auto_budget_amount', $data) || !array_key_exists('auto_budget_period', $data)) {
|
||||
@@ -616,10 +618,10 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = null;
|
||||
if (array_key_exists('currency_id', $data)) {
|
||||
$currency = $repos->find((int)$data['currency_id']);
|
||||
$currency = $repos->find((int) $data['currency_id']);
|
||||
}
|
||||
if (array_key_exists('currency_code', $data)) {
|
||||
$currency = $repos->findByCode((string)$data['currency_code']);
|
||||
$currency = $repos->findByCode((string) $data['currency_code']);
|
||||
}
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
@@ -655,7 +657,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
public function getMaxOrder(): int
|
||||
{
|
||||
return (int)$this->user->budgets()->max('order');
|
||||
return (int) $this->user->budgets()->max('order');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -750,7 +752,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function updateAutoBudget(Budget $budget, array $data): void
|
||||
{
|
||||
// update or create auto-budget:
|
||||
@@ -771,8 +773,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
/** @var CurrencyRepositoryInterface $repos */
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currencyId = (int)($data['currency_id'] ?? 0);
|
||||
$currencyCode = (string)($data['currency_code'] ?? '');
|
||||
$currencyId = (int) ($data['currency_id'] ?? 0);
|
||||
$currencyCode = (string) ($data['currency_code'] ?? '');
|
||||
$currency = $repos->find($currencyId);
|
||||
if (null === $currency) {
|
||||
$currency = $repos->findByCode($currencyCode);
|
||||
|
@@ -135,7 +135,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
* Used for connecting to a piggy bank.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function getExactAmount(PiggyBank $piggyBank, PiggyBankRepetition $repetition, TransactionJournal $journal): string
|
||||
{
|
||||
app('log')->debug(sprintf('Now in getExactAmount(%d, %d, %d)', $piggyBank->id, $repetition->id, $journal->id));
|
||||
@@ -318,8 +318,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
|
||||
/**
|
||||
* Get for piggy account what is left to put in piggies.
|
||||
*
|
||||
* */
|
||||
*/
|
||||
public function leftOnAccount(PiggyBank $piggyBank, Carbon $date): string
|
||||
{
|
||||
$balance = app('steam')->balanceIgnoreVirtual($piggyBank->account, $date);
|
||||
|
@@ -258,8 +258,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
|
||||
/**
|
||||
* Get the tags from the recurring transaction.
|
||||
*
|
||||
* */
|
||||
*/
|
||||
public function getTags(RecurrenceTransaction $transaction): array
|
||||
{
|
||||
$tags = [];
|
||||
@@ -479,7 +478,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function store(array $data): Recurrence
|
||||
{
|
||||
/** @var RecurrenceFactory $factory */
|
||||
|
@@ -255,7 +255,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
* Return all piggy bank events for all journals in the group.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function getPiggyEvents(TransactionGroup $group): array
|
||||
{
|
||||
$return = [];
|
||||
@@ -318,7 +318,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* @throws DuplicateTransactionException
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function store(array $data): TransactionGroup
|
||||
{
|
||||
/** @var TransactionGroupFactory $factory */
|
||||
|
@@ -157,6 +157,8 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function updateMembership(UserGroup $userGroup, array $data): UserGroup
|
||||
|
@@ -217,7 +217,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
* Find by object, ID or code. Returns user default or system default.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function findCurrency(?int $currencyId, ?string $currencyCode): TransactionCurrency
|
||||
{
|
||||
$result = $this->findCurrencyNull($currencyId, $currencyCode);
|
||||
|
@@ -88,6 +88,8 @@ trait AccountServiceTrait
|
||||
/**
|
||||
* Update metadata for account. Depends on type which fields are valid.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*
|
||||
* TODO this method treats expense accounts and liabilities the same way (tries to save interest)
|
||||
*/
|
||||
public function updateMetaData(Account $account, array $data): void
|
||||
@@ -336,7 +338,7 @@ trait AccountServiceTrait
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
protected function getCurrency(int $currencyId, string $currencyCode): TransactionCurrency
|
||||
{
|
||||
// find currency, or use default currency instead.
|
||||
@@ -360,7 +362,7 @@ trait AccountServiceTrait
|
||||
* Create the opposing "credit liability" transaction for credit liabilities.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
protected function updateCreditTransaction(Account $account, string $direction, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
@@ -416,7 +418,7 @@ trait AccountServiceTrait
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
protected function createCreditTransaction(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
|
||||
{
|
||||
app('log')->debug('Now going to create an createCreditTransaction.');
|
||||
@@ -510,7 +512,7 @@ trait AccountServiceTrait
|
||||
* Since opening balance and date can still be empty strings, it may fail.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
protected function updateOBGroupV2(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
@@ -566,7 +568,7 @@ trait AccountServiceTrait
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
protected function createOBGroupV2(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
|
||||
{
|
||||
app('log')->debug('Now going to create an OB group.');
|
||||
|
@@ -243,7 +243,11 @@ class CreditRecalculateService
|
||||
}
|
||||
|
||||
/**
|
||||
* A complex and long method, but rarely used luckily.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
private function processTransaction(Account $account, string $direction, Transaction $transaction, string $leftOfDebt): string
|
||||
{
|
||||
|
@@ -87,7 +87,9 @@ trait RecurringTransactionTrait
|
||||
* Store transactions of a recurring transactions. It's complex but readable.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
protected function createTransactions(Recurrence $recurrence, array $transactions): void
|
||||
{
|
||||
app('log')->debug('Now in createTransactions()');
|
||||
@@ -123,7 +125,7 @@ trait RecurringTransactionTrait
|
||||
if (!$validator->validateDestination(['id' => $destination->id])) {
|
||||
throw new FireflyException(sprintf('Destination invalid: %s', $validator->destError));
|
||||
}
|
||||
if (array_key_exists('foreign_amount', $array) && '' === (string)$array['foreign_amount']) {
|
||||
if (array_key_exists('foreign_amount', $array) && '' === (string) $array['foreign_amount']) {
|
||||
unset($array['foreign_amount']);
|
||||
}
|
||||
// TODO typeOverrule. The account validator may have a different opinion on the type of the transaction.
|
||||
@@ -135,25 +137,25 @@ trait RecurringTransactionTrait
|
||||
'source_id' => $source->id,
|
||||
'destination_id' => $destination->id,
|
||||
'amount' => $array['amount'],
|
||||
'foreign_amount' => array_key_exists('foreign_amount', $array) ? (string)$array['foreign_amount'] : null,
|
||||
'foreign_amount' => array_key_exists('foreign_amount', $array) ? (string) $array['foreign_amount'] : null,
|
||||
'description' => $array['description'],
|
||||
]
|
||||
);
|
||||
$transaction->save();
|
||||
|
||||
if (array_key_exists('budget_id', $array)) {
|
||||
$this->setBudget($transaction, (int)$array['budget_id']);
|
||||
$this->setBudget($transaction, (int) $array['budget_id']);
|
||||
}
|
||||
if (array_key_exists('bill_id', $array)) {
|
||||
$this->setBill($transaction, (int)$array['bill_id']);
|
||||
$this->setBill($transaction, (int) $array['bill_id']);
|
||||
}
|
||||
if (array_key_exists('category_id', $array)) {
|
||||
$this->setCategory($transaction, (int)$array['category_id']);
|
||||
$this->setCategory($transaction, (int) $array['category_id']);
|
||||
}
|
||||
|
||||
// same for piggy bank
|
||||
if (array_key_exists('piggy_bank_id', $array)) {
|
||||
$this->updatePiggyBank($transaction, (int)$array['piggy_bank_id']);
|
||||
$this->updatePiggyBank($transaction, (int) $array['piggy_bank_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('tags', $array) && is_array($array['tags'])) {
|
||||
@@ -165,8 +167,8 @@ trait RecurringTransactionTrait
|
||||
protected function findAccount(array $expectedTypes, ?int $accountId, ?string $accountName): Account
|
||||
{
|
||||
$result = null;
|
||||
$accountId = (int)$accountId;
|
||||
$accountName = (string)$accountName;
|
||||
$accountId = (int) $accountId;
|
||||
$accountName = (string) $accountName;
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
|
@@ -63,7 +63,7 @@ class AccountUpdateService
|
||||
* Update account data.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function update(Account $account, array $data): Account
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
|
@@ -46,14 +46,14 @@ class BillUpdateService
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function update(Bill $bill, array $data): Bill
|
||||
{
|
||||
$this->user = $bill->user;
|
||||
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$currency = $factory->find((int)($data['currency_id'] ?? null), $data['currency_code'] ?? null) ??
|
||||
$currency = $factory->find((int) ($data['currency_id'] ?? null), $data['currency_code'] ?? null) ??
|
||||
app('amount')->getDefaultCurrencyByUserGroup($bill->user->userGroup);
|
||||
|
||||
// enable the currency if it isn't.
|
||||
@@ -75,14 +75,14 @@ class BillUpdateService
|
||||
];
|
||||
// update note:
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->updateNote($bill, (string)$data['notes']);
|
||||
$this->updateNote($bill, (string) $data['notes']);
|
||||
}
|
||||
|
||||
// update order.
|
||||
if (array_key_exists('order', $data)) {
|
||||
// update the order of the piggy bank:
|
||||
$oldOrder = $bill->order;
|
||||
$newOrder = (int)($data['order'] ?? $oldOrder);
|
||||
$newOrder = (int) ($data['order'] ?? $oldOrder);
|
||||
if ($oldOrder !== $newOrder) {
|
||||
$this->updateOrder($bill, $oldOrder, $newOrder);
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class BillUpdateService
|
||||
}
|
||||
if (array_key_exists('object_group_id', $data)) {
|
||||
// try also with ID:
|
||||
$objectGroupId = (int)($data['object_group_id'] ?? 0);
|
||||
$objectGroupId = (int) ($data['object_group_id'] ?? 0);
|
||||
if (0 !== $objectGroupId) {
|
||||
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
||||
if (null !== $objectGroup) {
|
||||
@@ -129,22 +129,25 @@ class BillUpdateService
|
||||
return $bill;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
private function updateBillProperties(Bill $bill, array $data): Bill
|
||||
{
|
||||
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
|
||||
if (array_key_exists('name', $data) && '' !== (string) $data['name']) {
|
||||
$bill->name = $data['name'];
|
||||
}
|
||||
|
||||
if (array_key_exists('amount_min', $data) && '' !== (string)$data['amount_min']) {
|
||||
if (array_key_exists('amount_min', $data) && '' !== (string) $data['amount_min']) {
|
||||
$bill->amount_min = $data['amount_min'];
|
||||
}
|
||||
if (array_key_exists('amount_max', $data) && '' !== (string)$data['amount_max']) {
|
||||
if (array_key_exists('amount_max', $data) && '' !== (string) $data['amount_max']) {
|
||||
$bill->amount_max = $data['amount_max'];
|
||||
}
|
||||
if (array_key_exists('date', $data) && '' !== (string)$data['date']) {
|
||||
if (array_key_exists('date', $data) && '' !== (string) $data['date']) {
|
||||
$bill->date = $data['date'];
|
||||
}
|
||||
if (array_key_exists('repeat_freq', $data) && '' !== (string)$data['repeat_freq']) {
|
||||
if (array_key_exists('repeat_freq', $data) && '' !== (string) $data['repeat_freq']) {
|
||||
$bill->repeat_freq = $data['repeat_freq'];
|
||||
}
|
||||
if (array_key_exists('skip', $data)) {
|
||||
|
@@ -41,7 +41,7 @@ class GroupUpdateService
|
||||
*
|
||||
* @throws DuplicateTransactionException
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function update(TransactionGroup $transactionGroup, array $data): TransactionGroup
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
@@ -149,7 +149,7 @@ class GroupUpdateService
|
||||
/**
|
||||
* @throws DuplicateTransactionException
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function updateTransactions(TransactionGroup $transactionGroup, array $transactions): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
@@ -206,7 +206,7 @@ class GroupUpdateService
|
||||
/**
|
||||
* @throws DuplicateTransactionException
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function createTransactionJournal(TransactionGroup $transactionGroup, array $data): ?TransactionJournal
|
||||
{
|
||||
$submission = [
|
||||
|
@@ -71,7 +71,7 @@ class RecurrenceUpdateService
|
||||
$recurrence->repetitions = 0;
|
||||
}
|
||||
if (array_key_exists('nr_of_repetitions', $info)) {
|
||||
if (0 !== (int)$info['nr_of_repetitions']) {
|
||||
if (0 !== (int) $info['nr_of_repetitions']) {
|
||||
$recurrence->repeat_until = null;
|
||||
}
|
||||
$recurrence->repetitions = $info['nr_of_repetitions'];
|
||||
@@ -192,7 +192,7 @@ class RecurrenceUpdateService
|
||||
* TODO this method is very complex.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function updateTransactions(Recurrence $recurrence, array $transactions): void
|
||||
{
|
||||
app('log')->debug('Now in updateTransactions()');
|
||||
@@ -209,7 +209,7 @@ class RecurrenceUpdateService
|
||||
// First, make sure to loop all existing transactions and match them to a counterpart in the submitted transactions array.
|
||||
foreach ($originalTransactions as $i => $originalTransaction) {
|
||||
foreach ($transactions as $ii => $submittedTransaction) {
|
||||
if (array_key_exists('id', $submittedTransaction) && (int)$originalTransaction['id'] === (int)$submittedTransaction['id']) {
|
||||
if (array_key_exists('id', $submittedTransaction) && (int) $originalTransaction['id'] === (int) $submittedTransaction['id']) {
|
||||
app('log')->debug(sprintf('Match original transaction #%d with an entry in the submitted array.', $originalTransaction['id']));
|
||||
$combinations[] = [
|
||||
'original' => $originalTransaction,
|
||||
@@ -238,29 +238,34 @@ class RecurrenceUpdateService
|
||||
// anything left in the original transactions array can be deleted.
|
||||
foreach ($originalTransactions as $original) {
|
||||
app('log')->debug(sprintf('Original transaction #%d is unmatched, delete it!', $original['id']));
|
||||
$this->deleteTransaction($recurrence, (int)$original['id']);
|
||||
$this->deleteTransaction($recurrence, (int) $original['id']);
|
||||
}
|
||||
// anything left is new.
|
||||
$this->createTransactions($recurrence, $transactions);
|
||||
}
|
||||
|
||||
/**
|
||||
* It's a complex method but nothing surprising.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
private function updateCombination(Recurrence $recurrence, array $combination): void
|
||||
{
|
||||
$original = $combination['original'];
|
||||
$submitted = $combination['submitted'];
|
||||
$original = $combination['original'];
|
||||
$submitted = $combination['submitted'];
|
||||
$currencyFactory = app(TransactionCurrencyFactory::class);
|
||||
|
||||
/** @var RecurrenceTransaction $transaction */
|
||||
$transaction = $recurrence->recurrenceTransactions()->find($original['id']);
|
||||
app('log')->debug(sprintf('Now in updateCombination(#%d)', $original['id']));
|
||||
|
||||
$currencyFactory = app(TransactionCurrencyFactory::class);
|
||||
|
||||
// loop all and try to match them:
|
||||
$currency = null;
|
||||
$foreignCurrency = null;
|
||||
if (array_key_exists('currency_id', $submitted) || array_key_exists('currency_code', $submitted)) {
|
||||
$currency = $currencyFactory->find(
|
||||
array_key_exists('currency_id', $submitted) ? (int)$submitted['currency_id'] : null,
|
||||
array_key_exists('currency_id', $submitted) ? (int) $submitted['currency_id'] : null,
|
||||
array_key_exists('currency_code', $submitted) ? $submitted['currency_code'] : null
|
||||
);
|
||||
}
|
||||
@@ -272,7 +277,7 @@ class RecurrenceUpdateService
|
||||
}
|
||||
if (array_key_exists('foreign_currency_id', $submitted) || array_key_exists('foreign_currency_code', $submitted)) {
|
||||
$foreignCurrency = $currencyFactory->find(
|
||||
array_key_exists('foreign_currency_id', $submitted) ? (int)$submitted['foreign_currency_id'] : null,
|
||||
array_key_exists('foreign_currency_id', $submitted) ? (int) $submitted['foreign_currency_id'] : null,
|
||||
array_key_exists('foreign_currency_code', $submitted) ? $submitted['foreign_currency_code'] : null
|
||||
);
|
||||
}
|
||||
@@ -301,29 +306,29 @@ class RecurrenceUpdateService
|
||||
}
|
||||
// update meta data
|
||||
if (array_key_exists('budget_id', $submitted)) {
|
||||
$this->setBudget($transaction, (int)$submitted['budget_id']);
|
||||
$this->setBudget($transaction, (int) $submitted['budget_id']);
|
||||
}
|
||||
if (array_key_exists('bill_id', $submitted)) {
|
||||
$this->setBill($transaction, (int)$submitted['bill_id']);
|
||||
$this->setBill($transaction, (int) $submitted['bill_id']);
|
||||
}
|
||||
// reset category if name is set but empty:
|
||||
// can be removed when v1 is retired.
|
||||
if (array_key_exists('category_name', $submitted) && '' === (string)$submitted['category_name']) {
|
||||
if (array_key_exists('category_name', $submitted) && '' === (string) $submitted['category_name']) {
|
||||
app('log')->debug('Category name is submitted but is empty. Set category to be empty.');
|
||||
$submitted['category_name'] = null;
|
||||
$submitted['category_id'] = 0;
|
||||
}
|
||||
|
||||
if (array_key_exists('category_id', $submitted)) {
|
||||
app('log')->debug(sprintf('Category ID is submitted, set category to be %d.', (int)$submitted['category_id']));
|
||||
$this->setCategory($transaction, (int)$submitted['category_id']);
|
||||
app('log')->debug(sprintf('Category ID is submitted, set category to be %d.', (int) $submitted['category_id']));
|
||||
$this->setCategory($transaction, (int) $submitted['category_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('tags', $submitted) && is_array($submitted['tags'])) {
|
||||
$this->updateTags($transaction, $submitted['tags']);
|
||||
}
|
||||
if (array_key_exists('piggy_bank_id', $submitted)) {
|
||||
$this->updatePiggyBank($transaction, (int)$submitted['piggy_bank_id']);
|
||||
$this->updatePiggyBank($transaction, (int) $submitted['piggy_bank_id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -40,7 +40,7 @@ trait ChartGeneration
|
||||
* Shows an overview of the account balances for a set of accounts.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
protected function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array // chart helper method.
|
||||
{
|
||||
// chart properties for cache:
|
||||
|
@@ -70,6 +70,8 @@ class ParseDateString
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
public function parseDate(string $date): Carbon
|
||||
{
|
||||
@@ -82,7 +84,7 @@ class ParseDateString
|
||||
|
||||
// if regex for YYYY-MM-DD:
|
||||
$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';
|
||||
$result = preg_match($pattern, $date);
|
||||
$result = preg_match($pattern, $date);
|
||||
if (false !== $result && 0 !== $result) {
|
||||
return $this->parseDefaultDate($date);
|
||||
}
|
||||
@@ -224,7 +226,7 @@ class ParseDateString
|
||||
|
||||
// verify if correct
|
||||
$pattern = '/[+-]\d+[wqmdy]/';
|
||||
$result = preg_match($pattern, $part);
|
||||
$result = preg_match($pattern, $part);
|
||||
if (0 === $result || false === $result) {
|
||||
app('log')->error(sprintf('Part "%s" does not match regular expression. Will be skipped.', $part));
|
||||
|
||||
@@ -280,7 +282,7 @@ class ParseDateString
|
||||
{
|
||||
// if regex for xxxx-MM-xx:
|
||||
$pattern = '/^xxxx-(0[1-9]|1[012])-xx$/';
|
||||
$result = preg_match($pattern, $date);
|
||||
$result = preg_match($pattern, $date);
|
||||
if (false !== $result && 0 !== $result) {
|
||||
app('log')->debug(sprintf('"%s" is a month range.', $date));
|
||||
|
||||
@@ -308,7 +310,7 @@ class ParseDateString
|
||||
{
|
||||
// if regex for YYYY-xx-xx:
|
||||
$pattern = '/^(19|20)\d\d-xx-xx$/';
|
||||
$result = preg_match($pattern, $date);
|
||||
$result = preg_match($pattern, $date);
|
||||
if (false !== $result && 0 !== $result) {
|
||||
app('log')->debug(sprintf('"%s" is a year range.', $date));
|
||||
|
||||
@@ -336,7 +338,7 @@ class ParseDateString
|
||||
{
|
||||
// if regex for xxxx-MM-DD:
|
||||
$pattern = '/^xxxx-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';
|
||||
$result = preg_match($pattern, $date);
|
||||
$result = preg_match($pattern, $date);
|
||||
if (false !== $result && 0 !== $result) {
|
||||
app('log')->debug(sprintf('"%s" is a month/day range.', $date));
|
||||
|
||||
@@ -351,7 +353,7 @@ class ParseDateString
|
||||
{
|
||||
// if regex for YYYY-xx-DD:
|
||||
$pattern = '/^(19|20)\d\d-xx-(0[1-9]|[12]\d|3[01])$/';
|
||||
$result = preg_match($pattern, $date);
|
||||
$result = preg_match($pattern, $date);
|
||||
if (false !== $result && 0 !== $result) {
|
||||
app('log')->debug(sprintf('"%s" is a day/year range.', $date));
|
||||
|
||||
@@ -366,7 +368,7 @@ class ParseDateString
|
||||
{
|
||||
// if regex for YYYY-MM-xx:
|
||||
$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-xx$/';
|
||||
$result = preg_match($pattern, $date);
|
||||
$result = preg_match($pattern, $date);
|
||||
if (false !== $result && 0 !== $result) {
|
||||
app('log')->debug(sprintf('"%s" is a month/year range.', $date));
|
||||
|
||||
|
@@ -134,7 +134,7 @@ class BudgetReportGenerator
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->repository->setUser($user);
|
||||
|
@@ -30,60 +30,25 @@ trait GetRecurrenceData
|
||||
{
|
||||
protected function getSingleTransactionData(array $transaction): array
|
||||
{
|
||||
$return = [];
|
||||
$return = [];
|
||||
$stringKeys = ['id'];
|
||||
$intKeys = ['currency_id', 'foreign_currency_id', 'source_id', 'destination_id', 'bill_id', 'piggy_bank_id', 'bill_id', 'budget_id', 'category_id'];
|
||||
$keys = ['amount', 'currency_code', 'foreign_amount', 'foreign_currency_code', 'description', 'tags'];
|
||||
|
||||
if (array_key_exists('id', $transaction)) {
|
||||
$return['id'] = (string)$transaction['id'];
|
||||
foreach ($stringKeys as $key) {
|
||||
if (array_key_exists($key, $transaction)) {
|
||||
$return[$key] = (string) $transaction[$key];
|
||||
}
|
||||
}
|
||||
|
||||
// amount + currency
|
||||
if (array_key_exists('amount', $transaction)) {
|
||||
$return['amount'] = $transaction['amount'];
|
||||
foreach ($intKeys as $key) {
|
||||
if (array_key_exists($key, $transaction)) {
|
||||
$return[$key] = (int) $transaction[$key];
|
||||
}
|
||||
}
|
||||
if (array_key_exists('currency_id', $transaction)) {
|
||||
$return['currency_id'] = (int)$transaction['currency_id'];
|
||||
}
|
||||
if (array_key_exists('currency_code', $transaction)) {
|
||||
$return['currency_code'] = $transaction['currency_code'];
|
||||
}
|
||||
|
||||
// foreign amount + currency
|
||||
if (array_key_exists('foreign_amount', $transaction)) {
|
||||
$return['foreign_amount'] = $transaction['foreign_amount'];
|
||||
}
|
||||
if (array_key_exists('foreign_currency_id', $transaction)) {
|
||||
$return['foreign_currency_id'] = (int)$transaction['foreign_currency_id'];
|
||||
}
|
||||
if (array_key_exists('foreign_currency_code', $transaction)) {
|
||||
$return['foreign_currency_code'] = $transaction['foreign_currency_code'];
|
||||
}
|
||||
// source + dest
|
||||
if (array_key_exists('source_id', $transaction)) {
|
||||
$return['source_id'] = (int)$transaction['source_id'];
|
||||
}
|
||||
if (array_key_exists('destination_id', $transaction)) {
|
||||
$return['destination_id'] = (int)$transaction['destination_id'];
|
||||
}
|
||||
// description
|
||||
if (array_key_exists('description', $transaction)) {
|
||||
$return['description'] = $transaction['description'];
|
||||
}
|
||||
|
||||
if (array_key_exists('piggy_bank_id', $transaction)) {
|
||||
$return['piggy_bank_id'] = (int)$transaction['piggy_bank_id'];
|
||||
}
|
||||
if (array_key_exists('bill_id', $transaction)) {
|
||||
$return['bill_id'] = (int)$transaction['bill_id'];
|
||||
}
|
||||
|
||||
if (array_key_exists('tags', $transaction)) {
|
||||
$return['tags'] = $transaction['tags'];
|
||||
}
|
||||
if (array_key_exists('budget_id', $transaction)) {
|
||||
$return['budget_id'] = (int)$transaction['budget_id'];
|
||||
}
|
||||
if (array_key_exists('category_id', $transaction)) {
|
||||
$return['category_id'] = (int)$transaction['category_id'];
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $transaction)) {
|
||||
$return[$key] = $transaction[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
@@ -59,6 +59,8 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class OperatorQuerySearch
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class OperatorQuerySearch implements SearchInterface
|
||||
{
|
||||
@@ -69,8 +71,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
private CategoryRepositoryInterface $categoryRepository;
|
||||
private GroupCollectorInterface $collector;
|
||||
private CurrencyRepositoryInterface $currencyRepository;
|
||||
private array $excludeTags;
|
||||
private array $includeTags;
|
||||
private array $excludeTags;
|
||||
private array $includeTags;
|
||||
private array $invalidOperators;
|
||||
private int $limit;
|
||||
private Collection $operators;
|
||||
@@ -231,7 +233,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$this->collector->setUser($user);
|
||||
$this->collector->withAccountInformation()->withCategoryInformation()->withBudgetInformation();
|
||||
|
||||
$this->setLimit((int)app('preferences')->getForUser($user, 'listPageSize', 50)->data);
|
||||
$this->setLimit((int) app('preferences')->getForUser($user, 'listPageSize', 50)->data);
|
||||
}
|
||||
|
||||
public function setLimit(int $limit): void
|
||||
@@ -242,6 +244,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
private function handleSearchNode(Node $searchNode): void
|
||||
{
|
||||
@@ -271,7 +275,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case Emoticon::class:
|
||||
case Emoji::class:
|
||||
case Mention::class:
|
||||
$allWords = (string)$searchNode->getValue();
|
||||
$allWords = (string) $searchNode->getValue();
|
||||
app('log')->debug(sprintf('Add words "%s" to search string, because Node class is "%s"', $allWords, $class));
|
||||
$this->words[] = $allWords;
|
||||
|
||||
@@ -301,11 +305,11 @@ class OperatorQuerySearch implements SearchInterface
|
||||
// must be valid operator:
|
||||
if (
|
||||
in_array($operator, $this->validOperators, true)
|
||||
&& $this->updateCollector($operator, (string)$value, $prohibited)) {
|
||||
&& $this->updateCollector($operator, (string) $value, $prohibited)) {
|
||||
$this->operators->push(
|
||||
[
|
||||
'type' => self::getRootOperator($operator),
|
||||
'value' => (string)$value,
|
||||
'value' => (string) $value,
|
||||
'prohibited' => $prohibited,
|
||||
]
|
||||
);
|
||||
@@ -315,7 +319,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
app('log')->debug(sprintf('Added INVALID operator type "%s"', $operator));
|
||||
$this->invalidOperators[] = [
|
||||
'type' => $operator,
|
||||
'value' => (string)$value,
|
||||
'value' => (string) $value,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -325,6 +329,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
private function updateCollector(string $operator, string $value, bool $prohibited): bool
|
||||
{
|
||||
@@ -514,7 +519,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'source_account_id':
|
||||
$account = $this->accountRepository->find((int)$value);
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->setSourceAccounts(new Collection([$account]));
|
||||
}
|
||||
@@ -526,7 +531,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-source_account_id':
|
||||
$account = $this->accountRepository->find((int)$value);
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->excludeSourceAccounts(new Collection([$account]));
|
||||
}
|
||||
@@ -642,7 +647,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'destination_account_id':
|
||||
$account = $this->accountRepository->find((int)$value);
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->setDestinationAccounts(new Collection([$account]));
|
||||
}
|
||||
@@ -653,7 +658,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-destination_account_id':
|
||||
$account = $this->accountRepository->find((int)$value);
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->excludeDestinationAccounts(new Collection([$account]));
|
||||
}
|
||||
@@ -667,7 +672,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$parts = explode(',', $value);
|
||||
$collection = new Collection();
|
||||
foreach ($parts as $accountId) {
|
||||
$account = $this->accountRepository->find((int)$accountId);
|
||||
$account = $this->accountRepository->find((int) $accountId);
|
||||
if (null !== $account) {
|
||||
$collection->push($account);
|
||||
}
|
||||
@@ -685,7 +690,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$parts = explode(',', $value);
|
||||
$collection = new Collection();
|
||||
foreach ($parts as $accountId) {
|
||||
$account = $this->accountRepository->find((int)$accountId);
|
||||
$account = $this->accountRepository->find((int) $accountId);
|
||||
if (null !== $account) {
|
||||
$collection->push($account);
|
||||
}
|
||||
@@ -1974,6 +1979,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
private function searchAccountNr(string $value, SearchDirection $searchDirection, StringPosition $stringPosition, bool $prohibited = false): void
|
||||
{
|
||||
@@ -2033,7 +2039,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$filtered = $accounts->filter(
|
||||
static function (Account $account) use ($value, $stringMethod) {
|
||||
// either IBAN or account number
|
||||
$ibanMatch = $stringMethod(strtolower((string)$account->iban), strtolower($value));
|
||||
$ibanMatch = $stringMethod(strtolower((string) $account->iban), strtolower($value));
|
||||
$accountNrMatch = false;
|
||||
|
||||
/** @var AccountMeta $meta */
|
||||
|
@@ -87,7 +87,7 @@ class Steam
|
||||
* [yyyy-mm-dd] => 123,2
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function balanceInRange(Account $account, Carbon $start, Carbon $end, ?TransactionCurrency $currency = null): array
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
|
@@ -29,7 +29,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Support\Search\OperatorQuerySearch;
|
||||
use League\CommonMark\GithubFlavoredMarkdownConverter;
|
||||
use Route;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
@@ -111,6 +110,8 @@ class General extends AbstractExtension
|
||||
|
||||
/**
|
||||
* Show icon with attachment.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
protected function mimeIcon(): TwigFilter
|
||||
{
|
||||
@@ -205,7 +206,7 @@ class General extends AbstractExtension
|
||||
]
|
||||
);
|
||||
|
||||
return (string)$converter->convert($text);
|
||||
return (string) $converter->convert($text);
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
@@ -219,8 +220,8 @@ class General extends AbstractExtension
|
||||
return new TwigFilter(
|
||||
'phphost',
|
||||
static function (string $string): string {
|
||||
$proto = (string)parse_url($string, PHP_URL_SCHEME);
|
||||
$host = (string)parse_url($string, PHP_URL_HOST);
|
||||
$proto = (string) parse_url($string, PHP_URL_SCHEME);
|
||||
$host = (string) parse_url($string, PHP_URL_HOST);
|
||||
|
||||
return e(sprintf('%s://%s', $proto, $host));
|
||||
}
|
||||
|
@@ -121,7 +121,7 @@ class ConvertToDeposit implements ActionInterface
|
||||
* Is converted to a deposit from C to A.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function convertWithdrawalArray(TransactionJournal $journal): bool
|
||||
{
|
||||
$user = $journal->user;
|
||||
@@ -210,7 +210,7 @@ class ConvertToDeposit implements ActionInterface
|
||||
* The source account is replaced.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function convertTransferArray(TransactionJournal $journal): bool
|
||||
{
|
||||
$user = $journal->user;
|
||||
|
@@ -51,6 +51,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
|
@@ -116,7 +116,7 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function convertDepositArray(TransactionJournal $journal): bool
|
||||
{
|
||||
$user = $journal->user;
|
||||
@@ -202,7 +202,7 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
* Output is a withdrawal from A to C.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function convertTransferArray(TransactionJournal $journal): bool
|
||||
{
|
||||
// find or create expense account.
|
||||
|
@@ -49,7 +49,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
* Transform the account.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function transform(Account $account): array
|
||||
{
|
||||
$this->repository->setUser($account->user);
|
||||
@@ -156,7 +156,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
private function getCurrency(Account $account): array
|
||||
{
|
||||
$currency = $this->repository->getAccountCurrency($account);
|
||||
|
@@ -53,6 +53,7 @@ class BillTransformer extends AbstractTransformer
|
||||
* Transform the bill.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
public function transform(Bill $bill): array
|
||||
{
|
||||
|
@@ -49,7 +49,7 @@ class PiggyBankEventTransformer extends AbstractTransformer
|
||||
* Convert piggy bank event.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function transform(PiggyBankEvent $event): array
|
||||
{
|
||||
// get account linked to piggy bank
|
||||
|
@@ -50,7 +50,7 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
* Transform the piggy bank.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function transform(PiggyBank $piggyBank): array
|
||||
{
|
||||
$account = $piggyBank->account;
|
||||
|
@@ -139,7 +139,7 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
* Transform the piggy bank.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* */
|
||||
*/
|
||||
public function transform(PiggyBank $piggyBank): array
|
||||
{
|
||||
// $account = $piggyBank->account;
|
||||
|
@@ -76,6 +76,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
/**
|
||||
* Class User.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*
|
||||
* @property int|string $id
|
||||
* @property string $email
|
||||
* @property bool $isAdmin
|
||||
|
@@ -45,7 +45,7 @@ trait DepositValidation
|
||||
if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the destination of a deposit can't be created.
|
||||
$this->destError = (string)trans('validation.deposit_dest_need_data');
|
||||
$this->destError = (string) trans('validation.deposit_dest_need_data');
|
||||
app('log')->error('Both values are NULL, cant create deposit destination.');
|
||||
$result = false;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ trait DepositValidation
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
app('log')->debug('findExistingAccount() returned NULL, so the result is false.');
|
||||
$this->destError = (string)trans('validation.deposit_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->destError = (string) trans('validation.deposit_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$result = false;
|
||||
}
|
||||
if (null !== $search) {
|
||||
@@ -78,6 +78,12 @@ trait DepositValidation
|
||||
|
||||
abstract protected function findExistingAccount(array $validTypes, array $data): ?Account;
|
||||
|
||||
/**
|
||||
* Pretty complex unfortunately.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
protected function validateDepositSource(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
@@ -100,7 +106,7 @@ trait DepositValidation
|
||||
// if both values are NULL return false,
|
||||
// because the source of a deposit can't be created.
|
||||
// (this never happens).
|
||||
$this->sourceError = (string)trans('validation.deposit_source_need_data');
|
||||
$this->sourceError = (string) trans('validation.deposit_source_need_data');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
@@ -109,7 +115,7 @@ trait DepositValidation
|
||||
app('log')->debug('Check if there is not already another account with this IBAN');
|
||||
$existing = $this->findExistingAccount($validTypes, ['iban' => $accountIban], true);
|
||||
if (null !== $existing) {
|
||||
$this->sourceError = (string)trans('validation.deposit_src_iban_exists');
|
||||
$this->sourceError = (string) trans('validation.deposit_src_iban_exists');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@@ -247,7 +247,11 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* It's a long and fairly complex method, but I don't mind.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
protected function findExistingAccount(array $validTypes, array $data, bool $inverse = false): ?Account
|
||||
{
|
||||
|
@@ -30,39 +30,42 @@ use Illuminate\Validation\Validator;
|
||||
*/
|
||||
trait ValidatesAutoBudgetRequest
|
||||
{
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
protected function validateAutoBudgetAmount(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$type = $data['auto_budget_type'] ?? '';
|
||||
$amount = array_key_exists('auto_budget_amount', $data) ? $data['auto_budget_amount'] : null;
|
||||
$period = array_key_exists('auto_budget_period', $data) ? $data['auto_budget_period'] : null;
|
||||
$currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int)$data['auto_budget_currency_id'] : null;
|
||||
$currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int) $data['auto_budget_currency_id'] : null;
|
||||
$currencyCode = array_key_exists('auto_budget_currency_code', $data) ? $data['auto_budget_currency_code'] : null;
|
||||
if (is_numeric($type)) {
|
||||
$type = (int)$type;
|
||||
$type = (int) $type;
|
||||
}
|
||||
if ('' === $type || 0 === $type) {
|
||||
return;
|
||||
}
|
||||
// basic float check:
|
||||
if (!is_numeric($amount)) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (1 !== bccomp((string)$amount, '0')) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.auto_budget_amount_positive'));
|
||||
if (1 !== bccomp((string) $amount, '0')) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.auto_budget_amount_positive'));
|
||||
}
|
||||
if ('' === $period) {
|
||||
$validator->errors()->add('auto_budget_period', (string)trans('validation.auto_budget_period_mandatory'));
|
||||
$validator->errors()->add('auto_budget_period', (string) trans('validation.auto_budget_period_mandatory'));
|
||||
}
|
||||
if (null !== $currencyId && null !== $currencyCode && '' === $currencyCode && 0 === $currencyId) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.require_currency_info'));
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.require_currency_info'));
|
||||
}
|
||||
// too big amount
|
||||
if ((int)$amount > 268435456) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
if ((int) $amount > 268435456) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -88,7 +88,7 @@ trait RecurrenceValidation
|
||||
continue;
|
||||
}
|
||||
// validate source account.
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int) $transaction['source_id'] : null;
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$validSource = $accountValidator->validateSource(['id' => $sourceId, 'name' => $sourceName]);
|
||||
|
||||
@@ -100,7 +100,7 @@ trait RecurrenceValidation
|
||||
return;
|
||||
}
|
||||
// validate destination account
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int) $transaction['destination_id'] : null;
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
$validDestination = $accountValidator->validateDestination(['id' => $destinationId, 'name' => $destinationName]);
|
||||
// do something with result:
|
||||
@@ -122,7 +122,7 @@ trait RecurrenceValidation
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
// need at least one transaction
|
||||
if (!is_countable($repetitions) || 0 === count($repetitions)) {
|
||||
$validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition'));
|
||||
$validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ trait RecurrenceValidation
|
||||
}
|
||||
// need at least one transaction
|
||||
if (0 === count($repetitions)) {
|
||||
$validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition'));
|
||||
$validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,15 +153,15 @@ trait RecurrenceValidation
|
||||
$repeatUntil = $data['repeat_until'] ?? null;
|
||||
if (null !== $repetitions && null !== $repeatUntil) {
|
||||
// expect a date OR count:
|
||||
$validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('repeat_until', (string) trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string) trans('validation.require_repeat_until'));
|
||||
}
|
||||
}
|
||||
|
||||
public function validateRecurringConfig(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$reps = array_key_exists('nr_of_repetitions', $data) ? (int)$data['nr_of_repetitions'] : null;
|
||||
$reps = array_key_exists('nr_of_repetitions', $data) ? (int) $data['nr_of_repetitions'] : null;
|
||||
$repeatUntil = array_key_exists('repeat_until', $data) ? new Carbon($data['repeat_until']) : null;
|
||||
|
||||
if (null === $reps && null === $repeatUntil) {
|
||||
@@ -181,7 +181,7 @@ trait RecurrenceValidation
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
if (!is_array($repetitions)) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', 0), (string)trans('validation.valid_recurrence_rep_type'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', 0), (string) trans('validation.valid_recurrence_rep_type'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -200,32 +200,32 @@ trait RecurrenceValidation
|
||||
|
||||
switch ($repetition['type'] ?? 'empty') {
|
||||
default:
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', $index), (string)trans('validation.valid_recurrence_rep_type'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', $index), (string) trans('validation.valid_recurrence_rep_type'));
|
||||
|
||||
return;
|
||||
|
||||
case 'daily':
|
||||
$this->validateDaily($validator, $index, (string)$repetition['moment']);
|
||||
$this->validateDaily($validator, $index, (string) $repetition['moment']);
|
||||
|
||||
break;
|
||||
|
||||
case 'monthly':
|
||||
$this->validateMonthly($validator, $index, (int)$repetition['moment']);
|
||||
$this->validateMonthly($validator, $index, (int) $repetition['moment']);
|
||||
|
||||
break;
|
||||
|
||||
case 'ndom':
|
||||
$this->validateNdom($validator, $index, (string)$repetition['moment']);
|
||||
$this->validateNdom($validator, $index, (string) $repetition['moment']);
|
||||
|
||||
break;
|
||||
|
||||
case 'weekly':
|
||||
$this->validateWeekly($validator, $index, (int)$repetition['moment']);
|
||||
$this->validateWeekly($validator, $index, (int) $repetition['moment']);
|
||||
|
||||
break;
|
||||
|
||||
case 'yearly':
|
||||
$this->validateYearly($validator, $index, (string)$repetition['moment']);
|
||||
$this->validateYearly($validator, $index, (string) $repetition['moment']);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ trait RecurrenceValidation
|
||||
protected function validateDaily(Validator $validator, int $index, string $moment): void
|
||||
{
|
||||
if ('' !== $moment) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ trait RecurrenceValidation
|
||||
protected function validateMonthly(Validator $validator, int $index, int $dayOfMonth): void
|
||||
{
|
||||
if ($dayOfMonth < 1 || $dayOfMonth > 31) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,19 +260,19 @@ trait RecurrenceValidation
|
||||
{
|
||||
$parameters = explode(',', $moment);
|
||||
if (2 !== count($parameters)) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
|
||||
return;
|
||||
}
|
||||
$nthDay = (int)($parameters[0] ?? 0.0);
|
||||
$dayOfWeek = (int)($parameters[1] ?? 0.0);
|
||||
$nthDay = (int) ($parameters[0] ?? 0.0);
|
||||
$dayOfWeek = (int) ($parameters[1] ?? 0.0);
|
||||
if ($nthDay < 1 || $nthDay > 5) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
|
||||
return;
|
||||
}
|
||||
if ($dayOfWeek < 1 || $dayOfWeek > 7) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ trait RecurrenceValidation
|
||||
protected function validateWeekly(Validator $validator, int $index, int $dayOfWeek): void
|
||||
{
|
||||
if ($dayOfWeek < 1 || $dayOfWeek > 7) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,10 +295,13 @@ trait RecurrenceValidation
|
||||
Carbon::createFromFormat('Y-m-d', $moment);
|
||||
} catch (\InvalidArgumentException $e) { // @phpstan-ignore-line
|
||||
app('log')->debug(sprintf('Invalid argument for Carbon: %s', $e->getMessage()));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
protected function validateTransactionId(Recurrence $recurrence, Validator $validator): void
|
||||
{
|
||||
app('log')->debug('Now in validateTransactionId');
|
||||
@@ -307,7 +310,7 @@ trait RecurrenceValidation
|
||||
|
||||
if (0 === $submittedTrCount) {
|
||||
app('log')->warning('[b] User submitted no transactions.');
|
||||
$validator->errors()->add('transactions', (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions', (string) trans('validation.at_least_one_transaction'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -320,16 +323,16 @@ trait RecurrenceValidation
|
||||
return; // home safe!
|
||||
}
|
||||
$id = $first['id'];
|
||||
if ('' === (string)$id) {
|
||||
if ('' === (string) $id) {
|
||||
app('log')->debug('Single count and empty ID, done.');
|
||||
|
||||
return; // home safe!
|
||||
}
|
||||
$integer = (int)$id;
|
||||
$integer = (int) $id;
|
||||
$secondCount = $recurrence->recurrenceTransactions()->where('recurrences_transactions.id', $integer)->count();
|
||||
app('log')->debug(sprintf('Result of ID count: %d', $secondCount));
|
||||
if (0 === $secondCount) {
|
||||
$validator->errors()->add('transactions.0.id', (string)trans('validation.id_does_not_match', ['id' => $integer]));
|
||||
$validator->errors()->add('transactions.0.id', (string) trans('validation.id_does_not_match', ['id' => $integer]));
|
||||
}
|
||||
app('log')->debug('Single ID validation done.');
|
||||
|
||||
@@ -360,19 +363,19 @@ trait RecurrenceValidation
|
||||
app('log')->debug(sprintf('Now at %d/%d', $index + 1, $submittedTrCount));
|
||||
if (!is_array($transaction)) {
|
||||
app('log')->warning('Not an array. Give error.');
|
||||
$validator->errors()->add(sprintf('transactions.%d.id', $index), (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.id', $index), (string) trans('validation.at_least_one_transaction'));
|
||||
|
||||
return;
|
||||
}
|
||||
if (!array_key_exists('id', $transaction) && $idsMandatory) {
|
||||
app('log')->warning('ID is mandatory but array has no ID.');
|
||||
$validator->errors()->add(sprintf('transactions.%d.id', $index), (string)trans('validation.need_id_to_match'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.id', $index), (string) trans('validation.need_id_to_match'));
|
||||
|
||||
return;
|
||||
}
|
||||
if (array_key_exists('id', $transaction)) { // don't matter if $idsMandatory
|
||||
app('log')->debug('Array has ID.');
|
||||
$idCount = $recurrence->recurrenceTransactions()->where('recurrences_transactions.id', (int)$transaction['id'])->count();
|
||||
$idCount = $recurrence->recurrenceTransactions()->where('recurrences_transactions.id', (int) $transaction['id'])->count();
|
||||
if (0 === $idCount) {
|
||||
app('log')->debug('ID does not exist or no match. Count another unmatched ID.');
|
||||
++$unmatchedIds;
|
||||
@@ -388,7 +391,7 @@ trait RecurrenceValidation
|
||||
app('log')->debug(sprintf('Submitted: %d. Original: %d. User can submit %d unmatched transactions.', $submittedTrCount, $originalTrCount, $maxUnmatched));
|
||||
if ($unmatchedIds > $maxUnmatched) {
|
||||
app('log')->warning(sprintf('Too many unmatched transactions (%d).', $unmatchedIds));
|
||||
$validator->errors()->add('transactions.0.id', (string)trans('validation.too_many_unmatched'));
|
||||
$validator->errors()->add('transactions.0.id', (string) trans('validation.too_many_unmatched'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -109,7 +109,7 @@ trait TransactionValidation
|
||||
|
||||
// need at least one transaction
|
||||
if (0 === count($transactions)) {
|
||||
$validator->errors()->add('transactions', (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions', (string) trans('validation.at_least_one_transaction'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ trait TransactionValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
// need at least one transaction
|
||||
if (0 === count($transactions)) {
|
||||
$validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction'));
|
||||
app('log')->debug('Added error: at_least_one_transaction.');
|
||||
|
||||
return;
|
||||
@@ -143,7 +143,7 @@ trait TransactionValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
foreach (array_keys($transactions) as $key) {
|
||||
if (!is_int($key)) {
|
||||
$validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction'));
|
||||
app('log')->debug('Added error: at_least_one_transaction.');
|
||||
|
||||
return;
|
||||
@@ -168,13 +168,13 @@ trait TransactionValidation
|
||||
}
|
||||
$unique = array_unique($types);
|
||||
if (count($unique) > 1) {
|
||||
$validator->errors()->add('transactions.0.type', (string)trans('validation.transaction_types_equal'));
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal'));
|
||||
|
||||
return;
|
||||
}
|
||||
$first = $unique[0] ?? 'invalid';
|
||||
if ('invalid' === $first) {
|
||||
$validator->errors()->add('transactions.0.type', (string)trans('validation.invalid_transaction_type'));
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.invalid_transaction_type'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,14 +187,14 @@ trait TransactionValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
$types = [];
|
||||
foreach ($transactions as $transaction) {
|
||||
$originalType = $this->getOriginalType((int)($transaction['transaction_journal_id'] ?? 0));
|
||||
$originalType = $this->getOriginalType((int) ($transaction['transaction_journal_id'] ?? 0));
|
||||
// if type is not set, fall back to the type of the journal, if one is given.
|
||||
$types[] = $transaction['type'] ?? $originalType;
|
||||
}
|
||||
$unique = array_unique($types);
|
||||
if (count($unique) > 1) {
|
||||
app('log')->warning('Add error for mismatch transaction types.');
|
||||
$validator->errors()->add('transactions.0.type', (string)trans('validation.transaction_types_equal'));
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -217,6 +217,9 @@ trait TransactionValidation
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
protected function validateSingleAccount(Validator $validator, int $index, string $transactionType, array $transaction): void
|
||||
{
|
||||
app('log')->debug(sprintf('Now in validateSingleAccount(%d)', $index));
|
||||
@@ -235,10 +238,10 @@ trait TransactionValidation
|
||||
$accountValidator->setTransactionType($transactionType);
|
||||
|
||||
// validate source account.
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
|
||||
$sourceName = array_key_exists('source_name', $transaction) ? (string)$transaction['source_name'] : null;
|
||||
$sourceIban = array_key_exists('source_iban', $transaction) ? (string)$transaction['source_iban'] : null;
|
||||
$sourceNumber = array_key_exists('source_number', $transaction) ? (string)$transaction['source_number'] : null;
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int) $transaction['source_id'] : null;
|
||||
$sourceName = array_key_exists('source_name', $transaction) ? (string) $transaction['source_name'] : null;
|
||||
$sourceIban = array_key_exists('source_iban', $transaction) ? (string) $transaction['source_iban'] : null;
|
||||
$sourceNumber = array_key_exists('source_number', $transaction) ? (string) $transaction['source_number'] : null;
|
||||
$source = [
|
||||
'id' => $sourceId,
|
||||
'name' => $sourceName,
|
||||
@@ -255,10 +258,10 @@ trait TransactionValidation
|
||||
return;
|
||||
}
|
||||
// validate destination account
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationName = array_key_exists('destination_name', $transaction) ? (string)$transaction['destination_name'] : null;
|
||||
$destinationIban = array_key_exists('destination_iban', $transaction) ? (string)$transaction['destination_iban'] : null;
|
||||
$destinationNumber = array_key_exists('destination_number', $transaction) ? (string)$transaction['destination_number'] : null;
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int) $transaction['destination_id'] : null;
|
||||
$destinationName = array_key_exists('destination_name', $transaction) ? (string) $transaction['destination_name'] : null;
|
||||
$destinationIban = array_key_exists('destination_iban', $transaction) ? (string) $transaction['destination_iban'] : null;
|
||||
$destinationNumber = array_key_exists('destination_number', $transaction) ? (string) $transaction['destination_number'] : null;
|
||||
$destination = [
|
||||
'id' => $destinationId,
|
||||
'name' => $destinationName,
|
||||
@@ -335,7 +338,7 @@ trait TransactionValidation
|
||||
|| array_key_exists('source_number', $transaction)
|
||||
) {
|
||||
app('log')->debug('Will try to validate source account information.');
|
||||
$sourceId = (int)($transaction['source_id'] ?? 0);
|
||||
$sourceId = (int) ($transaction['source_id'] ?? 0);
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$sourceIban = $transaction['source_iban'] ?? null;
|
||||
$sourceNumber = $transaction['source_number'] ?? null;
|
||||
@@ -374,7 +377,7 @@ trait TransactionValidation
|
||||
$accountValidator->source = $source;
|
||||
}
|
||||
}
|
||||
$destinationId = (int)($transaction['destination_id'] ?? 0);
|
||||
$destinationId = (int) ($transaction['destination_id'] ?? 0);
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
$destinationIban = $transaction['destination_iban'] ?? null;
|
||||
$destinationNumber = $transaction['destination_number'] ?? null;
|
||||
@@ -395,6 +398,7 @@ trait TransactionValidation
|
||||
* TODO describe this method.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
private function sanityCheckForeignCurrency(
|
||||
Validator $validator,
|
||||
@@ -455,17 +459,17 @@ trait TransactionValidation
|
||||
|
||||
// no foreign currency information is present:
|
||||
if (!$this->hasForeignCurrencyInfo($transaction)) {
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string)trans('validation.require_foreign_currency'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string) trans('validation.require_foreign_currency'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// wrong currency information is present
|
||||
$foreignCurrencyCode = $transaction['foreign_currency_code'] ?? false;
|
||||
$foreignCurrencyId = (int)($transaction['foreign_currency_id'] ?? 0);
|
||||
$foreignCurrencyId = (int) ($transaction['foreign_currency_id'] ?? 0);
|
||||
app('log')->debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction);
|
||||
if ($foreignCurrencyCode !== $sourceCurrency->code && $foreignCurrencyId !== $sourceCurrency->id) {
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_currency_code', $index), (string)trans('validation.require_foreign_src'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_currency_code', $index), (string) trans('validation.require_foreign_src'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -482,19 +486,19 @@ trait TransactionValidation
|
||||
|
||||
// no foreign currency information is present:
|
||||
if (!$this->hasForeignCurrencyInfo($transaction)) {
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string)trans('validation.require_foreign_currency'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string) trans('validation.require_foreign_currency'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// wrong currency information is present
|
||||
$foreignCurrencyCode = $transaction['foreign_currency_code'] ?? false;
|
||||
$foreignCurrencyId = (int)($transaction['foreign_currency_id'] ?? 0);
|
||||
$foreignCurrencyId = (int) ($transaction['foreign_currency_id'] ?? 0);
|
||||
app('log')->debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction);
|
||||
if ($foreignCurrencyCode !== $destinationCurrency->code && $foreignCurrencyId !== $destinationCurrency->id) {
|
||||
app('log')->debug(sprintf('No match on code, "%s" vs "%s"', $foreignCurrencyCode, $destinationCurrency->code));
|
||||
app('log')->debug(sprintf('No match on ID, #%d vs #%d', $foreignCurrencyId, $destinationCurrency->id));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string)trans('validation.require_foreign_dest'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string) trans('validation.require_foreign_dest'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -541,7 +545,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);
|
||||
}
|
||||
|
||||
private function getOriginalSource(array $transaction, TransactionGroup $transactionGroup): ?Account
|
||||
@@ -554,7 +558,7 @@ trait TransactionValidation
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($transactionGroup->transactionJournals as $journal) {
|
||||
$journalId = (int)($transaction['transaction_journal_id'] ?? 0);
|
||||
$journalId = (int) ($transaction['transaction_journal_id'] ?? 0);
|
||||
if ($journal->id === $journalId) {
|
||||
return $journal->transactions()->where('amount', '<', 0)->first()?->account;
|
||||
}
|
||||
@@ -604,22 +608,22 @@ trait TransactionValidation
|
||||
default:
|
||||
case 'withdrawal':
|
||||
if (count($sources) > 1) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'deposit':
|
||||
if (count($dests) > 1) {
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case'transfer':
|
||||
if (count($sources) > 1 || count($dests) > 1) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -653,14 +657,14 @@ trait TransactionValidation
|
||||
$result = $this->compareAccountData($type, $comparison);
|
||||
if (false === $result) {
|
||||
if ('withdrawal' === $type) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
if ('deposit' === $type) {
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
if ('transfer' === $type) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
app('log')->warning('Add error about equal accounts.');
|
||||
|
||||
@@ -679,7 +683,7 @@ trait TransactionValidation
|
||||
/** @var array $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
// source or destination may be omitted. If this is the case, use the original source / destination name + ID.
|
||||
$originalData = $this->getOriginalData((int)($transaction['transaction_journal_id'] ?? 0));
|
||||
$originalData = $this->getOriginalData((int) ($transaction['transaction_journal_id'] ?? 0));
|
||||
|
||||
// get field.
|
||||
$comparison[$field][] = $transaction[$field] ?? $originalData[$field];
|
||||
|
@@ -527,6 +527,7 @@ class CreateMainTables extends Migration
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
private function createTransactionTables(): void
|
||||
{
|
||||
|
@@ -125,6 +125,7 @@ class ChangesForV550 extends Migration
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
|
Reference in New Issue
Block a user