mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Improve code quality for Export directory.
This commit is contained in:
parent
52f02cb9eb
commit
57345113b5
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AttachmentCollector.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
@ -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 CollectorInterface
|
||||
if ($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(): Collection
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 mixed
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* UploadCollector.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
@ -84,7 +83,10 @@ class UploadCollector extends BasicCollector implements CollectorInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @noinspection MultipleReturnStatementsInspection */
|
||||
/**
|
||||
* Process new file uploads.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ExpandedProcessor.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
@ -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 array
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 ExporterInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a temp file.
|
||||
*/
|
||||
private function tempFile()
|
||||
{
|
||||
$this->fileName = $this->job->key . '-records.csv';
|
||||
|
@ -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);
|
||||
|
@ -37,41 +37,57 @@ interface ProcessorInterface
|
||||
public 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);
|
||||
|
Loading…
Reference in New Issue
Block a user