Some code optimalisations.

This commit is contained in:
James Cole 2018-06-10 16:59:41 +02:00
parent 6743d99d9b
commit 5a058491b0
11 changed files with 40 additions and 11 deletions

View File

@ -34,7 +34,6 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;
@ -52,8 +51,6 @@ class AccountController extends Controller
{ {
/** @var CurrencyRepositoryInterface */ /** @var CurrencyRepositoryInterface */
private $currencyRepos; private $currencyRepos;
/** @var JournalRepositoryInterface */
private $journalRepos;
/** @var AccountRepositoryInterface */ /** @var AccountRepositoryInterface */
private $repository; private $repository;
@ -72,7 +69,6 @@ class AccountController extends Controller
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class);
$this->journalRepos = app(JournalRepositoryInterface::class);
return $next($request); return $next($request);
} }

View File

@ -37,6 +37,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property int $transaction_currency_id * @property int $transaction_currency_id
* @property string $amount_min * @property string $amount_min
* @property string $amount_max * @property string $amount_max
* @property int $id
* @property string $name
*/ */
class Bill extends Model class Bill extends Model
{ {

View File

@ -31,6 +31,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Class Budget. * Class Budget.
* @property int $id
* @property string $name
*/ */
class Budget extends Model class Budget extends Model
{ {

View File

@ -31,6 +31,9 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Class Category. * Class Category.
*
* @property string $name
* @property int $id
*/ */
class Category extends Model class Category extends Model
{ {

View File

@ -26,6 +26,8 @@ use Illuminate\Database\Eloquent\Model;
/** /**
* Class Note. * Class Note.
*
* @property string $text
*/ */
class Note extends Model class Note extends Model
{ {

View File

@ -36,6 +36,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property Carbon $targetdate * @property Carbon $targetdate
* @property Carbon $startdate * @property Carbon $startdate
* @property string $targetamount * @property string $targetamount
* @property int $id
* @property string $name
* *
*/ */
class PiggyBank extends Model class PiggyBank extends Model

View File

@ -25,6 +25,7 @@ namespace FireflyIII\Models;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@ -252,18 +253,18 @@ class Transaction extends Model
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo * @return BelongsTo
*/ */
public function transactionCurrency() public function transactionCurrency(): BelongsTo
{ {
return $this->belongsTo(TransactionCurrency::class); return $this->belongsTo(TransactionCurrency::class);
} }
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo * @return BelongsTo
*/ */
public function transactionJournal() public function transactionJournal(): BelongsTo
{ {
return $this->belongsTo(TransactionJournal::class); return $this->belongsTo(TransactionJournal::class);
} }

View File

@ -30,6 +30,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* Class TransactionCurrency. * Class TransactionCurrency.
* *
* @property string $code * @property string $code
* @property string $symbol
* @property int $decimal_places * @property int $decimal_places
* *
*/ */

View File

@ -203,6 +203,21 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return null; 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. * Get current amount saved in piggy bank.
* *

View File

@ -102,11 +102,17 @@ interface PiggyBankRepositoryInterface
/** /**
* @param int $piggyBankid * @param int $piggyBankid
* * @deprecated
* @return PiggyBank * @return PiggyBank
*/ */
public function find(int $piggyBankid): 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. * Find by name or return NULL.
* *

View File

@ -24,7 +24,6 @@ namespace FireflyIII\Support;
use Cache; use Cache;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Preferences as Prefs;
/** /**
* Class CacheProperties. * Class CacheProperties.
@ -44,7 +43,7 @@ class CacheProperties
$this->properties = new Collection; $this->properties = new Collection;
if (auth()->check()) { if (auth()->check()) {
$this->addProperty(auth()->user()->id); $this->addProperty(auth()->user()->id);
$this->addProperty(Prefs::lastActivity()); $this->addProperty(app('preferences')->lastActivity());
} }
} }