Various issues fixed (SonarQube)

This commit is contained in:
James Cole 2020-10-26 19:15:57 +01:00
parent e4923a3c69
commit 372c6ac667
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
57 changed files with 86 additions and 221 deletions

View File

@ -82,10 +82,9 @@ class TransactionStoreRequest extends FormRequest
{
$return = [];
/**
* @var int $index
* @var array $transaction
*/
foreach ($this->get('transactions') as $index => $transaction) {
foreach ($this->get('transactions') as $transaction) {
$object = new NullArrayObject($transaction);
$return[] = [
'type' => $this->stringFromValue($object['type']),

View File

@ -63,7 +63,6 @@ class TransactionJournalFactory
private array $fields;
private PiggyBankEventFactory $piggyEventFactory;
private PiggyBankRepositoryInterface $piggyRepository;
private TransactionFactory $transactionFactory;
private TransactionTypeRepositoryInterface $typeRepository;
private User $user;

View File

@ -155,7 +155,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
return [
'journals' => $journals,
'currency' => $currency,
'exists' => count($journals) > 0,
'exists' => !empty($journals),
'end' => $this->end->formatLocalized((string) trans('config.month_and_day', [], $locale)),
'endBalance' => app('steam')->balance($account, $this->end),
'dayBefore' => $date->formatLocalized((string) trans('config.month_and_day', [], $locale)),

View File

@ -224,7 +224,7 @@ class AttachmentHelper implements AttachmentHelperInterface
}
Log::debug('Done processing uploads.');
}
if (!is_array($files) || (is_array($files) && 0 === count($files))) {
if (!is_array($files) || empty($files)) {
Log::debug('Array of files is not an array. Probably nothing uploaded. Will not store attachments.');
}

View File

@ -267,7 +267,7 @@ class GroupCollector implements GroupCollectorInterface
*/
public function setJournalIds(array $journalIds): GroupCollectorInterface
{
if (count($journalIds) > 0) {
if (!empty($journalIds)) {
$this->query->whereIn('transaction_journals.id', $journalIds);
}

View File

@ -116,7 +116,7 @@ class LoginController extends Controller
$this->incrementLoginAttempts($request);
Log::channel('audit')->info(sprintf('Login failed. Attempt for user "%s" failed.', $request->get('email')));
return $this->sendFailedLoginResponse($request);
$this->sendFailedLoginResponse($request);
}
/**

View File

@ -264,10 +264,9 @@ class IndexController extends Controller
return [];
}
/**
* @var int $objectGroupId
* @var array $array
*/
foreach ($sums as $objectGroupId => $array) {
foreach ($sums as $array) {
/**
* @var int $currencyId
* @var array $entry

View File

@ -50,16 +50,11 @@ class BudgetController extends Controller
{
use DateCalculation, AugumentData;
/** @var GeneratorInterface Chart generation methods. */
protected $generator;
/** @var OperationsRepositoryInterface */
protected $opsRepository;
/** @var BudgetRepositoryInterface The budget repository */
protected $repository;
/** @var BudgetLimitRepositoryInterface */
private $blRepository;
/** @var NoBudgetRepositoryInterface */
private $nbRepository;
protected GeneratorInterface $generator;
protected OperationsRepositoryInterface $opsRepository;
protected BudgetRepositoryInterface $repository;
private BudgetLimitRepositoryInterface $blRepository;
private NoBudgetRepositoryInterface $nbRepository;
/**
* BudgetController constructor.
@ -185,12 +180,12 @@ class BudgetController extends Controller
while ($start <= $end) {
$spent = $this->opsRepository->spentInPeriod($budgetCollection, new Collection, $start, $start);
$amount = bcadd($amount, $spent);
$format = $start->formatLocalized((string) trans('config.month_and_day', [], $locale));
$format = $start->formatLocalized((string)trans('config.month_and_day', [], $locale));
$entries[$format] = $amount;
$start->addDay();
}
$data = $this->generator->singleSet((string) trans('firefly.left'), $entries);
$data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
// add currency symbol from budget limit:
$data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol;
$data['datasets'][0]['currency_code'] = $budgetLimit->transactionCurrency->code;
@ -239,7 +234,7 @@ class BudgetController extends Controller
// group by asset account ID:
foreach ($journals as $journal) {
$key = sprintf('%d-%d', (int) $journal['source_account_id'], $journal['currency_id']);
$key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']);
$result[$key] = $result[$key] ?? [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
@ -252,7 +247,7 @@ class BudgetController extends Controller
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$assetId = (int) $parts[0];
$assetId = (int)$parts[0];
$title = sprintf('%s (%s)', $names[$assetId] ?? '(empty)', $info['currency_name']);
$chartData[$title]
= [
@ -319,7 +314,7 @@ class BudgetController extends Controller
$names = $this->getCategoryNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$categoryId = (int) $parts[0];
$categoryId = (int)$parts[0];
$title = sprintf('%s (%s)', $names[$categoryId] ?? '(empty)', $info['currency_name']);
$chartData[$title] = [
'amount' => $info['amount'],
@ -385,7 +380,7 @@ class BudgetController extends Controller
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$opposingId = (int) $parts[0];
$opposingId = (int)$parts[0];
$name = $names[$opposingId] ?? 'no name';
$title = sprintf('%s (%s)', $name, $info['currency_name']);
$chartData[$title] = [
@ -422,12 +417,12 @@ class BudgetController extends Controller
return response()->json($cache->get()); // @codeCoverageIgnore
}
$generator = app(FrontpageChartGenerator::class);
$generator->setUser(auth()->user());
$generator->setStart($start);
$generator->setEnd($end);
$chartGenerator = app(FrontpageChartGenerator::class);
$chartGenerator->setUser(auth()->user());
$chartGenerator->setStart($start);
$chartGenerator->setEnd($end);
$chartData = $generator->generate();
$chartData = $chartGenerator->generate();
$data = $this->generator->multiSet($chartData);
$cache->store($data);
@ -463,14 +458,14 @@ class BudgetController extends Controller
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$chartData = [
[
'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency->name]),
'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency->name]),
'type' => 'bar',
'entries' => [],
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
],
[
'label' => (string) trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]),
'label' => (string)trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]),
'type' => 'bar',
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
@ -549,7 +544,7 @@ class BudgetController extends Controller
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
}
$data = $this->generator->singleSet((string) trans('firefly.spent'), $chartData);
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
$cache->store($data);
return response()->json($data);

View File

@ -187,7 +187,7 @@ class ExpenseReportController extends Controller
$newSet[$key] = $chartData[$key]; // @codeCoverageIgnore
}
}
if (0 === count($newSet)) {
if (empty($newSet)) {
$newSet = $chartData; // @codeCoverageIgnore
}
$data = $this->generator->multiSet($newSet);

View File

@ -193,7 +193,7 @@ class BoxController extends Controller
$incomes[$currencyId] = app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false);
$expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false);
}
if (0 === count($sums)) {
if (empty($sums)) {
$currency = app('amount')->getDefaultCurrency();
$sums[$currency->id] = app('amount')->formatAnything($currency, '0', false);
$incomes[$currency->id] = app('amount')->formatAnything($currency, '0', false);
@ -257,7 +257,7 @@ class BoxController extends Controller
$return = [];
foreach ($netWorthSet as $index => $data) {
foreach ($netWorthSet as $data) {
/** @var TransactionCurrency $currency */
$currency = $data['currency'];
$return[$currency->id] = app('amount')->formatAnything($currency, $data['balance'], false);

View File

@ -64,7 +64,7 @@ class FrontpageController extends Controller
}
}
$html = '';
if (count($info) > 0) {
if (!empty($info)) {
try {
$html = view('json.piggy-banks', compact('info'))->render();
// @codeCoverageIgnoreStart

View File

@ -67,8 +67,6 @@ class EditController extends Controller
{
$subTitle = (string) trans('firefly.edit_object_group', ['title' => $objectGroup->title]);
$subTitleIcon = 'fa-pencil';
$targetDate = null;
$startDate = null;
if (true !== session('object-groups.edit.fromUpdate')) {
$this->rememberPreviousUri('object-groups.edit.uri');

View File

@ -165,7 +165,6 @@ class BudgetController extends Controller
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$destinationId = $journal['destination_account_id'];
@ -328,7 +327,6 @@ class BudgetController extends Controller
foreach ($expenses as $currency) {
foreach ($currency['budgets'] as $budget) {
$count = 0;
$total = '0';
foreach ($budget['transaction_journals'] as $journal) {
$count++;
$key = sprintf('%d-%d', $budget['id'], $currency['currency_id']);
@ -377,7 +375,6 @@ class BudgetController extends Controller
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$result[] = [

View File

@ -40,10 +40,7 @@ use Throwable;
*/
class TagController extends Controller
{
/** @var OperationsRepositoryInterface */
private $opsRepository;
private OperationsRepositoryInterface $opsRepository;
/**
* ExpenseReportController constructor.
@ -282,7 +279,6 @@ class TagController extends Controller
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
$result = [];
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
$destinationId = $journal['destination_account_id'];
@ -335,7 +331,6 @@ class TagController extends Controller
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$result = [];
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
$sourceId = $journal['source_account_id'];
@ -496,7 +491,6 @@ class TagController extends Controller
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
$result = [];
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
$result[] = [
@ -546,7 +540,6 @@ class TagController extends Controller
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$result = [];
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
$result[] = [

View File

@ -242,17 +242,15 @@ class ConvertController extends Controller
private function getAssetAccounts(): array
{
// make repositories
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountList = $accountRepository->getActiveAccountsByType([AccountType::ASSET]);
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::ASSET]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$balance = app('steam')->balance($account, today());
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = (string)$accountRepository->getMetaValue($account, 'account_role');
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore
}
@ -271,16 +269,14 @@ class ConvertController extends Controller
private function getLiabilities(): array
{
// make repositories
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountList = $accountRepository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$balance = app('steam')->balance($account, today());
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = 'l_' . $account->accountType->type;
$key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
@ -295,16 +291,14 @@ class ConvertController extends Controller
private function getValidDepositSources(): array
{
// make repositories
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
$accountList = $accountRepository
$accountList = $this->accountRepository
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$role = (string)$accountRepository->getMetaValue($account, 'account_role');
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore
@ -337,17 +331,15 @@ class ConvertController extends Controller
private function getValidWithdrawalDests(): array
{
// make repositories
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
$accountList = $accountRepository->getActiveAccountsByType(
$accountList = $this->accountRepository->getActiveAccountsByType(
[AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]
);
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$role = (string)$accountRepository->getMetaValue($account, 'account_role');
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore

View File

@ -171,7 +171,7 @@ class ShowController extends Controller
{
$accounts = [];
foreach ($group['transactions'] as $index => $transaction) {
foreach ($group['transactions'] as $transaction) {
$accounts['source'][] = [
'type' => $transaction['source_type'],
'id' => $transaction['source_id'],

View File

@ -354,17 +354,7 @@ class CreateRecurringTransactions implements ShouldQueue
$includeWeekend = clone $this->date;
$includeWeekend->addDays(2);
$occurrences = $this->repository->getOccurrencesInRange($repetition, $recurrence->first_date, $includeWeekend);
/*
Log::debug(
sprintf(
'Calculated %d occurrences between %s and %s',
count($occurrences),
$recurrence->first_date->format('Y-m-d'),
$includeWeekend->format('Y-m-d')
),
$this->debugArray($occurrences)
);
*/
unset($includeWeekend);
$result = $this->handleOccurrences($recurrence, $repetition, $occurrences);

View File

@ -70,12 +70,6 @@ class ReportNewJournalsMail extends Mailable
*/
public function build(): self
{
$subject = 1 === $this->groups->count()
? 'Firefly III has created a new transaction'
: sprintf(
'Firefly III has created new %d transactions',
$this->groups->count()
);
$this->transform();
return $this->view('emails.report-new-journals-html')->text('emails.report-new-journals-text')

View File

@ -355,7 +355,7 @@ class TransactionJournal extends Model
if (!self::isJoined($query, 'transaction_types')) {
$query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
}
if (count($types) > 0) {
if (!empty($types)) {
$query->whereIn('transaction_types.type', $types);
}
}

View File

@ -128,7 +128,7 @@ class AccountRepository implements AccountRepositoryInterface
->where('account_meta.name', 'account_number')
->where('account_meta.data', json_encode($number));
if (count($types) > 0) {
if (!empty($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@ -152,7 +152,7 @@ class AccountRepository implements AccountRepositoryInterface
{
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (count($types) > 0) {
if (!empty($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@ -180,7 +180,7 @@ class AccountRepository implements AccountRepositoryInterface
{
$query = $this->user->accounts();
if (count($types) > 0) {
if (!empty($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@ -260,7 +260,7 @@ class AccountRepository implements AccountRepositoryInterface
/** @var Collection $result */
$query = $this->user->accounts();
if (count($accountIds) > 0) {
if (!empty($accountIds)) {
$query->whereIn('accounts.id', $accountIds);
}
$query->orderBy('accounts.order', 'ASC');
@ -279,7 +279,7 @@ class AccountRepository implements AccountRepositoryInterface
{
/** @var Collection $result */
$query = $this->user->accounts();
if (count($types) > 0) {
if (!empty($types)) {
$query->accountTypeIn($types);
}
$query->orderBy('accounts.order', 'ASC');
@ -303,7 +303,7 @@ class AccountRepository implements AccountRepositoryInterface
$query->where('name', 'account_role');
}, 'attachments']
);
if (count($types) > 0) {
if (!empty($types)) {
$query->accountTypeIn($types);
}
$query->where('active', 1);
@ -572,7 +572,7 @@ class AccountRepository implements AccountRepositoryInterface
}
}
if (count($types) > 0) {
if (!empty($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$dbQuery->whereIn('account_types.type', $types);
}
@ -630,7 +630,7 @@ class AccountRepository implements AccountRepositoryInterface
$query->where('name', 'account_role');
}]
);
if (count($types) > 0) {
if (!empty($types)) {
$query->accountTypeIn($types);
}
$query->where('active', 0);
@ -728,7 +728,7 @@ class AccountRepository implements AccountRepositoryInterface
});
}
}
if (count($types) > 0) {
if (!empty($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$dbQuery->whereIn('account_types.type', $types);
}

View File

@ -157,7 +157,6 @@ class BudgetRepository implements BudgetRepositoryInterface
*/
public function firstUseDate(Budget $budget): ?Carbon
{
$oldest = null;
$journal = $budget->transactionJournals()->orderBy('date', 'ASC')->first();
if (null !== $journal) {
return $journal->date;

View File

@ -215,7 +215,6 @@ class JournalRepository implements JournalRepositoryInterface
*/
public function getLinkNoteText(TransactionJournalLink $link): string
{
$notes = null;
/** @var Note $note */
$note = $link->notes()->first();
if (null !== $note) {

View File

@ -60,7 +60,6 @@ trait CreatesObjectGroups
*/
protected function findOrCreateObjectGroup(string $title): ?ObjectGroup
{
$group = null;
$maxOrder = $this->getObjectGroupMaxOrder();
if (!$this->hasObjectGroup($title)) {
return ObjectGroup::create(

View File

@ -327,7 +327,7 @@ class RecurringRepository implements RecurringRepositoryInterface
foreach ($journalMeta as $journalId) {
$search[] = (int)$journalId;
}
if (0 === count($search)) {
if (empty($search)) {
return new Collection;
}

View File

@ -476,7 +476,6 @@ class TagRepository implements TagRepositoryInterface
*/
public function update(Tag $tag, array $data): Tag
{
$oldTag = $data['tag'];
$tag->tag = $data['tag'];
$tag->date = $data['date'];
$tag->description = $data['description'];

View File

@ -275,7 +275,7 @@ trait RecurringTransactionTrait
*/
protected function updateTags(RecurrenceTransaction $transaction, array $tags): void
{
if (count($tags) > 0) {
if (!empty($tags)) {
/** @var RecurrenceMeta $entry */
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'tags')->first();
if (null === $entry) {
@ -284,7 +284,7 @@ trait RecurringTransactionTrait
$entry->value = json_encode($tags);
$entry->save();
}
if (0 === count($tags)) {
if (empty($tags)) {
// delete if present
$transaction->recurrenceTransactionMeta()->where('name', 'tags')->delete();
}

View File

@ -76,10 +76,6 @@ class JournalUpdateService
private $transactionGroup;
/** @var TransactionJournal The journal to update. */
private $transactionJournal;
/** @var Account If new account info is submitted, this array will hold the valid destination. */
private $validDestination;
/** @var Account If new account info is submitted, this array will hold the valid source. */
private $validSource;
/**
* JournalUpdateService constructor.

View File

@ -41,8 +41,7 @@ class RecurrenceUpdateService
{
use TransactionTypeTrait, RecurringTransactionTrait;
/** @var User */
private $user;
private User $user;
/**
* Updates a recurrence.
@ -99,7 +98,7 @@ class RecurrenceUpdateService
$this->createRepetitions($recurrence, $data['repetitions'] ?? []);
}
// update all transactions (and associated meta-data);
// update all transactions (and associated meta-data)
if (null !== $data['transactions']) {
$this->deleteTransactions($recurrence);
$this->createTransactions($recurrence, $data['transactions'] ?? []);

View File

@ -57,8 +57,6 @@ class WholePeriodChartGenerator
public function generate(Category $category, Carbon $start, Carbon $end): array
{
$collection = new Collection([$category]);
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);

View File

@ -717,7 +717,7 @@ class ExportDataGenerator
*/
private function mergeTags(array $tags): string
{
if (0 === count($tags)) {
if (empty($tags)) {
return '';
}
$smol = [];

View File

@ -129,7 +129,7 @@ trait RequestInformation
$triggers = [];
$data = $request->get('triggers');
if (is_array($data)) {
foreach ($data as $index => $triggerInfo) {
foreach ($data as $triggerInfo) {
$triggers[] = [
'type' => $triggerInfo['type'] ?? '',
'value' => $triggerInfo['value'] ?? '',

View File

@ -154,9 +154,9 @@ class BudgetReportGenerator
*/
private function generalBudgetReport(): void
{
$budgets = $this->repository->getBudgets();
$budgetList = $this->repository->getBudgets();
/** @var Budget $budget */
foreach ($budgets as $budget) {
foreach ($budgetList as $budget) {
$this->processBudget($budget);
}
}
@ -192,14 +192,14 @@ class BudgetReportGenerator
*/
private function processLimit(Budget $budget, BudgetLimit $limit): void
{
$budgetId = (int)$budget->id;
$limitId = (int)$limit->id;
$currency = $limit->transactionCurrency ?? $this->currency;
$currencyId = (int)$currency->id;
$expenses = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, $this->accounts, new Collection([$budget]));
$spent = $expenses[$currencyId]['sum'] ?? '0';
$left = -1 === bccomp(bcadd($limit->amount, $spent), '0') ? '0' : bcadd($limit->amount, $spent);
$overspent = 1 === bccomp(bcmul($spent, '-1'), $limit->amount) ? bcadd($spent, $limit->amount) : '0';
$budgetId = (int)$budget->id;
$limitId = (int)$limit->id;
$limitCurrency = $limit->transactionCurrency ?? $this->currency;
$currencyId = (int)$limitCurrency->id;
$expenses = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, $this->accounts, new Collection([$budget]));
$spent = $expenses[$currencyId]['sum'] ?? '0';
$left = -1 === bccomp(bcadd($limit->amount, $spent), '0') ? '0' : bcadd($limit->amount, $spent);
$overspent = 1 === bccomp(bcmul($spent, '-1'), $limit->amount) ? bcadd($spent, $limit->amount) : '0';
$this->report['budgets'][$budgetId]['budget_limits'][$limitId] = $this->report['budgets'][$budgetId]['budget_limits'][$limitId] ?? [
'budget_limit_id' => $limitId,
@ -212,10 +212,10 @@ class BudgetReportGenerator
'left' => $left,
'overspent' => $overspent,
'currency_id' => $currencyId,
'currency_code' => $currency->code,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'currency_code' => $limitCurrency->code,
'currency_name' => $limitCurrency->name,
'currency_symbol' => $limitCurrency->symbol,
'currency_decimal_places' => $limitCurrency->decimal_places,
];
// make sum information:
@ -226,10 +226,10 @@ class BudgetReportGenerator
'left' => '0',
'overspent' => '0',
'currency_id' => $currencyId,
'currency_code' => $currency->code,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'currency_code' => $limitCurrency->code,
'currency_name' => $limitCurrency->name,
'currency_symbol' => $limitCurrency->symbol,
'currency_decimal_places' => $limitCurrency->decimal_places,
];
$this->report['sums'][$currencyId]['budgeted'] = bcadd($this->report['sums'][$currencyId]['budgeted'], $limit->amount);
$this->report['sums'][$currencyId]['spent'] = bcadd($this->report['sums'][$currencyId]['spent'], $spent);

View File

@ -36,14 +36,14 @@ $factory->state(TransactionJournal::class, 'ob_broken', function ($faker) {
$factory->afterCreatingState(TransactionJournal::class, TransactionType::OPENING_BALANCE, function ($journal, $faker) {
$obAccount = factory(Account::class)->state(AccountType::INITIAL_BALANCE)->create();
$assetAccount = factory(Account::class)->state(AccountType::ASSET)->create();
$sourceTransaction = factory(Transaction::class)->create(
factory(Transaction::class)->create(
[
'account_id' => $obAccount->id,
'transaction_journal_id' => $journal->id,
'amount' => '5',
]);
$destTransaction = factory(Transaction::class)->create(
factory(Transaction::class)->create(
[
'account_id' => $assetAccount->id,
'transaction_journal_id' => $journal->id,
@ -55,14 +55,14 @@ $factory->afterCreatingState(TransactionJournal::class, 'ob_broken', function ($
$ob1 = factory(Account::class)->state(AccountType::INITIAL_BALANCE)->create();
$ob2 = factory(Account::class)->state(AccountType::INITIAL_BALANCE)->create();
$sourceTransaction = factory(Transaction::class)->create(
factory(Transaction::class)->create(
[
'account_id' => $ob1->id,
'transaction_journal_id' => $journal->id,
'amount' => '5',
]);
$destTransaction = factory(Transaction::class)->create(
factory(Transaction::class)->create(
[
'account_id' => $ob2->id,
'transaction_journal_id' => $journal->id,

View File

@ -43,7 +43,3 @@ export default {
name: "ProfileOptions"
}
</script>
<style scoped>
</style>

View File

@ -245,7 +245,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -151,7 +151,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -106,7 +106,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -105,7 +105,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -168,7 +168,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -72,7 +72,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -72,7 +72,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -131,7 +131,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -71,7 +71,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -1046,7 +1046,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -213,7 +213,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -73,7 +73,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -116,7 +116,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -75,7 +75,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -105,7 +105,3 @@ export default {
},
}
</script>
<style scoped>
</style>

View File

@ -155,7 +155,3 @@ export default {
}
}
</script>
<style scoped>
</style>

View File

@ -84,7 +84,3 @@ export default {
name: "TransactionType"
}
</script>
<style scoped>
</style>

View File

@ -176,7 +176,7 @@
{# Moment JS #}
<script src="v1/js/lib/moment.min.js?v={{ FF_VERSION }}" type="text/javascript" nonce="{{ JS_NONCE }}"></script>
<script src="v1/js/ff/moment/{{ language }}.js?v={{ FF_VERSION }}" type="text/javascript" nonce="{{ JS_NONCE }}"></script>
<script src="v1/js/lib/moment/{{ language }}.js?v={{ FF_VERSION }}" type="text/javascript" nonce="{{ JS_NONCE }}"></script>
{# All kinds of variables. #}
<script src="{{ route('javascript.variables') }}?ext=.js&amp;v={{ FF_VERSION }}{% if account %}&amp;account={{ account.id }}{% endif %}" type="text/javascript" nonce="{{ JS_NONCE }}"></script>

View File

@ -1143,7 +1143,7 @@ try {
Breadcrumbs::register(
'transactions.mass.edit',
static function (BreadcrumbsGenerator $breadcrumbs, array $journals): void {
if (count($journals) > 0) {
if (!empty($journals)) {
$objectType = strtolower(reset($journals)['transaction_type_type']);
$breadcrumbs->parent('transactions.index', $objectType);
$breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', ['']));
@ -1167,7 +1167,7 @@ try {
Breadcrumbs::register(
'transactions.bulk.edit',
static function (BreadcrumbsGenerator $breadcrumbs, array $journals): void {
if (count($journals) > 0) {
if (!empty($journals)) {
$ids = Arr::pluck($journals, 'transaction_journal_id');
$first = reset($journals);
$breadcrumbs->parent('transactions.index', strtolower($first['transaction_type_type']));

View File

@ -59,7 +59,7 @@ class CorrectOpeningBalanceCurrenciesTest extends TestCase
public function testHandleBroken(): void
{
// create opening balance journal for test. Is enough to trigger this test.
$journal = factory(TransactionJournal::class)->state(TransactionType::OPENING_BALANCE)->create();
factory(TransactionJournal::class)->state(TransactionType::OPENING_BALANCE)->create();
// run command
$this->artisan('firefly-iii:fix-ob-currencies')

View File

@ -300,7 +300,6 @@ class FixAccountTypesTest extends TestCase
$newSource = $this->getRandomRevenue();
$destination = $this->getRandomAsset();
$withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$deposit = TransactionType::where('type', TransactionType::DEPOSIT)->first();
$journal = TransactionJournal::create(
[

View File

@ -34,14 +34,7 @@ class FixTransactionTypesTest extends TestCase
*/
public function testHandle(): void
{
$this->artisan('firefly-iii:fix-transaction-types')
->expectsOutput(sprintf('Recurring transaction #%d should be a "%s" but is a "%s" and will be corrected.',
1, 'Withdrawal','Transfer',
))
->assertExitCode(0);
$this->markTestIncomplete();
}

View File

@ -34,7 +34,7 @@ use Tests\Traits\TestHelpers;
*/
abstract class TestCase extends BaseTestCase
{
use CreatesApplication, CollectsValues;//, MocksDefaultValues, TestHelpers, ;
use CreatesApplication, CollectsValues; // MocksDefaultValues TestHelpers
/**
* @return array