Code cleaning stuff.

This commit is contained in:
James Cole
2019-02-13 17:38:41 +01:00
parent 9a461fc7b7
commit 71fb9d8fa5
141 changed files with 495 additions and 482 deletions

View File

@@ -41,6 +41,7 @@ use Illuminate\Support\Collection;
/**
*
* Class ApplyRules
*
* @codeCoverageIgnore
*/
class ApplyRules extends Command
@@ -184,6 +185,8 @@ class ApplyRules extends Command
private function applyRuleSelection(Collection $rules, Collection $transactions, bool $breakProcessing): void
{
$bar = $this->output->createProgressBar($rules->count() * $transactions->count());
/** @var Rule $rule */
foreach ($rules as $rule) {
/** @var Processor $processor */
$processor = app(Processor::class);
@@ -191,7 +194,7 @@ class ApplyRules extends Command
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
/** @var Rule $rule */
/** @noinspection DisconnectedForeachInstructionInspection */
$bar->advance();
$result = $processor->handleTransaction($transaction);
if (true === $result) {
@@ -210,6 +213,7 @@ class ApplyRules extends Command
/**
*
* @throws \FireflyIII\Exceptions\FireflyException
*/
private function grabAllRules(): void
{
@@ -226,6 +230,7 @@ class ApplyRules extends Command
/**
*
* @throws \FireflyIII\Exceptions\FireflyException
*/
private function parseDates(): void
{

View File

@@ -134,8 +134,8 @@ class CreateExport extends Command
}
$processor->createZipFile();
$disk = Storage::disk('export');
$fileName = sprintf('export-%s.zip', date('Y-m-d_H-i-s'));
$disk = Storage::disk('export');
$fileName = sprintf('export-%s.zip', date('Y-m-d_H-i-s'));
$localPath = storage_path('export') . '/' . $job->key . '.zip';
// "move" from local to export disk

View File

@@ -97,7 +97,7 @@ class CreateImport extends Command
return 1;
}
if (\strlen($configuration) > 0) {
if ('' !== $configuration) {
$configurationData = json_decode(file_get_contents($configuration), true);
if (null === $configurationData) {
$this->errorLine(sprintf('Firefly III cannot read the contents of configuration file "%s" (working directory: "%s").', $configuration, $cwd));
@@ -136,7 +136,7 @@ class CreateImport extends Command
}
// store file as attachment.
if (\strlen($file) > 0) {
if ('' !== $file) {
$messages = $jobRepository->storeCLIUpload($importJob, 'import_file', $file);
if ($messages->count() > 0) {
$this->errorLine($messages->first());

View File

@@ -48,16 +48,6 @@ class Cron extends Command
*/
protected $signature = 'firefly:cron';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*

View File

@@ -113,7 +113,7 @@ class DecryptDatabase extends Command
$configName = sprintf('is_decrypted_%s', $table);
$configVar = FireflyConfig::get($configName, false);
if (null !== $configVar) {
return $configVar->data;
return (bool)$configVar->data;
}
return false;
@@ -130,7 +130,7 @@ class DecryptDatabase extends Command
try {
$value = Crypt::decrypt($value);
} catch (DecryptException $e) {
//Log::debug(sprintf('Could not decrypt. %s', $e->getMessage()));
Log::debug(sprintf('Could not decrypt. %s', $e->getMessage()));
}
return $value;

View File

@@ -35,6 +35,7 @@ use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Note;
use FireflyIII\Models\Preference;
@@ -272,7 +273,7 @@ class UpgradeDatabase extends Command
->whereNull('transactions.deleted_at')
->groupBy(['transaction_journals.id'])
->select(['transaction_journals.id', DB::raw('COUNT(transactions.id) AS t_count')]);
$result = DB::table(DB::raw('(' . $subQuery->toSql() . ') AS derived'))
$result = DB::table((string)DB::raw('(' . $subQuery->toSql() . ') AS derived'))
->mergeBindings($subQuery->getQuery())
->where('t_count', '>', 2)
->select(['id', 't_count']);
@@ -448,6 +449,7 @@ class UpgradeDatabase extends Command
/** @var BudgetLimit $budgetLimit */
foreach ($budgetLimits as $budgetLimit) {
if (null === $budgetLimit->transaction_currency_id) {
/** @var Budget $budget */
$budget = $budgetLimit->budget;
if (null !== $budget) {
$user = $budget->user;
@@ -465,7 +467,7 @@ class UpgradeDatabase extends Command
}
/**
*
*
*/
private function createNewTypes(): void
{
@@ -493,7 +495,7 @@ class UpgradeDatabase extends Command
// move description:
$description = (string)$att->description;
if (\strlen($description) > 0) {
if ('' !== $description) {
// find or create note:
$note = $att->notes()->first();
if (null === $note) {
@@ -544,19 +546,19 @@ class UpgradeDatabase extends Command
*/
private function removeCCLiabilities(): void
{
$ccType = AccountType::where('type', AccountType::CREDITCARD)->first();
$debtType =AccountType::where('type', AccountType::DEBT)->first();
if(null === $ccType || null === $debtType) {
$ccType = AccountType::where('type', AccountType::CREDITCARD)->first();
$debtType = AccountType::where('type', AccountType::DEBT)->first();
if (null === $ccType || null === $debtType) {
return;
}
/** @var Collection $accounts */
$accounts = Account::where('account_type_id', $ccType->id)->get();
foreach($accounts as $account) {
foreach ($accounts as $account) {
$account->account_type_id = $debtType->id;
$account->save();
$this->line(sprintf('Converted credit card liability account "%s" (#%d) to generic debt liability.', $account->name, $account->id));
}
if($accounts->count() > 0) {
if ($accounts->count() > 0) {
$this->info('Credit card liability types are no longer supported and have been converted to generic debts. See: http://bit.ly/FF3-credit-cards');
}
}

View File

@@ -25,7 +25,6 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands;
use Crypt;
use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
@@ -42,10 +41,8 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Log;
use Schema;
use stdClass;

View File

@@ -30,6 +30,7 @@ use Log;
/**
* File to make sure commands work.
*
* @codeCoverageIgnore
*/
class Kernel extends ConsoleKernel
@@ -54,7 +55,9 @@ class Kernel extends ConsoleKernel
{
$schedule->call(
function () {
Log::error('Firefly III no longer users the Laravel scheduler to do cron jobs! Please read the instructions at https://firefly-iii.readthedocs.io/en/latest/');
Log::error(
'Firefly III no longer users the Laravel scheduler to do cron jobs! Please read the instructions at https://firefly-iii.readthedocs.io/en/latest/'
);
echo "\n";
echo '------------';
echo "\n";