Skip to content

Firefly III: a personal finances manager

Some code optimalisations.

James Cole5a058491b069
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index db68a5c841..ad44631ba9 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -34,7 +34,6 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
@@ -52,8 +51,6 @@ class AccountController extends Controller
{
/** @var CurrencyRepositoryInterface */
private $currencyRepos;
- /** @var JournalRepositoryInterface */
- private $journalRepos;
/** @var AccountRepositoryInterface */
private $repository;
@@ -72,7 +69,6 @@ class AccountController extends Controller
$this->repository = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
- $this->journalRepos = app(JournalRepositoryInterface::class);
return $next($request);
}
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
index bf4c01ff12..3da9e56add 100644
--- a/app/Models/Bill.php
+++ b/app/Models/Bill.php
@@ -37,6 +37,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property int $transaction_currency_id
* @property string $amount_min
* @property string $amount_max
+ * @property int $id
+ * @property string $name
*/
class Bill extends Model
{
diff --git a/app/Models/Budget.php b/app/Models/Budget.php
index 60f80da5f3..c4bd59d5c8 100644
--- a/app/Models/Budget.php
+++ b/app/Models/Budget.php
@@ -31,6 +31,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class Budget.
+ * @property int $id
+ * @property string $name
*/
class Budget extends Model
{
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 068c12934b..7bc567f2b7 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -31,6 +31,9 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class Category.
+ *
+ * @property string $name
+ * @property int $id
*/
class Category extends Model
{
diff --git a/app/Models/Note.php b/app/Models/Note.php
index a6588c8564..f2cc1ddb20 100644
--- a/app/Models/Note.php
+++ b/app/Models/Note.php
@@ -26,6 +26,8 @@ use Illuminate\Database\Eloquent\Model;
/**
* Class Note.
+ *
+ * @property string $text
*/
class Note extends Model
{
diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php
index e5b8c30a37..92819a5d28 100644
--- a/app/Models/PiggyBank.php
+++ b/app/Models/PiggyBank.php
@@ -36,6 +36,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property Carbon $targetdate
* @property Carbon $startdate
* @property string $targetamount
+ * @property int $id
+ * @property string $name
*
*/
class PiggyBank extends Model
diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php
index df124b1041..2a9ffa0a69 100644
--- a/app/Models/Transaction.php
+++ b/app/Models/Transaction.php
@@ -25,6 +25,7 @@ namespace FireflyIII\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -252,18 +253,18 @@ class Transaction extends Model
/**
* @codeCoverageIgnore
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ * @return BelongsTo
*/
- public function transactionCurrency()
+ public function transactionCurrency(): BelongsTo
{
return $this->belongsTo(TransactionCurrency::class);
}
/**
* @codeCoverageIgnore
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ * @return BelongsTo
*/
- public function transactionJournal()
+ public function transactionJournal(): BelongsTo
{
return $this->belongsTo(TransactionJournal::class);
}
diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php
index 829d5e9876..e54c7513a6 100644
--- a/app/Models/TransactionCurrency.php
+++ b/app/Models/TransactionCurrency.php
@@ -30,6 +30,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* Class TransactionCurrency.
*
* @property string $code
+ * @property string $symbol
* @property int $decimal_places
*
*/
diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php
index 401d53d4b1..99ef2b7f28 100644
--- a/app/Repositories/PiggyBank/PiggyBankRepository.php
+++ b/app/Repositories/PiggyBank/PiggyBankRepository.php
@@ -203,6 +203,21 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return null;
}
+ /**
+ * @param int $piggyBankId
+ *
+ * @return PiggyBank|null
+ */
+ public function findNull(int $piggyBankId): ?PiggyBank
+ {
+ $piggyBank = $this->user->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
+ if (null !== $piggyBank) {
+ return $piggyBank;
+ }
+
+ return null;
+ }
+
/**
* Get current amount saved in piggy bank.
*
diff --git a/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php b/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php
index 9b22a8d3b8..f1ee19124a 100644
--- a/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php
+++ b/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php
@@ -102,11 +102,17 @@ interface PiggyBankRepositoryInterface
/**
* @param int $piggyBankid
- *
+ * @deprecated
* @return PiggyBank
*/
public function find(int $piggyBankid): PiggyBank;
+ /**
+ * @param int $piggyBankId
+ * @return PiggyBank|null
+ */
+ public function findNull(int $piggyBankId): ?PiggyBank;
+
/**
* Find by name or return NULL.
*
diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php
index 0e0be45819..d6d34aa8ed 100644
--- a/app/Support/CacheProperties.php
+++ b/app/Support/CacheProperties.php
@@ -24,7 +24,6 @@ namespace FireflyIII\Support;
use Cache;
use Illuminate\Support\Collection;
-use Preferences as Prefs;
/**
* Class CacheProperties.
@@ -44,7 +43,7 @@ class CacheProperties
$this->properties = new Collection;
if (auth()->check()) {
$this->addProperty(auth()->user()->id);
- $this->addProperty(Prefs::lastActivity());
+ $this->addProperty(app('preferences')->lastActivity());
}
}