Various code optimalisations.

This commit is contained in:
James Cole
2018-07-08 07:59:58 +02:00
parent 10492e3b2f
commit 2f2f907ffe
59 changed files with 309 additions and 279 deletions

View File

@@ -95,9 +95,9 @@ class BulkController extends Controller
{
$journalIds = $request->get('journals');
$journalIds = \is_array($journalIds) ? $journalIds : [];
$ignoreCategory = (int)$request->get('ignore_category') === 1;
$ignoreBudget = (int)$request->get('ignore_budget') === 1;
$ignoreTags = (int)$request->get('ignore_tags') === 1;
$ignoreCategory = 1 === (int)$request->get('ignore_category');
$ignoreBudget = 1 === (int)$request->get('ignore_budget');
$ignoreTags = 1 === (int)$request->get('ignore_tags');
$count = 0;
foreach ($journalIds as $journalId) {
@@ -110,20 +110,20 @@ class BulkController extends Controller
Log::debug(sprintf('Found journal #%d', $journal->id));
// update category if not told to ignore
if ($ignoreCategory === false) {
if (false === $ignoreCategory) {
Log::debug(sprintf('Set category to %s', $request->string('category')));
$this->repository->updateCategory($journal, $request->string('category'));
}
// update budget if not told to ignore (and is withdrawal)
if ($ignoreBudget === false) {
if (false === $ignoreBudget) {
Log::debug(sprintf('Set budget to %d', $request->integer('budget_id')));
$this->repository->updateBudget($journal, $request->integer('budget_id'));
}
// update tags:
if ($ignoreTags === false) {
if (false === $ignoreTags) {
Log::debug(sprintf('Set tags to %s', $request->string('budget_id')));
$this->repository->updateTags($journal, ['tags' => explode(',', $request->string('tags'))]);
}

View File

@@ -153,12 +153,12 @@ class MassController extends Controller
// transform to array
$transactions = $collection->map(
function (Transaction $transaction) use ($transformer) {
$transaction = $transformer->transform($transaction);
$transformed = $transformer->transform($transaction);
// make sure amount is positive:
$transaction['amount'] = app('steam')->positive((string)$transaction['amount']);
$transaction['foreign_amount'] = app('steam')->positive((string)$transaction['foreign_amount']);
$transformed['amount'] = app('steam')->positive((string)$transformed['amount']);
$transformed['foreign_amount'] = app('steam')->positive((string)$transformed['foreign_amount']);
return $transaction;
return $transformed;
}
);
@@ -177,7 +177,7 @@ class MassController extends Controller
$count = 0;
if (\is_array($journalIds)) {
foreach ($journalIds as $journalId) {
$journal = $repository->find((int)$journalId);
$journal = $repository->findNull((int)$journalId);
if (null !== $journal) {
// get optional fields:
$what = strtolower($this->repository->getTransactionType($journal));
@@ -206,7 +206,7 @@ class MassController extends Controller
'category_id' => null,
'category_name' => $category,
'budget_id' => (int)$budgetId,
'budget_id' => $budgetId,
'budget_name' => null,
'source_id' => (int)$sourceAccountId,
'source_name' => $sourceAccountName,

View File

@@ -113,13 +113,13 @@ class SingleController extends Controller
'budget_id' => $budgetId,
'category' => $categoryName,
'tags' => $tags,
'interest_date' => $journal->getMeta('interest_date'),
'book_date' => $journal->getMeta('book_date'),
'process_date' => $journal->getMeta('process_date'),
'due_date' => $journal->getMeta('due_date'),
'payment_date' => $journal->getMeta('payment_date'),
'invoice_date' => $journal->getMeta('invoice_date'),
'internal_reference' => $journal->getMeta('internal_reference'),
'interest_date' => $this->repository->getMetaField($journal, 'interest_date'),
'book_date' => $this->repository->getMetaField($journal, 'book_date'),
'process_date' => $this->repository->getMetaField($journal, 'process_date'),
'due_date' => $this->repository->getMetaField($journal, 'due_date'),
'payment_date' => $this->repository->getMetaField($journal, 'payment_date'),
'invoice_date' => $this->repository->getMetaField($journal, 'invoice_date'),
'internal_reference' => $this->repository->getMetaField($journal, 'internal_reference'),
'notes' => '',
];
@@ -143,7 +143,7 @@ class SingleController extends Controller
public function create(Request $request, string $what = TransactionType::DEPOSIT)
{
$what = strtolower($what);
$what = $request->old('what') ?? $what;
$what = (string)($request->old('what') ?? $what);
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
$preFilled = session()->has('preFilled') ? session('preFilled') : [];
$subTitle = trans('form.add_new_' . $what);
@@ -152,13 +152,13 @@ class SingleController extends Controller
$source = (int)$request->get('source');
// grab old currency ID from old data:
$currencyID = (int)$request->old('amount_currency_id_amount');
$currencyID = (int)$request->old('amount_currency_id_amount');
$preFilled['amount_currency_id_amount'] = $currencyID;
if (($what === 'withdrawal' || $what === 'transfer') && $source > 0) {
if (('withdrawal' === $what || 'transfer' === $what) && $source > 0) {
$preFilled['source_id'] = $source;
}
if ($what === 'deposit' && $source > 0) {
if ('deposit' === $what && $source > 0) {
$preFilled['destination_id'] = $source;
}

View File

@@ -32,7 +32,6 @@ use FireflyIII\Http\Requests\SplitJournalFormRequest;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -49,9 +48,6 @@ use View;
*/
class SplitController extends Controller
{
/** @var AccountRepositoryInterface */
private $accounts;
/** @var AttachmentHelperInterface */
private $attachments;
@@ -73,7 +69,6 @@ class SplitController extends Controller
// some useful repositories:
$this->middleware(
function ($request, $next) {
$this->accounts = app(AccountRepositoryInterface::class);
$this->budgets = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
$this->currencies = app(CurrencyRepositoryInterface::class);