From 170aebfe543625465714f631c54d7354a3edb3ba Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 5 Jul 2015 19:57:44 +0200 Subject: [PATCH] Some code improvements. --- app/Helpers/Csv/Importer.php | 21 +++++++++--- .../Csv/PostProcessing/OpposingAccount.php | 7 +++- .../RabobankDescription.php} | 33 +++++-------------- .../Csv/Specifix/SpecifixInterface.php | 25 ++++++++++++++ config/csv.php | 2 +- 5 files changed, 57 insertions(+), 31 deletions(-) rename app/Helpers/Csv/{Specifix.php => Specifix/RabobankDescription.php} (62%) create mode 100644 app/Helpers/Csv/Specifix/SpecifixInterface.php diff --git a/app/Helpers/Csv/Importer.php b/app/Helpers/Csv/Importer.php index ca2e2e2d1f..07372518e6 100644 --- a/app/Helpers/Csv/Importer.php +++ b/app/Helpers/Csv/Importer.php @@ -8,13 +8,12 @@ use Config; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Csv\Converter\ConverterInterface; use FireflyIII\Helpers\Csv\PostProcessing\PostProcessorInterface; +use FireflyIII\Helpers\Csv\Specifix\SpecifixInterface; use FireflyIII\Models\Transaction; -use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; use Illuminate\Support\MessageBag; use Log; -use Preferences; set_time_limit(0); @@ -127,7 +126,7 @@ class Importer } // post processing and validating. - $data = $this->postProcess($data); + $data = $this->postProcess($data, $row); $result = $this->validateData($data); if ($result === true) { $result = $this->createTransactionJournal($data); @@ -167,11 +166,24 @@ class Importer * Row denotes the original data. * * @param array $data + * @param array $row * * @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'); foreach ($set as $className) { /** @var PostProcessorInterface $postProcessor */ @@ -180,7 +192,6 @@ class Importer $data = $postProcessor->process(); } - // do bank specific fixes: TODO // $specifix = new Specifix(); // $specifix->setData($data); diff --git a/app/Helpers/Csv/PostProcessing/OpposingAccount.php b/app/Helpers/Csv/PostProcessing/OpposingAccount.php index 1ffaafc721..91214edd05 100644 --- a/app/Helpers/Csv/PostProcessing/OpposingAccount.php +++ b/app/Helpers/Csv/PostProcessing/OpposingAccount.php @@ -4,6 +4,8 @@ namespace FireflyIII\Helpers\Csv\PostProcessing; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use Auth; +use FireflyIII\Validation\FireflyValidator; +use Validator; /** * Class OpposingAccount @@ -36,8 +38,11 @@ class OpposingAccount implements PostProcessorInterface 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(); diff --git a/app/Helpers/Csv/Specifix.php b/app/Helpers/Csv/Specifix/RabobankDescription.php similarity index 62% rename from app/Helpers/Csv/Specifix.php rename to app/Helpers/Csv/Specifix/RabobankDescription.php index 0e530d4a5d..2a2f7211e9 100644 --- a/app/Helpers/Csv/Specifix.php +++ b/app/Helpers/Csv/Specifix/RabobankDescription.php @@ -1,13 +1,13 @@ rabobankFixEmptyOpposing(); + return $this->data; + } /** @@ -30,21 +32,12 @@ class Specifix */ protected function rabobankFixEmptyOpposing() { - if (strlen($this->data['opposing-account']) == 0) { - $this->data['opposing-account'] = $this->row[10]; + if (strlen($this->data['opposing-account-name']) == 0) { + $this->data['opposing-account-name'] = $this->row[10]; } $this->data['description'] = trim(str_replace($this->row[10], '', $this->data['description'])); } - - /** - * @return array - */ - public function getData() - { - return $this->data; - } - /** * @param array $data */ @@ -53,14 +46,6 @@ class Specifix $this->data = $data; } - /** - * @return array - */ - public function getRow() - { - return $this->row; - } - /** * @param array $row */ diff --git a/app/Helpers/Csv/Specifix/SpecifixInterface.php b/app/Helpers/Csv/Specifix/SpecifixInterface.php new file mode 100644 index 0000000000..a71e3cb45a --- /dev/null +++ b/app/Helpers/Csv/Specifix/SpecifixInterface.php @@ -0,0 +1,25 @@ + [ - 'rabo_description' + 'RabobankDescription' ], 'post_processors' => [ 'OpposingAccount',