Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Improve code quality for Export directory.
James Cole57345113b5f4
diff --git a/app/Export/Collector/AttachmentCollector.php b/app/Export/Collector/AttachmentCollector.phpindex 0db72ed3a2..9eecde245b 100644--- a/app/Export/Collector/AttachmentCollector.php+++ b/app/Export/Collector/AttachmentCollector.php@@ -1,5 +1,4 @@<?php-/*** AttachmentCollector.php* Copyright (c) 2018 [email protected]@@ -29,6 +28,7 @@ use Crypt;use FireflyIII\Models\Attachment;use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;use Illuminate\Contracts\Encryption\DecryptException;+use Illuminate\Contracts\Filesystem\FileNotFoundException;use Illuminate\Support\Collection;use Log;use Storage;@@ -38,15 +38,15 @@ use Storage;*/class AttachmentCollector extends BasicCollector implements CollectorInterface{- /** @var Carbon */+ /** @var Carbon The end date of the range. */private $end;- /** @var \Illuminate\Contracts\Filesystem\Filesystem */+ /** @var \Illuminate\Contracts\Filesystem\Filesystem File system */private $exportDisk;- /** @var AttachmentRepositoryInterface */+ /** @var AttachmentRepositoryInterface Attachment repository */private $repository;- /** @var Carbon */+ /** @var Carbon Start date of range */private $start;- /** @var \Illuminate\Contracts\Filesystem\Filesystem */+ /** @var \Illuminate\Contracts\Filesystem\Filesystem Disk with uploads on it */private $uploadDisk;/**@@ -64,6 +64,8 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface}/**+ * Run the routine.+ ** @return bool*/public function run(): bool@@ -80,6 +82,8 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface}/**+ * Set the start and end date.+ ** @param Carbon $start* @param Carbon $end*/@@ -89,7 +93,10 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface$this->end = $end;}+ /** @noinspection MultipleReturnStatementsInspection *//**+ * Export attachments.+ ** @param Attachment $attachment** @return bool@@ -101,13 +108,13 @@ class AttachmentCollector extends BasicCollector implements CollectorInterfaceif ($this->uploadDisk->exists($file)) {try {$decrypted = Crypt::decrypt($this->uploadDisk->get($file));- } catch (DecryptException $e) {+ } catch (FileNotFoundException|DecryptException $e) {Log::error('Catchable error: could not decrypt attachment #' . $attachment->id . ' because: ' . $e->getMessage());return false;}}- if ($decrypted === false) {+ if (false === $decrypted) {return false;}$exportFile = $this->exportFileName($attachment);@@ -130,6 +137,8 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface}/**+ * Get the attachments.+ ** @return Collection*/private function getAttachments(): Collectiondiff --git a/app/Export/Collector/BasicCollector.php b/app/Export/Collector/BasicCollector.phpindex bc19f1f541..10215d6c58 100644--- a/app/Export/Collector/BasicCollector.php+++ b/app/Export/Collector/BasicCollector.php@@ -33,11 +33,11 @@ use Illuminate\Support\Collection;*/class BasicCollector{- /** @var ExportJob */+ /** @var ExportJob The job to export. */protected $job;- /** @var User */+ /** @var User The user */protected $user;- /** @var Collection */+ /** @var Collection All the entries. */private $entries;/**@@ -49,6 +49,8 @@ class BasicCollector}/**+ * Get all entries.+ ** @return Collection*/public function getEntries(): Collection@@ -57,26 +59,32 @@ class BasicCollector}/**+ * Set entries.+ ** @param Collection $entries*/- public function setEntries(Collection $entries)+ public function setEntries(Collection $entries): void{$this->entries = $entries;}/**+ * Set export job.+ ** @param ExportJob $job*/- public function setJob(ExportJob $job)+ public function setJob(ExportJob $job): void{$this->job = $job;$this->user = $job->user;}/**+ * Set user.+ ** @param User $user*/- public function setUser(User $user)+ public function setUser(User $user): void{$this->user = $user;}diff --git a/app/Export/Collector/CollectorInterface.php b/app/Export/Collector/CollectorInterface.phpindex bd40c82f29..b93dc1617b 100644--- a/app/Export/Collector/CollectorInterface.php+++ b/app/Export/Collector/CollectorInterface.php@@ -33,21 +33,29 @@ use Illuminate\Support\Collection;interface CollectorInterface{/**+ * Get entries.+ ** @return Collection*/public function getEntries(): Collection;/**+ * Run the collector.+ ** @return bool*/public function run(): bool;/**+ * Set entries.+ ** @param Collection $entries*/public function setEntries(Collection $entries);/**+ * Set export job.+ ** @param ExportJob $job** @return mixeddiff --git a/app/Export/Collector/UploadCollector.php b/app/Export/Collector/UploadCollector.phpindex dd8c71e769..5e1e6df02b 100644--- a/app/Export/Collector/UploadCollector.php+++ b/app/Export/Collector/UploadCollector.php@@ -1,5 +1,4 @@<?php-/*** UploadCollector.php* Copyright (c) 2018 [email protected]@@ -84,7 +83,10 @@ class UploadCollector extends BasicCollector implements CollectorInterfacereturn true;}+ /** @noinspection MultipleReturnStatementsInspection *//**+ * Process new file uploads.+ ** @param string $key** @return booldiff --git a/app/Export/Entry/Entry.php b/app/Export/Entry/Entry.phpindex 55886a2697..8543c75646 100644--- a/app/Export/Entry/Entry.php+++ b/app/Export/Entry/Entry.php@@ -46,137 +46,65 @@ use FireflyIII\Models\Transaction;*/final class Entry{- // @formatter:off- /**- * @var int- */+ /** @var int ID of the journal */public $journal_id;- /**- * @var int- */+ /** @var int ID of the transaction */public $transaction_id = 0;-- /**- * @var string- */+ /** @var string The date. */public $date;- /**- * @var string- */+ /** @var string The description */public $description;-- /**- * @var string- */+ /** @var string The currency code. */public $currency_code;- /**- * @var string- */+ /** @var string The amount. */public $amount;- /**- * @var string- */+ /** @var string The foreign currency code */public $foreign_currency_code = '';- /**- * @var string- */+ /** @var string Foreign amount */public $foreign_amount = '0';-- /**- * @var string- */+ /** @var string Transaction type */public $transaction_type;-- /**- * @var string- */+ /** @var string Asset account ID */public $asset_account_id;- /**- * @var string- */+ /** @var string Asset account name */public $asset_account_name;- /**- * @var string- */+ /** @var string Asset account IBAN */public $asset_account_iban;- /**- * @var string- */+ /** @var string Asset account BIC */public $asset_account_bic;- /**- * @var string- */+ /** @var string Asset account number */public $asset_account_number;- /**- * @var string- */+ /** @var string Asset account currency code */public $asset_currency_code;-- /**- * @var string- */+ /** @var string Opposing account ID */public $opposing_account_id;- /**- * @var string- */+ /** @var string Opposing account name */public $opposing_account_name;- /**- * @var string- */+ /** @var string Opposing account IBAN */public $opposing_account_iban;- /**- * @var string- */+ /** @var string Opposing account BIC */public $opposing_account_bic;- /**- * @var string- */+ /** @var string Opposing account number */public $opposing_account_number;- /**- * @var string- */+ /** @var string Opposing account code */public $opposing_currency_code;-- /**- * @var string- */+ /** @var string Budget ID */public $budget_id;- /**- * @var string- */+ /** @var string Budget name */public $budget_name;-- /**- * @var string- */+ /** @var string Category ID */public $category_id;- /**- * @var string- */+ /** @var string Category name */public $category_name;-- /**- * @var string- */+ /** @var string Bill ID */public $bill_id;- /**- * @var string- */+ /** @var string Bill name */public $bill_name;-- /**- * @var string- */+ /** @var string Notes */public $notes;-- /**- * @var string- */+ /** @var string Tags */public $tags;-- // @formatter:on-/*** Entry constructor.*/diff --git a/app/Export/ExpandedProcessor.php b/app/Export/ExpandedProcessor.phpindex 3c964efeba..f20c25e0a7 100644--- a/app/Export/ExpandedProcessor.php+++ b/app/Export/ExpandedProcessor.php@@ -1,5 +1,4 @@<?php-/*** ExpandedProcessor.php* Copyright (c) 2018 [email protected]@@ -20,6 +19,8 @@* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.*/+/** @noinspection PhpDynamicAsStaticMethodCallInspection */+declare(strict_types=1);namespace FireflyIII\Export;@@ -50,23 +51,23 @@ use ZipArchive;*/class ExpandedProcessor implements ProcessorInterface{- /** @var Collection */+ /** @var Collection All accounts */public $accounts;- /** @var string */+ /** @var string The export format*/public $exportFormat;- /** @var bool */+ /** @var bool Should include attachments */public $includeAttachments;- /** @var bool */+ /** @var bool Should include old uploads */public $includeOldUploads;- /** @var ExportJob */+ /** @var ExportJob The export job itself */public $job;- /** @var array */+ /** @var array The settings*/public $settings;- /** @var Collection */+ /** @var Collection The entries to export. */private $exportEntries;- /** @var Collection */+ /** @var Collection The files to export */private $files;- /** @var Collection */+ /** @var Collection The journals. */private $journals;/**@@ -80,6 +81,8 @@ class ExpandedProcessor implements ProcessorInterface}/**+ * Collect all attachments+ ** @return bool*/public function collectAttachments(): bool@@ -143,6 +146,8 @@ class ExpandedProcessor implements ProcessorInterface}/**+ * Get old oploads.+ ** @return bool*/public function collectOldUploads(): bool@@ -158,6 +163,8 @@ class ExpandedProcessor implements ProcessorInterface}/**+ * Convert journals to export objects.+ ** @return bool*/public function convertJournals(): bool@@ -173,6 +180,8 @@ class ExpandedProcessor implements ProcessorInterface}/**+ * Create a ZIP file.+ ** @return bool** @throws FireflyException@@ -204,6 +213,8 @@ class ExpandedProcessor implements ProcessorInterface}/**+ * Export the journals.+ ** @return bool*/public function exportJournals(): bool@@ -219,6 +230,8 @@ class ExpandedProcessor implements ProcessorInterface}/**+ * Get files.+ ** @return Collection*/public function getFiles(): Collection@@ -231,7 +244,7 @@ class ExpandedProcessor implements ProcessorInterface** @param array $settings*/- public function setSettings(array $settings)+ public function setSettings(array $settings): void{// save settings$this->settings = $settings;@@ -243,9 +256,9 @@ class ExpandedProcessor implements ProcessorInterface}/**- *+ * Delete files.*/- private function deleteFiles()+ private function deleteFiles():void{$disk = Storage::disk('export');foreach ($this->getFiles() as $file) {@@ -254,6 +267,8 @@ class ExpandedProcessor implements ProcessorInterface}/**+ * Get currencies.+ ** @param array $array** @return arraydiff --git a/app/Export/Exporter/BasicExporter.php b/app/Export/Exporter/BasicExporter.phpindex 02826171c2..fd1003ddfa 100644--- a/app/Export/Exporter/BasicExporter.php+++ b/app/Export/Exporter/BasicExporter.php@@ -32,9 +32,9 @@ use Illuminate\Support\Collection;*/class BasicExporter{- /** @var ExportJob */+ /** @var ExportJob The export job */protected $job;- /** @var Collection */+ /** @var Collection The entries */private $entries;/**@@ -46,6 +46,8 @@ class BasicExporter}/**+ * Get all entries.+ ** @return Collection*/public function getEntries(): Collection@@ -54,17 +56,21 @@ class BasicExporter}/**+ * Set all entries.+ ** @param Collection $entries*/- public function setEntries(Collection $entries)+ public function setEntries(Collection $entries): void{$this->entries = $entries;}/**+ * Set the job.+ ** @param ExportJob $job*/- public function setJob(ExportJob $job)+ public function setJob(ExportJob $job): void{$this->job = $job;}diff --git a/app/Export/Exporter/CsvExporter.php b/app/Export/Exporter/CsvExporter.phpindex e323b94bf9..bbc66b8345 100644--- a/app/Export/Exporter/CsvExporter.php+++ b/app/Export/Exporter/CsvExporter.php@@ -33,10 +33,12 @@ use Storage;*/class CsvExporter extends BasicExporter implements ExporterInterface{- /** @var string */+ /** @var string Filename */private $fileName;/**+ * Get file name.+ ** @return string*/public function getFileName(): string@@ -45,6 +47,8 @@ class CsvExporter extends BasicExporter implements ExporterInterface}/**+ * Run collector.+ ** @return bool**/@@ -83,6 +87,9 @@ class CsvExporter extends BasicExporter implements ExporterInterfacereturn true;}+ /**+ * Make a temp file.+ */private function tempFile(){$this->fileName = $this->job->key . '-records.csv';diff --git a/app/Export/Exporter/ExporterInterface.php b/app/Export/Exporter/ExporterInterface.phpindex f10e763dab..cc44b69c08 100644--- a/app/Export/Exporter/ExporterInterface.php+++ b/app/Export/Exporter/ExporterInterface.php@@ -33,26 +33,36 @@ use Illuminate\Support\Collection;interface ExporterInterface{/**+ * Get entries.+ ** @return Collection*/public function getEntries(): Collection;/**+ * Get file name.+ ** @return string*/public function getFileName(): string;/**+ * Run exporter.+ ** @return bool*/public function run(): bool;/**+ * Set entries.+ ** @param Collection $entries*/public function setEntries(Collection $entries);/**+ * Set job.+ ** @param ExportJob $job*/public function setJob(ExportJob $job);diff --git a/app/Export/ProcessorInterface.php b/app/Export/ProcessorInterface.phpindex ad8745cc7c..641e26eaeb 100644--- a/app/Export/ProcessorInterface.php+++ b/app/Export/ProcessorInterface.php@@ -37,41 +37,57 @@ interface ProcessorInterfacepublic function __construct();/**+ * Collect all attachments.+ ** @return bool*/public function collectAttachments(): bool;/**+ * Collect all journals.+ ** @return bool*/public function collectJournals(): bool;/**+ * Collect old uploads.+ ** @return bool*/public function collectOldUploads(): bool;/**+ * Convert all journals.+ ** @return bool*/public function convertJournals(): bool;/**+ * Create a zip file.+ ** @return bool*/public function createZipFile(): bool;/**+ * Export journals.+ ** @return bool*/public function exportJournals(): bool;/**+ * Get all files.+ ** @return Collection*/public function getFiles(): Collection;/**+ * Set the settings.+ ** @param array $settings*/public function setSettings(array $settings);