Skip to content

Firefly III: a personal finances manager

Some code cleanup.

James Cole49af6522a82e
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php
index 543fe47f12..4f9d8b6675 100755
--- a/app/Exceptions/Handler.php
+++ b/app/Exceptions/Handler.php
@@ -108,7 +108,8 @@ class Handler extends ExceptionHandler
/**
* Convert an authentication exception into an unauthenticated response.
*
- * @param \Illuminate\Http\Request $request
+ * @param \Illuminate\Http\Request $request
+ *
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request)
diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php
index cab8f39f18..d13dd53b70 100644
--- a/app/Helpers/Report/ReportHelper.php
+++ b/app/Helpers/Report/ReportHelper.php
@@ -257,17 +257,17 @@ class ReportHelper implements ReportHelperInterface
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
->where(
- // source.account_id in accountIds XOR destination.account_id in accountIds
- function (Builder $sourceXorDestinationQuery) use ($ids) {
- $sourceXorDestinationQuery->where(
- function (Builder $inSourceButNotDestinationQuery) use ($ids) {
- $inSourceButNotDestinationQuery->whereIn('source.account_id', $ids)
- ->whereNotIn('destination.account_id', $ids);
+ // source.account_id in accountIds XOR destination.account_id in accountIds
+ function (Builder $query) use ($ids) {
+ $query->where(
+ function (Builder $q1) use ($ids) {
+ $q1->whereIn('source.account_id', $ids)
+ ->whereNotIn('destination.account_id', $ids);
}
)->orWhere(
- function (Builder $inDestinationButNotSourceQuery) use ($ids) {
- $inDestinationButNotSourceQuery->whereIn('destination.account_id', $ids)
- ->whereNotIn('source.account_id', $ids);
+ function (Builder $q2) use ($ids) {
+ $q2->whereIn('destination.account_id', $ids)
+ ->whereNotIn('source.account_id', $ids);
}
);
}
diff --git a/app/Import/Converter/Amount.php b/app/Import/Converter/Amount.php
index bf15ad63ab..6b64a2b862 100644
--- a/app/Import/Converter/Amount.php
+++ b/app/Import/Converter/Amount.php
@@ -41,7 +41,7 @@ class Amount extends BasicConverter implements ConverterInterface
}
if ($len > 2 && $value{$decimalPosition} == ',') {
$decimal = ',';
- }
+ }
// if decimal is dot, replace all comma's and spaces with nothing. then parse as float (round to 4 pos)
if ($decimal === '.') {
diff --git a/app/Models/Preference.php b/app/Models/Preference.php
index 6bedbdd24a..cebb90f2c2 100644
--- a/app/Models/Preference.php
+++ b/app/Models/Preference.php
@@ -44,7 +44,7 @@ class Preference extends Model
{
protected $dates = ['created_at', 'updated_at'];
- protected $fillable = ['user_id', 'data', 'name','data'];
+ protected $fillable = ['user_id', 'data', 'name', 'data'];
/**
* @param $value
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index e8b9364705..fd5e695e25 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -22,8 +22,8 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\User;
-use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
use Steam;
@@ -415,23 +415,23 @@ class AccountRepository implements AccountRepositoryInterface
}
);
$query->where(
- // source.account_id in accountIds XOR destination.account_id in accountIds
- function (Builder $sourceXorDestinationQuery) use ($accountIds) {
- $sourceXorDestinationQuery->where(
- function (Builder $inSourceButNotDestinationQuery) use ($accountIds) {
- $inSourceButNotDestinationQuery->whereIn('source.account_id', $accountIds)
- ->whereNotIn('destination.account_id', $accountIds);
+ // source.account_id in accountIds XOR destination.account_id in accountIds
+ function (Builder $query) use ($accountIds) {
+ $query->where(
+ function (Builder $q1) use ($accountIds) {
+ $q1->whereIn('source.account_id', $accountIds)
+ ->whereNotIn('destination.account_id', $accountIds);
}
)->orWhere(
- function (Builder $inDestinationButNotSourceQuery) use ($accountIds) {
- $inDestinationButNotSourceQuery->whereIn('destination.account_id', $accountIds)
- ->whereNotIn('source.account_id', $accountIds);
+ function (Builder $q2) use ($accountIds) {
+ $q2->whereIn('destination.account_id', $accountIds)
+ ->whereNotIn('source.account_id', $accountIds);
}
);
}
);
}
-
+
// that should do it:
$fields = TransactionJournal::queryFields();
$complete = $query->get($fields);
diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php
index 51e1f37a48..7d7e24dc52 100644
--- a/app/Repositories/Budget/BudgetRepository.php
+++ b/app/Repositories/Budget/BudgetRepository.php
@@ -22,8 +22,8 @@ use FireflyIII\Models\LimitRepetition;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\User;
-use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
@@ -370,17 +370,17 @@ class BudgetRepository implements BudgetRepositoryInterface
if ($accounts->count() > 0) {
$accountIds = $accounts->pluck('id')->toArray();
$query->where(
- // source.account_id in accountIds XOR destination.account_id in accountIds
- function (Builder $sourceXorDestinationQuery) use ($accountIds) {
- $sourceXorDestinationQuery->where(
- function (Builder $inSourceButNotDestinationQuery) use ($accountIds) {
- $inSourceButNotDestinationQuery->whereIn('source.account_id', $accountIds)
- ->whereNotIn('destination.account_id', $accountIds);
+ // source.account_id in accountIds XOR destination.account_id in accountIds
+ function (Builder $query) use ($accountIds) {
+ $query->where(
+ function (Builder $q1) use ($accountIds) {
+ $q1->whereIn('source.account_id', $accountIds)
+ ->whereNotIn('destination.account_id', $accountIds);
}
)->orWhere(
- function (Builder $inDestinationButNotSourceQuery) use ($accountIds) {
- $inDestinationButNotSourceQuery->whereIn('destination.account_id', $accountIds)
- ->whereNotIn('source.account_id', $accountIds);
+ function (Builder $q2) use ($accountIds) {
+ $q2->whereIn('destination.account_id', $accountIds)
+ ->whereNotIn('source.account_id', $accountIds);
}
);
}
@@ -460,7 +460,7 @@ class BudgetRepository implements BudgetRepositoryInterface
if ($accounts->count() > 0) {
$accountIds = $accounts->pluck('id')->toArray();
$query->where(
- // source.account_id in accountIds XOR destination.account_id in accountIds
+ // source.account_id in accountIds XOR destination.account_id in accountIds
function (Builder $sourceXorDestinationQuery) use ($accountIds) {
$sourceXorDestinationQuery->where(
function (Builder $inSourceButNotDestinationQuery) use ($accountIds) {
diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php
index a68c340171..ac3ea1e285 100644
--- a/app/Repositories/Category/CategoryRepository.php
+++ b/app/Repositories/Category/CategoryRepository.php
@@ -489,17 +489,17 @@ class CategoryRepository implements CategoryRepositoryInterface
if ($accounts->count() > 0) {
$accountIds = $accounts->pluck('id')->toArray();
$query->where(
- // source.account_id in accountIds XOR destination.account_id in accountIds
- function (Builder $sourceXorDestinationQuery) use ($accountIds) {
- $sourceXorDestinationQuery->where(
- function (Builder $inSourceButNotDestinationQuery) use ($accountIds) {
- $inSourceButNotDestinationQuery->whereIn('source.account_id', $accountIds)
- ->whereNotIn('destination.account_id', $accountIds);
+ // source.account_id in accountIds XOR destination.account_id in accountIds
+ function (Builder $query) use ($accountIds) {
+ $query->where(
+ function (Builder $q1) use ($accountIds) {
+ $q1->whereIn('source.account_id', $accountIds)
+ ->whereNotIn('destination.account_id', $accountIds);
}
)->orWhere(
- function (Builder $inDestinationButNotSourceQuery) use ($accountIds) {
- $inDestinationButNotSourceQuery->whereIn('destination.account_id', $accountIds)
- ->whereNotIn('source.account_id', $accountIds);
+ function (Builder $q2) use ($accountIds) {
+ $q2->whereIn('destination.account_id', $accountIds)
+ ->whereNotIn('source.account_id', $accountIds);
}
);
}
diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php
index 6ad9176a60..d5aaff5bc2 100644
--- a/app/Repositories/Category/CategoryRepositoryInterface.php
+++ b/app/Repositories/Category/CategoryRepositoryInterface.php
@@ -71,7 +71,7 @@ interface CategoryRepositoryInterface
public function findByName(string $name) : Category;
/**
- * @param Category $category
+ * @param Category $category
*
* @return Carbon
*/
diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php
index 0033f3c807..6c29921d88 100644
--- a/app/Repositories/Tag/TagRepository.php
+++ b/app/Repositories/Tag/TagRepository.php
@@ -145,7 +145,7 @@ class TagRepository implements TagRepositoryInterface
->transactionJournals()
->sortCorrectly()
->expanded()
- ->groupBy(['tag_transaction_journal.tag_id','tag_transaction_journal.transaction_journal_id'])
+ ->groupBy(['tag_transaction_journal.tag_id', 'tag_transaction_journal.transaction_journal_id'])
->get(TransactionJournal::queryFields());
return $journals;
diff --git a/app/Repositories/Tag/TagRepositoryInterface.php b/app/Repositories/Tag/TagRepositoryInterface.php
index aa10d6a839..b1676b2f03 100644
--- a/app/Repositories/Tag/TagRepositoryInterface.php
+++ b/app/Repositories/Tag/TagRepositoryInterface.php
@@ -35,13 +35,6 @@ interface TagRepositoryInterface
*/
public function connect(TransactionJournal $journal, Tag $tag): bool;
- /**
- * @param Tag $tag
- *
- * @return Collection
- */
- public function getJournals(Tag $tag) : Collection;
-
/**
* This method destroys a tag.
*
@@ -72,6 +65,13 @@ interface TagRepositoryInterface
*/
public function get(): Collection;
+ /**
+ * @param Tag $tag
+ *
+ * @return Collection
+ */
+ public function getJournals(Tag $tag) : Collection;
+
/**
* This method stores a tag.
*
diff --git a/app/Rules/Triggers/FromAccountContains.php b/app/Rules/Triggers/FromAccountContains.php
index 475d3a2554..1b8241ef7b 100644
--- a/app/Rules/Triggers/FromAccountContains.php
+++ b/app/Rules/Triggers/FromAccountContains.php
@@ -83,7 +83,8 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
Log::debug(
sprintf(
'RuleTrigger FromAccountContains for journal #%d: "%s" does not contain "%s", return false.',
- $journal->id, $fromAccountName, $search)
+ $journal->id, $fromAccountName, $search
+ )
);
return false;
diff --git a/app/Rules/Triggers/ToAccountContains.php b/app/Rules/Triggers/ToAccountContains.php
index 926c141808..d80c9ab4d5 100644
--- a/app/Rules/Triggers/ToAccountContains.php
+++ b/app/Rules/Triggers/ToAccountContains.php
@@ -83,7 +83,8 @@ final class ToAccountContains extends AbstractTrigger implements TriggerInterfac
Log::debug(
sprintf(
'RuleTrigger ToAccountContains for journal #%d: "%s" does not contain "%s", return false.',
- $journal->id, $toAccountName, $search)
+ $journal->id, $toAccountName, $search
+ )
);
return false;
diff --git a/app/Rules/Triggers/ToAccountEnds.php b/app/Rules/Triggers/ToAccountEnds.php
index 13d6eed81e..f4fd676422 100644
--- a/app/Rules/Triggers/ToAccountEnds.php
+++ b/app/Rules/Triggers/ToAccountEnds.php
@@ -86,6 +86,7 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
if ($part === $search) {
Log::debug(sprintf('RuleTrigger ToAccountEnds for journal #%d: "%s" ends with "%s", return true.', $journal->id, $toAccountName, $search));
+
return true;
}
diff --git a/app/Rules/Triggers/ToAccountStarts.php b/app/Rules/Triggers/ToAccountStarts.php
index 619c0209fb..f5f162c283 100644
--- a/app/Rules/Triggers/ToAccountStarts.php
+++ b/app/Rules/Triggers/ToAccountStarts.php
@@ -75,6 +75,7 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
if ($part === $search) {
Log::debug(sprintf('RuleTrigger ToAccountStarts for journal #%d: "%s" starts with "%s", return true.', $journal->id, $toAccountName, $search));
+
return true;
}
Log::debug(sprintf('RuleTrigger ToAccountStarts for journal #%d: "%s" does not start with "%s", return false.', $journal->id, $toAccountName, $search));