mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code consistency and new tests.
This commit is contained in:
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Import\Routine\Fake;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
@@ -34,17 +35,8 @@ use Carbon\Carbon;
|
||||
*/
|
||||
class StageFinalHandler
|
||||
{
|
||||
|
||||
private $job;
|
||||
|
||||
/**
|
||||
* @param mixed $job
|
||||
*/
|
||||
public function setJob($job): void
|
||||
{
|
||||
$this->job = $job;
|
||||
}
|
||||
|
||||
/** @var ImportJob */
|
||||
private $importJob;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@@ -58,7 +50,7 @@ class StageFinalHandler
|
||||
'type' => 'withdrawal',
|
||||
'date' => Carbon::create()->format('Y-m-d'),
|
||||
'tags' => '',
|
||||
'user' => $this->job->user_id,
|
||||
'user' => $this->importJob->user_id,
|
||||
|
||||
// all custom fields:
|
||||
'internal_reference' => null,
|
||||
@@ -103,7 +95,7 @@ class StageFinalHandler
|
||||
'type' => 'transfer',
|
||||
'date' => '2017-02-28',
|
||||
'tags' => '',
|
||||
'user' => $this->job->user_id,
|
||||
'user' => $this->importJob->user_id,
|
||||
|
||||
// all custom fields:
|
||||
'internal_reference' => null,
|
||||
@@ -145,4 +137,12 @@ class StageFinalHandler
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $importJob
|
||||
*/
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
$this->importJob = $importJob;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -80,11 +80,11 @@ class CSVProcessor implements FileProcessorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param ImportJob $importJob
|
||||
*/
|
||||
public function setImportJob(ImportJob $job): void
|
||||
public function setImportJob(ImportJob $importJob): void
|
||||
{
|
||||
Log::debug('Now in setJob()');
|
||||
$this->importJob = $job;
|
||||
Log::debug('Now in setImportJob()');
|
||||
$this->importJob = $importJob;
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ interface FileProcessorInterface
|
||||
/**
|
||||
* Set values.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param ImportJob $importJob
|
||||
*/
|
||||
public function setImportJob(ImportJob $job): void;
|
||||
public function setImportJob(ImportJob $importJob): void;
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Placeholder\ImportTransaction;
|
||||
use InvalidArgumentException;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -112,6 +113,8 @@ class ImportableConverter
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param array $mappedValues
|
||||
*/
|
||||
public function setMappedValues(array $mappedValues): void
|
||||
@@ -179,18 +182,27 @@ class ImportableConverter
|
||||
Log::debug('Destination is an expense account. This is a withdrawal.');
|
||||
$transactionType = 'withdrawal';
|
||||
}
|
||||
if ($transactionType === 'unknown') {
|
||||
Log::error(
|
||||
if ($destination->id === $source->id) {
|
||||
throw new FireflyException(
|
||||
sprintf(
|
||||
'Cannot determine transaction type. Source account is a %s, destination is a %s',
|
||||
$source->accountType->type, $destination->accountType->type
|
||||
), ['source' => $source->toArray(), 'dest' => $destination->toArray()]
|
||||
'Source ("%s", #%d) and destination ("%s", #%d) are the same account.', $source->name, $source->id, $destination->name, $destination->id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($transactionType === 'unknown') {
|
||||
$message = sprintf(
|
||||
'Cannot determine transaction type. Source account is a %s, destination is a %s', $source->accountType->type, $destination->accountType->type
|
||||
);
|
||||
Log::error($message, ['source' => $source->toArray(), 'dest' => $destination->toArray()]);
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
|
||||
// throw error when both are he same
|
||||
|
||||
try {
|
||||
$date = Carbon::createFromFormat($this->config['date-format'] ?? 'Ymd', $importable->date);
|
||||
} catch (InvalidDateException $e) {
|
||||
} catch (InvalidDateException|InvalidArgumentException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$date = new Carbon;
|
||||
|
@@ -82,6 +82,7 @@ class MappingConverger
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getMappedValues(): array
|
||||
|
Reference in New Issue
Block a user