Code cleanup.

This commit is contained in:
James Cole
2016-08-12 15:10:03 +02:00
parent 955306d877
commit 5c4d010bde
94 changed files with 106 additions and 363 deletions

View File

@@ -51,7 +51,7 @@ class EncryptFile extends Command
*/
public function handle()
{
$file = $this->argument('file');
$file = e($this->argument('file'));
if (!file_exists($file)) {
$this->error(sprintf('File "%s" does not seem to exist.', $file));

View File

@@ -19,7 +19,6 @@ use FireflyIII\Import\Logging\CommandHandler;
use FireflyIII\Models\ImportJob;
use Illuminate\Console\Command;
use Log;
use Monolog\Handler\StreamHandler;
/**
* Class Import
@@ -73,7 +72,11 @@ class Import extends Command
}
$this->line('Going to import job with key "' . $job->key . '" of type ' . $job->file_type);
$valid = array_keys(config('firefly.import_formats'));
$class = 'INVALID';
if (in_array($job->file_type, $valid)) {
$class = config('firefly.import_formats.' . $job->file_type);
}
/** @var ImporterInterface $importer */
$importer = app($class);
@@ -98,7 +101,7 @@ class Import extends Command
$cleaned = $validator->clean();
// then import collection:
$storage = new ImportStorage($collection);
$storage = new ImportStorage($cleaned);
$storage->setUser($job->user);
// and run store routine:

View File

@@ -119,7 +119,7 @@ class AccountCrud implements AccountCrudInterface
*/
public function findByIban(string $iban, array $types): Account
{
$query = $this->user->accounts()->where('iban', '!=', "");
$query = $this->user->accounts()->where('iban', '!=', '');
if (count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');

View File

@@ -83,10 +83,10 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface
/** @var TransactionJournal $journal */
$journal = $attachment->attachable;
$args = [
'attachment_name' => $attachment->filename,
'attachment_name' => e($attachment->filename),
'attachment_id' => $attachment->id,
'type' => strtolower($journal->transactionType->type),
'description' => $journal->description,
'description' => e($journal->description),
'journal_id' => $journal->id,
'date' => $journal->date->formatLocalized(strval(trans('config.month_and_day'))),
'amount' => Amount::formatJournal($journal, false),

View File

@@ -45,8 +45,6 @@ class UploadCollector extends BasicCollector implements CollectorInterface
// make storage:
$this->uploadDisk = Storage::disk('upload');
$this->exportDisk = Storage::disk('export');
// todo needs work for new importer (potentially collect other types as well)
$this->expected = 'csv-upload-' . Auth::user()->id . '-';
}

View File

@@ -28,10 +28,12 @@ class UserController extends Controller
/**
* @param User $user
*
* @return int
*/
public function edit(User $user)
{
return $user->id;
}

View File

@@ -45,8 +45,7 @@ class ImportController extends Controller
*
* @param ImportJob $job
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws FireflyException
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/
public function complete(ImportJob $job)
{
@@ -54,7 +53,6 @@ class ImportController extends Controller
if (!$this->jobInCorrectStep($job, 'complete')) {
return $this->redirectToCorrectStep($job);
}
$importer = $this->makeImporter($job);
$subTitle = trans('firefy.import_complete');
$subTitleIcon = 'fa-star';
@@ -305,14 +303,11 @@ class ImportController extends Controller
case 'configure':
case 'process':
return $job->status === 'import_status_never_started';
break;
case 'settings':
case 'store-settings':
return $job->status === 'import_configuration_saved';
break;
case 'complete':
return $job->status === 'settings_complete';
break;
}
return false;

View File

@@ -107,6 +107,8 @@ class Range
$ranges['next'] = [$nextStart->format('Y-m-d'), $nextEnd->format('Y-m-d')];
switch ($viewRange) {
default:
throw new FireflyException('The date picker does not yet support "' . $viewRange . '".');
case '1D':
$format = (string)trans('config.month_and_day');
break;
@@ -122,8 +124,6 @@ class Range
case '1M':
$format = (string)trans('config.month');
break;
default:
throw new FireflyException('The date picker does not yet support "' . $viewRange . '".');
case '1W':
$format = (string)trans('config.week_in_year');
break;

View File

@@ -1,31 +0,0 @@
<?php
/**
* SomeConverter.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Import\Converter;
/**
* Class SomeConverter
*
* @package FireflyIII\Import\Converter
*/
class SomeConverter extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
*/
public function convert($value)
{
// // TODO: Implement convert() method.
// throw new NotImplementedException;
}
}

View File

@@ -55,7 +55,6 @@ class ImportEntry
*/
public function __construct()
{
$this->defaultImportAccount = new Account;
/** @var string $value */
foreach ($this->validFields as $value) {
$this->fields[$value] = null;
@@ -63,21 +62,6 @@ class ImportEntry
}
}
/**
* @return ImportResult
*/
public function import(): ImportResult
{
$validation = $this->validate();
if ($validation->valid()) {
return $this->doImport();
}
return $validation;
}
/**
* @param string $role
* @param int $certainty
@@ -91,14 +75,11 @@ class ImportEntry
default:
Log::error('Import entry cannot handle object.', ['role' => $role]);
throw new FireflyException('Import entry cannot handle object of type "' . $role . '".');
break;
case 'amount':
/*
* Easy enough.
*/
$this->setFloat('amount', $convertedValue, $certainty);
$this->applyMultiplier('amount'); // if present.
return;
@@ -147,7 +128,7 @@ class ImportEntry
case 'sepa-ct-id':
case 'sepa-db':
case 'sepa-ct-op':
case'description':
case 'description':
$this->setAppendableString('description', $convertedValue);
break;
case '_ignore':
@@ -160,6 +141,7 @@ class ImportEntry
case 'tags-comma':
case 'tags-space':
$this->appendCollection('tags', $convertedValue);
break;
case 'external-id':
$this->externalID = $convertedValue;
break;

View File

@@ -86,6 +86,8 @@ class CsvImporter implements ImporterInterface
// create import object. This is where each entry ends up.
$object = new ImportEntry;
Log::debug(sprintf('Now at row %d', $index));
// set some vars:
$object->setUser($this->job->user);
$config = $this->job->configuration;

View File

@@ -29,7 +29,7 @@ class AbnAmroDescription implements SpecificInterface
/**
* @return string
*/
static public function getDescription(): string
public static function getDescription(): string
{
return 'Fixes possible problems with ABN Amro descriptions.';
}
@@ -37,7 +37,7 @@ class AbnAmroDescription implements SpecificInterface
/**
* @return string
*/
static public function getName(): string
public static function getName(): string
{
return 'ABN Amro description';
}

View File

@@ -23,7 +23,7 @@ class RabobankDescription implements SpecificInterface
/**
* @return string
*/
static public function getDescription(): string
public static function getDescription(): string
{
return 'Fixes possible problems with Rabobank descriptions.';
}
@@ -31,7 +31,7 @@ class RabobankDescription implements SpecificInterface
/**
* @return string
*/
static public function getName(): string
public static function getName(): string
{
return 'Rabobank description';
}

View File

@@ -21,12 +21,12 @@ interface SpecificInterface
/**
* @return string
*/
static public function getName(): string;
public static function getName(): string;
/**
* @return string
*/
static public function getDescription(): string;
public static function getDescription(): string;
/**
* @param array $row

View File

@@ -28,7 +28,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property string $key
* @property string $file_type
* @property string $status
* @property string $configuration
* @property array $configuration
* @property-read \FireflyIII\User $user
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\ImportJob whereId($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\ImportJob whereCreatedAt($value)

View File

@@ -58,8 +58,6 @@ class CrudServiceProvider extends ServiceProvider
if (!isset($arguments[0]) && !$app->auth->check()) {
throw new FireflyException('There is no user present.');
}
// Log::debug('AccountCrud constructor, run with default arguments.', $arguments);
return app('FireflyIII\Crud\Account\AccountCrud', $arguments);
}
);

View File

@@ -444,12 +444,6 @@ class CategoryRepository implements CategoryRepositoryInterface
*/
public function store(array $data): Category
{
// TODO use validation, not this.
if (strlen($data['name']) > 200 || strlen($data['name']) === 0) {
}
$newCategory = Category::firstOrCreateEncrypted(
[
'user_id' => $data['user'],

View File

@@ -276,203 +276,4 @@ return [
'field' => 'description',
],
],
/*
'specifix' => [
'RabobankDescription',
'AbnAmroDescription',
'Dummy'
],
'post_processors' => [
'Description',
'Amount',
'Currency',
'Bill',
'OpposingAccount', // must be after Amount!
'AssetAccount',
],
'roles' => [
'_ignore' => [
'mappable' => false,
'converter' => 'Ignore',
'field' => 'ignored',
],
'bill-id' => [
'mappable' => false,
'field' => 'bill',
'converter' => 'BillId',
'mapper' => 'Bill',
],
'bill-name' => [
'mappable' => true,
'converter' => 'BillName',
'field' => 'bill',
'mapper' => 'Bill',
],
'currency-id' => [
'mappable' => true,
'converter' => 'CurrencyId',
'field' => 'currency',
'mapper' => 'TransactionCurrency'
],
'currency-name' => [
'mappable' => true,
'converter' => 'CurrencyName',
'field' => 'currency',
'mapper' => 'TransactionCurrency'
],
'currency-code' => [
'mappable' => true,
'converter' => 'CurrencyCode',
'field' => 'currency',
'mapper' => 'TransactionCurrency'
],
'currency-symbol' => [
'mappable' => true,
'converter' => 'CurrencySymbol',
'field' => 'currency',
'mapper' => 'TransactionCurrency'
],
'description' => [
'mappable' => false,
'converter' => 'Description',
'field' => 'description',
],
'date-transaction' => [
'mappable' => false,
'converter' => 'Date',
'field' => 'date',
],
'date-rent' => [
'mappable' => false,
'converter' => 'Date',
'field' => 'date-rent',
],
'budget-id' => [
'mappable' => true,
'converter' => 'BudgetId',
'field' => 'budget',
'mapper' => 'Budget',
],
'budget-name' => [
'mappable' => true,
'converter' => 'BudgetName',
'field' => 'budget',
'mapper' => 'Budget',
],
'rabo-debet-credit' => [
'mappable' => false,
'converter' => 'RabobankDebetCredit',
'field' => 'amount-modifier',
],
'ing-debet-credit' => [
'mappable' => false,
'converter' => 'INGDebetCredit',
'field' => 'amount-modifier',
],
'category-id' => [
'mappable' => true,
'converter' => 'CategoryId',
'field' => 'category',
'mapper' => 'Category',
],
'category-name' => [
'mappable' => true,
'converter' => 'CategoryName',
'field' => 'category',
'mapper' => 'Category',
],
'tags-comma' => [
'mappable' => true,
'field' => 'tags',
'converter' => 'TagsComma',
'mapper' => 'Tag',
],
'tags-space' => [
'mappable' => true,
'field' => 'tags',
'converter' => 'TagsSpace',
'mapper' => 'Tag',
],
'account-id' => [
'mappable' => true,
'mapper' => 'AssetAccount',
'field' => 'asset-account-id',
'converter' => 'AccountId'
],
'account-name' => [
'mappable' => true,
'mapper' => 'AssetAccount',
'field' => 'asset-account-name',
'converter' => 'AssetAccountName'
],
'account-iban' => [
'mappable' => true,
'converter' => 'AssetAccountIban',
'field' => 'asset-account-iban',
'mapper' => 'AssetAccount'
],
'account-number' => [
'mappable' => true,
'converter' => 'AssetAccountNumber',
'field' => 'asset-account-number',
'mapper' => 'AssetAccount'
],
'opposing-id' => [
'mappable' => true,
'field' => 'opposing-account-id',
'converter' => 'OpposingAccountId',
'mapper' => 'AnyAccount',
],
'opposing-name' => [
'mappable' => true,
'field' => 'opposing-account-name',
'converter' => 'OpposingAccountName',
'mapper' => 'AnyAccount',
],
'opposing-iban' => [
'mappable' => true,
'field' => 'opposing-account-iban',
'converter' => 'OpposingAccountIban',
'mapper' => 'AnyAccount',
],
'opposing-number' => [
'mappable' => true,
'field' => 'opposing-account-number',
'converter' => 'OpposingAccountNumber',
'mapper' => 'AnyAccount',
],
'amount' => [
'mappable' => false,
'converter' => 'Amount',
'field' => 'amount',
],
'amount-comma-separated' => [
'mappable' => false,
'converter' => 'AmountComma',
'field' => 'amount',
],
'sepa-ct-id' => [
'mappable' => false,
'converter' => 'Description',
'field' => 'description',
],
'sepa-ct-op' => [
'mappable' => false,
'converter' => 'Description',
'field' => 'description',
],
'sepa-db' => [
'mappable' => false,
'converter' => 'Description',
'field' => 'description',
],
]
*/
];

View File

@@ -56,7 +56,6 @@ class CreateMainTables extends Migration
$this->createBudgetTables();
$this->createCategoriesTable();
$this->createExportJobsTable();
// $this->createImportJobsTable();
$this->createPreferencesTable();
$this->createRoleTable();
$this->createRuleTables();

0
phpunit.xml Executable file → Normal file
View File