Some code improvements.

This commit is contained in:
James Cole
2015-07-05 19:57:44 +02:00
parent c4ef379d0e
commit 170aebfe54
5 changed files with 57 additions and 31 deletions

View File

@@ -8,13 +8,12 @@ use Config;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Csv\Converter\ConverterInterface; use FireflyIII\Helpers\Csv\Converter\ConverterInterface;
use FireflyIII\Helpers\Csv\PostProcessing\PostProcessorInterface; use FireflyIII\Helpers\Csv\PostProcessing\PostProcessorInterface;
use FireflyIII\Helpers\Csv\Specifix\SpecifixInterface;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Illuminate\Support\MessageBag; use Illuminate\Support\MessageBag;
use Log; use Log;
use Preferences;
set_time_limit(0); set_time_limit(0);
@@ -127,7 +126,7 @@ class Importer
} }
// post processing and validating. // post processing and validating.
$data = $this->postProcess($data); $data = $this->postProcess($data, $row);
$result = $this->validateData($data); $result = $this->validateData($data);
if ($result === true) { if ($result === true) {
$result = $this->createTransactionJournal($data); $result = $this->createTransactionJournal($data);
@@ -167,11 +166,24 @@ class Importer
* Row denotes the original data. * Row denotes the original data.
* *
* @param array $data * @param array $data
* @param array $row
* *
* @return array * @return array
*/ */
protected function postProcess(array $data) protected function postProcess(array $data, array $row)
{ {
// do bank specific fixes (must be enabled but now all of them.
$set = Config::get('csv.specifix');
foreach ($set as $className) {
/** @var SpecifixInterface $specifix */
$specifix = App::make('FireflyIII\Helpers\Csv\Specifix\\' . $className);
$specifix->setData($data);
$specifix->setRow($row);
$data = $specifix->fix();
}
$set = Config::get('csv.post_processors'); $set = Config::get('csv.post_processors');
foreach ($set as $className) { foreach ($set as $className) {
/** @var PostProcessorInterface $postProcessor */ /** @var PostProcessorInterface $postProcessor */
@@ -180,7 +192,6 @@ class Importer
$data = $postProcessor->process(); $data = $postProcessor->process();
} }
// do bank specific fixes: TODO
// $specifix = new Specifix(); // $specifix = new Specifix();
// $specifix->setData($data); // $specifix->setData($data);

View File

@@ -4,6 +4,8 @@ namespace FireflyIII\Helpers\Csv\PostProcessing;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use Auth; use Auth;
use FireflyIII\Validation\FireflyValidator;
use Validator;
/** /**
* Class OpposingAccount * Class OpposingAccount
@@ -36,8 +38,11 @@ class OpposingAccount implements PostProcessorInterface
return $this->data; return $this->data;
} }
$rules = ['iban' => 'iban'];
$check = ['iban' => $this->data['opposing-account-iban']];
$validator = Validator::make($check, $rules);
if (is_string($this->data['opposing-account-iban'])) { if (is_string($this->data['opposing-account-iban']) && $validator->valid()) {
$this->data['opposing-account-object'] = $this->parseIbanString(); $this->data['opposing-account-object'] = $this->parseIbanString();

View File

@@ -1,13 +1,13 @@
<?php <?php
namespace FireflyIII\Helpers\Csv; namespace FireflyIII\Helpers\Csv\Specifix;
/** /**
* Class Specifix * Class RabobankDescription
* *
* @package FireflyIII\Helpers\Csv * @package FireflyIII\Helpers\Csv\Specifix
*/ */
class Specifix class RabobankDescription
{ {
/** @var array */ /** @var array */
protected $data; protected $data;
@@ -17,12 +17,14 @@ class Specifix
/** /**
* Implement bank and locale related fixes. * @return array
*/ */
public function fix() public function fix()
{ {
$this->rabobankFixEmptyOpposing(); $this->rabobankFixEmptyOpposing();
return $this->data;
} }
/** /**
@@ -30,21 +32,12 @@ class Specifix
*/ */
protected function rabobankFixEmptyOpposing() protected function rabobankFixEmptyOpposing()
{ {
if (strlen($this->data['opposing-account']) == 0) { if (strlen($this->data['opposing-account-name']) == 0) {
$this->data['opposing-account'] = $this->row[10]; $this->data['opposing-account-name'] = $this->row[10];
} }
$this->data['description'] = trim(str_replace($this->row[10], '', $this->data['description'])); $this->data['description'] = trim(str_replace($this->row[10], '', $this->data['description']));
} }
/**
* @return array
*/
public function getData()
{
return $this->data;
}
/** /**
* @param array $data * @param array $data
*/ */
@@ -53,14 +46,6 @@ class Specifix
$this->data = $data; $this->data = $data;
} }
/**
* @return array
*/
public function getRow()
{
return $this->row;
}
/** /**
* @param array $row * @param array $row
*/ */

View File

@@ -0,0 +1,25 @@
<?php
namespace FireflyIII\Helpers\Csv\Specifix;
/**
* Interface SpecifixInterface
*
* @package FireflyIII\Helpers\Csv\Specifix
*/
interface SpecifixInterface
{
/**
* Implement bank and locale related fixes.
*/
public function fix();
/**
* @param array $data
*/
public function setData($data);
/**
* @param array $row
*/
public function setRow($row);
}

View File

@@ -1,7 +1,7 @@
<?php <?php
return [ return [
'specifix' => [ 'specifix' => [
'rabo_description' 'RabobankDescription'
], ],
'post_processors' => [ 'post_processors' => [
'OpposingAccount', 'OpposingAccount',