mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-03 19:28:40 +00:00
Improve test coverage.
This commit is contained in:
@@ -46,16 +46,19 @@ class IsValidAttachmentModel implements Rule
|
||||
/**
|
||||
* IsValidAttachmentModel constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $model
|
||||
*/
|
||||
public function __construct(string $model)
|
||||
{
|
||||
$model = $this->normalizeModel($model);
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function message(): string
|
||||
@@ -78,9 +81,9 @@ class IsValidAttachmentModel implements Rule
|
||||
if (!auth()->check()) {
|
||||
return false;
|
||||
}
|
||||
$model = false === strpos('FireflyIII', $this->model) ? 'FireflyIII\\Models\\' . $this->model : $this->model;
|
||||
|
||||
if (Bill::class === $model) {
|
||||
|
||||
if (Bill::class === $this->model) {
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
/** @var User $user */
|
||||
@@ -91,7 +94,7 @@ class IsValidAttachmentModel implements Rule
|
||||
return null !== $bill;
|
||||
}
|
||||
|
||||
if (ImportJob::class === $model) {
|
||||
if (ImportJob::class === $this->model) {
|
||||
/** @var ImportJobRepositoryInterface $repository */
|
||||
$repository = app(ImportJobRepositoryInterface::class);
|
||||
/** @var User $user */
|
||||
@@ -102,7 +105,7 @@ class IsValidAttachmentModel implements Rule
|
||||
return null !== $importJob;
|
||||
}
|
||||
|
||||
if (Transaction::class === $model) {
|
||||
if (Transaction::class === $this->model) {
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
/** @var User $user */
|
||||
@@ -113,7 +116,7 @@ class IsValidAttachmentModel implements Rule
|
||||
return null !== $transaction;
|
||||
}
|
||||
|
||||
if (TransactionJournal::class === $model) {
|
||||
if (TransactionJournal::class === $this->model) {
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$user = auth()->user();
|
||||
$repository->setUser($user);
|
||||
@@ -121,8 +124,23 @@ class IsValidAttachmentModel implements Rule
|
||||
|
||||
return null !== $result;
|
||||
}
|
||||
Log::error(sprintf('No model was recognized from string "%s"', $model));
|
||||
Log::error(sprintf('No model was recognized from string "%s"', $this->model));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function normalizeModel(string $model): string
|
||||
{
|
||||
$search = ['FireflyIII\Models\\'];
|
||||
$replace = '';
|
||||
$model = str_replace($search, $replace, $model);
|
||||
|
||||
$model = sprintf('FireflyIII\Models\%s', $model);
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user