Code clean up.

This commit is contained in:
James Cole
2017-11-15 10:52:29 +01:00
parent aee17221eb
commit 649dca77f5
305 changed files with 1200 additions and 1600 deletions

View File

@@ -37,7 +37,6 @@ use FireflyIII\User;
use Log;
use Validator;
/**
*
* Class AccountRepository
@@ -176,7 +175,6 @@ class AccountRepository implements AccountRepositoryInterface
$this->deleteInitialBalance($newAccount);
return $newAccount;
}
/**
@@ -211,7 +209,6 @@ class AccountRepository implements AccountRepositoryInterface
if (!is_null($journal->id)) {
$journal->delete();
}
}
/**
@@ -276,10 +273,10 @@ class AccountRepository implements AccountRepositoryInterface
// verify its creation:
if (is_null($newAccount->id)) {
Log::error(
sprintf('Could not create account "%s" (%d error(s))', $data['name'], $newAccount->getErrors()->count()), $newAccount->getErrors()->toArray()
sprintf('Could not create account "%s" (%d error(s))', $data['name'], $newAccount->getErrors()->count()),
$newAccount->getErrors()->toArray()
);
throw new FireflyException(sprintf('Tried to create account named "%s" but failed. The logs have more details.', $data['name']));
}
Log::debug(sprintf('Created new account #%d named "%s" of type %s.', $newAccount->id, $newAccount->name, $accountType->type));
@@ -424,7 +421,10 @@ class AccountRepository implements AccountRepositoryInterface
Log::debug(
sprintf(
'Created meta-field "%s":"%s" for account #%d ("%s") ',
$field, $data[$field], $account->id, $account->name
$field,
$data[$field],
$account->id,
$account->name
)
);
AccountMeta::create(
@@ -443,12 +443,14 @@ class AccountRepository implements AccountRepositoryInterface
Log::debug(
sprintf(
'Updated meta-field "%s":"%s" for account #%d ("%s") ',
$field, $data[$field], $account->id, $account->name
$field,
$data[$field],
$account->id,
$account->name
)
);
}
}
}
/**
@@ -496,7 +498,6 @@ class AccountRepository implements AccountRepositoryInterface
Log::debug('Updated opening balance journal.');
return true;
}

View File

@@ -159,5 +159,4 @@ interface AccountRepositoryInterface
* @return Account
*/
public function update(Account $account, array $data): Account;
}

View File

@@ -65,5 +65,4 @@ interface AccountTaskerInterface
* @param User $user
*/
public function setUser(User $user);
}

View File

@@ -120,7 +120,6 @@ trait FindAccountsTrait
if (count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
Log::debug(sprintf('Searching for account named "%s" (of user #%d) of the following type(s)', $name, $this->user->id), ['types' => $types]);

View File

@@ -168,13 +168,11 @@ class AttachmentRepository implements AttachmentRepositoryInterface
*/
public function update(Attachment $attachment, array $data): Attachment
{
$attachment->title = $data['title'];
$attachment->description = $data['description'];
$attachment->notes = $data['notes'];
$attachment->save();
return $attachment;
}
}

View File

@@ -97,4 +97,3 @@ interface AttachmentRepositoryInterface
*/
public function update(Attachment $attachment, array $attachmentData): Attachment;
}

View File

@@ -125,7 +125,6 @@ class BillRepository implements BillRepositoryInterface
$set = $set->sortBy(
function (Bill $bill) {
$int = $bill->active ? 0 : 1;
return $int . strtolower($bill->name);
@@ -161,14 +160,16 @@ class BillRepository implements BillRepositoryInterface
$ids = $accounts->pluck('id')->toArray();
$set = $this->user->bills()
->leftJoin(
'transaction_journals', function (JoinClause $join) {
$join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
}
'transaction_journals',
function (JoinClause $join) {
$join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
}
)
->leftJoin(
'transactions', function (JoinClause $join) {
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
}
'transactions',
function (JoinClause $join) {
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
}
)
->whereIn('transactions.account_id', $ids)
->whereNull('transaction_journals.deleted_at')
@@ -177,7 +178,6 @@ class BillRepository implements BillRepositoryInterface
$set = $set->sortBy(
function (Bill $bill) {
$int = $bill->active === 1 ? 0 : 1;
return $int . strtolower($bill->name);
@@ -238,7 +238,6 @@ class BillRepository implements BillRepositoryInterface
Log::debug(sprintf('Dates = %d, journalCount = %d, total = %d', $dates->count(), $count, $total));
if ($total > 0) {
$average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2');
$multi = bcmul($average, strval($total));
$sum = bcadd($sum, $multi);
@@ -285,7 +284,6 @@ class BillRepository implements BillRepositoryInterface
$dates = $bill->transactionJournals()->before($end)->after($start)->get(['transaction_journals.date'])->pluck('date');
return $dates;
}
/**
@@ -519,7 +517,6 @@ class BillRepository implements BillRepositoryInterface
}
return false;
}
/**
@@ -565,8 +562,6 @@ class BillRepository implements BillRepositoryInterface
*/
public function update(Bill $bill, array $data): Bill
{
$bill->name = $data['name'];
$bill->match = $data['match'];
$bill->amount_min = $data['amount_min'];

View File

@@ -188,5 +188,4 @@ interface BillRepositoryInterface
* @return Bill
*/
public function update(Bill $bill, array $data): Bill;
}

View File

@@ -72,7 +72,6 @@ class BudgetRepository implements BudgetRepositoryInterface
}
return true;
}
/**
@@ -229,7 +228,6 @@ class BudgetRepository implements BudgetRepositoryInterface
}
return $oldest;
}
/**
@@ -396,7 +394,6 @@ class BudgetRepository implements BudgetRepositoryInterface
}
return $data;
}
/**

View File

@@ -219,5 +219,4 @@ interface BudgetRepositoryInterface
* @return BudgetLimit
*/
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, int $amount): BudgetLimit;
}

View File

@@ -547,5 +547,4 @@ class CategoryRepository implements CategoryRepositoryInterface
return null;
}
}

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Currency;
use Carbon\Carbon;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\Preference;
@@ -228,8 +227,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface
}
return new CurrencyExchangeRate;
}
/**

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Currency;
use Carbon\Carbon;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\Preference;
@@ -142,5 +141,4 @@ interface CurrencyRepositoryInterface
* @return TransactionCurrency
*/
public function update(TransactionCurrency $currency, array $data): TransactionCurrency;
}

View File

@@ -103,11 +103,9 @@ class ExportJobRepository implements ExportJobRepositoryInterface
return $exportJob;
}
$count++;
}
return new ExportJob;
}
/**

View File

@@ -76,5 +76,4 @@ interface ExportJobRepositoryInterface
* @param User $user
*/
public function setUser(User $user);
}

View File

@@ -81,7 +81,6 @@ class ImportJobRepository implements ImportJobRepositoryInterface
return $importJob;
}
$count++;
}
return new ImportJob;
@@ -115,7 +114,8 @@ class ImportJobRepository implements ImportJobRepositoryInterface
// demo user's configuration upload is ignored completely.
if (!$repository->hasRole($this->user, 'demo')) {
Log::debug(
'Uploaded configuration file', ['name' => $file->getClientOriginalName(), 'size' => $file->getSize(), 'mime' => $file->getClientMimeType()]
'Uploaded configuration file',
['name' => $file->getClientOriginalName(), 'size' => $file->getSize(), 'mime' => $file->getClientMimeType()]
);
$configFileObject = new SplFileObject($file->getRealPath());

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Note;
@@ -205,7 +204,6 @@ trait CreateJournalsTrait
}
return $transaction;
}

View File

@@ -166,7 +166,6 @@ class JournalRepository implements JournalRepositoryInterface
$entry = $this->user->transactionJournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
if (is_null($entry)) {
return new TransactionJournal;
}
@@ -214,7 +213,6 @@ class JournalRepository implements JournalRepositoryInterface
$opposing->save();
return true;
}
/**
@@ -321,7 +319,6 @@ class JournalRepository implements JournalRepositoryInterface
$journal->save();
return $journal;
}
/**

View File

@@ -149,5 +149,4 @@ interface JournalRepositoryInterface
* @return TransactionJournal
*/
public function updateSplitJournal(TransactionJournal $journal, array $data): TransactionJournal;
}

View File

@@ -86,13 +86,14 @@ class JournalTasker implements JournalTaskerInterface
$set = $journal
->transactions()// "source"
->leftJoin(
'transactions as destination', function (JoinClause $join) {
$join
'transactions as destination',
function (JoinClause $join) {
$join
->on('transactions.transaction_journal_id', '=', 'destination.transaction_journal_id')
->where('transactions.amount', '=', DB::raw('destination.amount * -1'))
->where('transactions.identifier', '=', DB::raw('destination.identifier'))
->whereNull('destination.deleted_at');
}
}
)
->with(['budgets', 'categories'])
->leftJoin('accounts as source_accounts', 'transactions.account_id', '=', 'source_accounts.id')

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\User;
use Illuminate\Support\Collection;

View File

@@ -81,7 +81,6 @@ trait SupportJournalsTrait
if (is_null($accounts['destination'])) {
Log::error('"destination"-account is null, so we cannot continue!', ['data' => $data]);
throw new FireflyException('"destination"-account is null, so we cannot continue!');
}

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use DB;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
@@ -96,7 +95,6 @@ trait UpdateJournalsTrait
$transaction->foreign_currency_id = $data['foreign_currency_id'];
$transaction->account_id = $account->id;
$transaction->save();
}
/**

View File

@@ -106,8 +106,6 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
$opposingCount = TransactionJournalLink::whereDestinationId($two->id)->whereSourceId($one->id)->count();
return ($count + $opposingCount > 0);
}
/**
@@ -187,6 +185,5 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
$linkType->save();
return $linkType;
}
}

View File

@@ -109,5 +109,4 @@ interface LinkTypeRepositoryInterface
* @return LinkType
*/
public function update(LinkType $linkType, array $data): LinkType;
}

View File

@@ -365,7 +365,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
*/
public function update(PiggyBank $piggyBank, array $data): PiggyBank
{
$piggyBank->name = $data['name'];
$piggyBank->account_id = intval($data['account_id']);
$piggyBank->targetamount = round($data['targetamount'], 2);
@@ -380,7 +379,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
// remove money from the rep.
$repetition = $piggyBank->currentRelevantRep();
if ($repetition->currentamount > $piggyBank->targetamount) {
$diff = bcsub($piggyBank->targetamount, $repetition->currentamount);
$this->createEvent($piggyBank, $diff);

View File

@@ -230,7 +230,6 @@ class RuleRepository implements RuleRepositoryInterface
}
return true;
}
/**
@@ -373,7 +372,6 @@ class RuleRepository implements RuleRepositoryInterface
}
return true;
}
/**

View File

@@ -147,5 +147,4 @@ interface RuleRepositoryInterface
* @return Rule
*/
public function update(Rule $rule, array $data): Rule;
}

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\RuleGroup;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\User;
@@ -58,9 +57,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
{
/** @var Rule $rule */
foreach ($ruleGroup->rules as $rule) {
if (is_null($moveTo)) {
$rule->delete();
continue;
}
@@ -167,7 +164,6 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
'rules' => function (HasMany $query) {
$query->orderBy('active', 'DESC');
$query->orderBy('order', 'ASC');
},
'rules.ruleTriggers' => function (HasMany $query) {
$query->orderBy('order', 'ASC');
@@ -267,7 +263,6 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
}
return true;
}
/**

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\RuleGroup;
use FireflyIII\Models\RuleGroup;
use FireflyIII\User;
use Illuminate\Support\Collection;
@@ -141,6 +140,4 @@ interface RuleGroupRepositoryInterface
* @return RuleGroup
*/
public function update(RuleGroup $ruleGroup, array $data): RuleGroup;
}

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Tag;
use Carbon\Carbon;
use DB;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
@@ -252,8 +251,6 @@ class TagRepository implements TagRepositoryInterface
$tag->save();
return $tag;
}
/**
@@ -435,7 +432,6 @@ class TagRepository implements TagRepositoryInterface
// no difference? Every tag same range:
if ($amountDiff === 0.0) {
return $range[0];
}

View File

@@ -29,7 +29,6 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
* Interface TagRepositoryInterface
*

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\User;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Role;
use FireflyIII\User;

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\User;
use FireflyIII\User;
use Illuminate\Support\Collection;