Code cleanup

This commit is contained in:
James Cole
2018-04-02 15:10:40 +02:00
parent fa7ab45a40
commit a3c34e6b3c
151 changed files with 802 additions and 990 deletions

View File

@@ -70,7 +70,6 @@ class BulkController extends Controller
* @param Collection $journals
*
* @return View
* @throws \RuntimeException
*/
public function edit(Request $request, Collection $journals)
{
@@ -140,22 +139,21 @@ class BulkController extends Controller
* @param JournalRepositoryInterface $repository
*
* @return mixed
* @throws \RuntimeException
*/
public function update(BulkEditJournalRequest $request, JournalRepositoryInterface $repository)
{
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$journalIds = $request->get('journals');
$ignoreCategory = intval($request->get('ignore_category')) === 1;
$ignoreBudget = intval($request->get('ignore_budget')) === 1;
$ignoreTags = intval($request->get('ignore_tags')) === 1;
$ignoreCategory = (int)$request->get('ignore_category') === 1;
$ignoreBudget = (int)$request->get('ignore_budget') === 1;
$ignoreTags = (int)$request->get('ignore_tags') === 1;
$count = 0;
if (is_array($journalIds)) {
foreach ($journalIds as $journalId) {
$journal = $repository->find(intval($journalId));
if (!is_null($journal)) {
$journal = $repository->find((int)$journalId);
if (null !== $journal) {
$count++;
Log::debug(sprintf('Found journal #%d', $journal->id));
// update category if not told to ignore

View File

@@ -191,7 +191,7 @@ class ConvertController extends Controller
break;
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:
// two
$destination = $accountRepository->findNull(intval($data['destination_account_asset']));
$destination = $accountRepository->findNull((int)$data['destination_account_asset']);
break;
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:
@@ -266,7 +266,7 @@ class ConvertController extends Controller
$source = $destinationAccount;
break;
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:
$source = $accountRepository->findNull(intval($data['source_account_asset']));
$source = $accountRepository->findNull((int)$data['source_account_asset']);
break;
}

View File

@@ -86,10 +86,10 @@ class LinkController extends Controller
{
$this->repository->destroyLink($link);
Session::flash('success', strval(trans('firefly.deleted_link')));
Session::flash('success', (string)trans('firefly.deleted_link'));
Preferences::mark();
return redirect(strval(session('journal_links.delete.uri')));
return redirect((string)session('journal_links.delete.uri'));
}
/**
@@ -111,7 +111,7 @@ class LinkController extends Controller
$other = $this->journalRepository->find($linkInfo['transaction_journal_id']);
$alreadyLinked = $this->repository->findLink($journal, $other);
if($other->id === $journal->id) {
if ($other->id === $journal->id) {
Session::flash('error', trans('firefly.journals_link_to_self'));
return redirect(route('transactions.show', [$journal->id]));

View File

@@ -92,8 +92,8 @@ class MassController extends Controller
/** @var int $journalId */
foreach ($ids as $journalId) {
/** @var TransactionJournal $journal */
$journal = $this->repository->find(intval($journalId));
if (null !== $journal->id && intval($journalId) === $journal->id) {
$journal = $this->repository->find((int)$journalId);
if (null !== $journal->id && (int)$journalId === $journal->id) {
$set->push($journal);
}
}
@@ -174,14 +174,14 @@ class MassController extends Controller
function (TransactionJournal $journal) {
$transaction = $this->repository->getFirstPosTransaction($journal);
$currency = $transaction->transactionCurrency;
$journal->amount = floatval($transaction->amount);
$journal->amount = (float)$transaction->amount;
$sources = $this->repository->getJournalSourceAccounts($journal);
$destinations = $this->repository->getJournalDestinationAccounts($journal);
$journal->transaction_count = $journal->transactions()->count();
$journal->currency_symbol = $currency->symbol;
$journal->transaction_type_type = $journal->transactionType->type;
$journal->foreign_amount = floatval($transaction->foreign_amount);
$journal->foreign_amount = (float)$transaction->foreign_amount;
$journal->foreign_currency = $transaction->foreignCurrency;
if (null !== $sources->first()) {
@@ -216,8 +216,8 @@ class MassController extends Controller
$count = 0;
if (is_array($journalIds)) {
foreach ($journalIds as $journalId) {
$journal = $repository->find(intval($journalId));
if (!is_null($journal)) {
$journal = $repository->find((int)$journalId);
if (null !== $journal) {
// get optional fields:
$what = strtolower($this->repository->getTransactionType($journal));
$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? null;
@@ -225,13 +225,13 @@ class MassController extends Controller
$sourceAccountName = $request->get('source_account_name')[$journal->id] ?? null;
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? null;
$destAccountName = $request->get('destination_account_name')[$journal->id] ?? null;
$budgetId = $request->get('budget_id')[$journal->id] ?? 0;
$budgetId = (int)($request->get('budget_id')[$journal->id] ?? 0.0);
$category = $request->get('category')[$journal->id];
$tags = $journal->tags->pluck('tag')->toArray();
$amount = round($request->get('amount')[$journal->id], 12);
$foreignAmount = isset($request->get('foreign_amount')[$journal->id]) ? round($request->get('foreign_amount')[$journal->id], 12) : null;
$foreignCurrencyId = isset($request->get('foreign_currency_id')[$journal->id]) ?
intval($request->get('foreign_currency_id')[$journal->id]) : null;
(int)$request->get('foreign_currency_id')[$journal->id] : null;
// build data array
$data = [
'id' => $journal->id,
@@ -245,16 +245,16 @@ class MassController extends Controller
'category_id' => null,
'category_name' => $category,
'budget_id' => intval($budgetId),
'budget_id' => (int)$budgetId,
'budget_name' => null,
'source_id' => intval($sourceAccountId),
'source_id' => (int)$sourceAccountId,
'source_name' => $sourceAccountName,
'destination_id' => intval($destAccountId),
'destination_id' => (int)$destAccountId,
'destination_name' => $destAccountName,
'amount' => $amount,
'identifier' => 0,
'reconciled' => false,
'currency_id' => intval($currencyId),
'currency_id' => (int)$currencyId,
'currency_code' => null,
'description' => null,
'foreign_amount' => $foreignAmount,

View File

@@ -162,7 +162,7 @@ class SingleController extends Controller
$subTitle = trans('form.add_new_' . $what);
$subTitleIcon = 'fa-plus';
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
$source = intval($request->get('source'));
$source = (int)$request->get('source');
if (($what === 'withdrawal' || $what === 'transfer') && $source > 0) {
$preFilled['source_account_id'] = $source;
@@ -227,7 +227,7 @@ class SingleController extends Controller
}
// @codeCoverageIgnoreEnd
$type = $transactionJournal->transactionTypeStr();
Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => $transactionJournal->description])));
Session::flash('success', (string)trans('firefly.deleted_' . strtolower($type), ['description' => $transactionJournal->description]));
$this->repository->destroy($transactionJournal);
@@ -272,7 +272,7 @@ class SingleController extends Controller
$destinationAccounts = $repository->getJournalDestinationAccounts($journal);
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
$pTransaction = $repository->getFirstPosTransaction($journal);
$foreignCurrency = null !== $pTransaction->foreignCurrency ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency;
$foreignCurrency = $pTransaction->foreignCurrency ?? $pTransaction->transactionCurrency;
$preFilled = [
'date' => $repository->getJournalDate($journal, null), // $journal->dateAsString()
'interest_date' => $repository->getJournalDate($journal, 'interest_date'),
@@ -334,16 +334,16 @@ class SingleController extends Controller
*/
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository)
{
$doSplit = 1 === intval($request->get('split_journal'));
$createAnother = 1 === intval($request->get('create_another'));
$doSplit = 1 === (int)$request->get('split_journal');
$createAnother = 1 === (int)$request->get('create_another');
$data = $request->getJournalData();
$journal = $repository->store($data);
if (null === $journal->id) {
// error!
Log::error('Could not store transaction journal: ', $journal->getErrors()->toArray());
Session::flash('error', $journal->getErrors()->first());
Log::error('Could not store transaction journal.');
Session::flash('error', (string)trans('firefly.unknown_journal_error'));
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
}
@@ -354,17 +354,17 @@ class SingleController extends Controller
// store the journal only, flash the rest.
Log::debug(sprintf('Count of error messages is %d', $this->attachments->getErrors()->count()));
if (count($this->attachments->getErrors()->get('attachments')) > 0) {
if (\count($this->attachments->getErrors()->get('attachments')) > 0) {
Session::flash('error', $this->attachments->getErrors()->get('attachments'));
}
// flash messages
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
if (\count($this->attachments->getMessages()->get('attachments')) > 0) {
Session::flash('info', $this->attachments->getMessages()->get('attachments'));
}
event(new StoredTransactionJournal($journal, $data['piggy_bank_id']));
Session::flash('success', strval(trans('firefly.stored_journal', ['description' => $journal->description])));
Session::flash('success', (string)trans('firefly.stored_journal', ['description' => $journal->description]));
Preferences::mark();
// @codeCoverageIgnoreStart
@@ -417,11 +417,11 @@ class SingleController extends Controller
// update, get events by date and sort DESC
$type = strtolower($this->repository->getTransactionType($journal));
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => $data['description']])));
Session::flash('success', (string)trans('firefly.updated_' . $type, ['description' => $data['description']]));
Preferences::mark();
// @codeCoverageIgnoreStart
if (1 === intval($request->get('return_to_edit'))) {
if (1 === (int)$request->get('return_to_edit')) {
Session::put('transactions.edit.fromUpdate', true);
return redirect(route('transactions.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);

View File

@@ -114,7 +114,7 @@ class SplitController extends Controller
/** @var Account $account */
foreach ($accountList as $account) {
$accountArray[$account->id] = $account;
$accountArray[$account->id]['currency_id'] = intval($account->getMeta('currency_id'));
$accountArray[$account->id]['currency_id'] = (int)$account->getMeta('currency_id');
}
// put previous url in session if not redirect from store (not "return_to_edit").
@@ -126,8 +126,7 @@ class SplitController extends Controller
return view(
'transactions.split.edit', compact(
'subTitleIcon', 'currencies', 'optionalFields', 'preFilled', 'subTitle', 'uploadSize', 'budgets',
'journal', 'accountArray',
'previous'
'journal', 'accountArray'
)
);
}
@@ -160,11 +159,11 @@ class SplitController extends Controller
// @codeCoverageIgnoreEnd
$type = strtolower($this->repository->getTransactionType($journal));
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => $journal->description])));
Session::flash('success', (string)trans('firefly.updated_' . $type, ['description' => $journal->description]));
Preferences::mark();
// @codeCoverageIgnoreStart
if (1 === intval($request->get('return_to_edit'))) {
if (1 === (int)$request->get('return_to_edit')) {
// set value so edit routine will not overwrite URL:
Session::put('transactions.edit-split.fromUpdate', true);