Various code cleanup.

This commit is contained in:
James Cole
2017-12-22 18:32:43 +01:00
parent f13a93348f
commit 8bd76d1ff0
188 changed files with 383 additions and 396 deletions

View File

@@ -25,7 +25,6 @@ namespace FireflyIII\Console\Commands;
use Artisan;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Logging\CommandHandler;
use FireflyIII\Import\Routine\ImportRoutine;
use FireflyIII\Import\Routine\RoutineInterface;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
@@ -75,6 +74,7 @@ class CreateImport extends Command
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five exactly.
*
* @throws FireflyException
*/
public function handle()
@@ -133,7 +133,7 @@ class CreateImport extends Command
$monolog->pushHandler($handler);
// start the actual routine:
$type = $job->file_type === 'csv' ? 'file' : $job->file_type;
$type = 'csv' === $job->file_type ? 'file' : $job->file_type;
$key = sprintf('import.routine.%s', $type);
$className = config($key);
if (null === $className || !class_exists($className)) {

View File

@@ -24,7 +24,6 @@ namespace FireflyIII\Console\Commands;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Logging\CommandHandler;
use FireflyIII\Import\Routine\ImportRoutine;
use FireflyIII\Import\Routine\RoutineInterface;
use FireflyIII\Models\ImportJob;
use Illuminate\Console\Command;
@@ -60,6 +59,8 @@ class Import extends Command
/**
* Run the import routine.
*
* @throws FireflyException
*/
public function handle()
{
@@ -84,7 +85,7 @@ class Import extends Command
$monolog->pushHandler($handler);
// actually start job:
$type = $job->file_type === 'csv' ? 'file' : $job->file_type;
$type = 'csv' === $job->file_type ? 'file' : $job->file_type;
$key = sprintf('import.routine.%s', $type);
$className = config($key);
if (null === $className || !class_exists($className)) {

View File

@@ -26,8 +26,6 @@ use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\LimitRepetition;
use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;

View File

@@ -111,10 +111,10 @@ class VerifyDatabase extends Command
$token = $user->generateAccessToken();
Preferences::setForUser($user, 'access_token', $token);
$this->line(sprintf('Generated access token for user %s', $user->email));
$count++;
++$count;
}
}
if ($count === 0) {
if (0 === $count) {
$this->info('All access tokens OK!');
}
}
@@ -138,12 +138,12 @@ class VerifyDatabase extends Command
$link->name = $name;
$link->outward = $values[0];
$link->inward = $values[1];
$count++;
++$count;
}
$link->editable = false;
$link->save();
}
if ($count === 0) {
if (0 === $count) {
$this->info('All link types OK!');
}
}
@@ -158,7 +158,7 @@ class VerifyDatabase extends Command
->get(['transaction_journal_id', DB::raw('SUM(amount) AS the_sum')]);
/** @var stdClass $entry */
foreach ($journals as $entry) {
if (bccomp(strval($entry->the_sum), '0') !== 0) {
if (0 !== bccomp(strval($entry->the_sum), '0')) {
$errored[] = $entry->transaction_journal_id;
}
}
@@ -167,14 +167,14 @@ class VerifyDatabase extends Command
$res = Transaction::whereNull('deleted_at')->where('transaction_journal_id', $journalId)->groupBy('amount')->get([DB::raw('MIN(id) as first_id')]);
$ids = $res->pluck('first_id')->toArray();
DB::table('transactions')->whereIn('id', $ids)->update(['amount' => DB::raw('amount * -1')]);
$count++;
++$count;
// report about it
/** @var TransactionJournal $journal */
$journal = TransactionJournal::find($journalId);
if (is_null($journal)) {
continue;
}
if ($journal->transactionType->type === TransactionType::OPENING_BALANCE) {
if (TransactionType::OPENING_BALANCE === $journal->transactionType->type) {
$this->error(
sprintf(
'Transaction #%d was stored incorrectly. One of your asset accounts may show the wrong balance. Please visit /transactions/show/%d to verify the opening balance.',
@@ -182,7 +182,7 @@ class VerifyDatabase extends Command
)
);
}
if ($journal->transactionType->type !== TransactionType::OPENING_BALANCE) {
if (TransactionType::OPENING_BALANCE !== $journal->transactionType->type) {
$this->error(
sprintf(
'Transaction #%d was stored incorrectly. Could be that the transaction shows the wrong amount. Please visit /transactions/show/%d to verify the opening balance.',
@@ -191,7 +191,7 @@ class VerifyDatabase extends Command
);
}
}
if ($count === 0) {
if (0 === $count) {
$this->info('Amount integrity OK!');
}
@@ -371,9 +371,9 @@ class VerifyDatabase extends Command
'Error: Transaction #' . $entry->transaction_id . ' should have been deleted, but has not.' .
' Find it in the table called "transactions" and change the "deleted_at" field to: "' . $entry->journal_deleted . '"'
);
$count++;
++$count;
}
if ($count === 0) {
if (0 === $count) {
$this->info('No orphaned transactions!');
}
}
@@ -393,9 +393,9 @@ class VerifyDatabase extends Command
$this->error(
'Error: Journal #' . $entry->id . ' has zero transactions. Open table "transaction_journals" and delete the entry with id #' . $entry->id
);
$count++;
++$count;
}
if ($count === 0) {
if (0 === $count) {
$this->info('No orphaned journals!');
}
}