mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-23 20:38:46 +00:00
Code cleanup that (hopefully) matches style CI
This commit is contained in:
@@ -26,7 +26,9 @@ use Crypt;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Contracts\Encryption\EncryptException;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -50,18 +52,19 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
/** @var int Max upload size. */
|
||||
protected $maxUploadSize = 0;
|
||||
|
||||
/** @var \Illuminate\Contracts\Filesystem\Filesystem The disk where attachments are stored. */
|
||||
/** @var Filesystem The disk where attachments are stored. */
|
||||
protected $uploadDisk;
|
||||
|
||||
|
||||
/**
|
||||
* AttachmentHelper constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->maxUploadSize = (int)config('firefly.maxUploadSize');
|
||||
$this->allowedMimes = (array)config('firefly.allowedMimes');
|
||||
$this->maxUploadSize = (int) config('firefly.maxUploadSize');
|
||||
$this->allowedMimes = (array) config('firefly.allowedMimes');
|
||||
$this->errors = new MessageBag;
|
||||
$this->messages = new MessageBag;
|
||||
$this->attachments = new Collection;
|
||||
@@ -104,16 +107,18 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
* Returns the file path relative to upload disk for an attachment,
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getAttachmentLocation(Attachment $attachment): string
|
||||
{
|
||||
return sprintf('%sat-%d.data', DIRECTORY_SEPARATOR, (int)$attachment->id);
|
||||
return sprintf('%sat-%d.data', DIRECTORY_SEPARATOR, (int) $attachment->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all attachments.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -198,8 +203,8 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
* @param object $model
|
||||
* @param array|null $files
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
* @return bool
|
||||
*/
|
||||
public function saveAttachmentsForModel(object $model, ?array $files): bool
|
||||
{
|
||||
@@ -242,7 +247,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$count = $model->user->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
|
||||
$result = false;
|
||||
if ($count > 0) {
|
||||
$msg = (string)trans('validation.file_already_attached', ['name' => $name]);
|
||||
$msg = (string) trans('validation.file_already_attached', ['name' => $name]);
|
||||
$this->errors->add('attachments', $msg);
|
||||
Log::error($msg);
|
||||
$result = true;
|
||||
@@ -257,9 +262,9 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
* @param UploadedFile $file
|
||||
* @param Model $model
|
||||
*
|
||||
* @return Attachment|null
|
||||
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
||||
* @throws EncryptException
|
||||
* @throws FireflyException
|
||||
* @return Attachment|null
|
||||
*/
|
||||
protected function processFile(UploadedFile $file, Model $model): ?Attachment
|
||||
{
|
||||
@@ -286,7 +291,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
throw new FireflyException('Cannot upload empty or non-existent file.'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$content = $fileObject->fread($file->getSize());
|
||||
$content = $fileObject->fread($file->getSize());
|
||||
Log::debug(sprintf('Full file length is %d and upload size is %d.', strlen($content), $file->getSize()));
|
||||
|
||||
// store it:
|
||||
@@ -296,7 +301,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$this->attachments->push($attachment);
|
||||
|
||||
$name = e($file->getClientOriginalName()); // add message:
|
||||
$msg = (string)trans('validation.file_attached', ['name' => $name]);
|
||||
$msg = (string) trans('validation.file_attached', ['name' => $name]);
|
||||
$this->messages->add('attachments', $msg);
|
||||
}
|
||||
|
||||
@@ -320,7 +325,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$result = true;
|
||||
|
||||
if (!in_array($mime, $this->allowedMimes, true)) {
|
||||
$msg = (string)trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]);
|
||||
$msg = (string) trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]);
|
||||
$this->errors->add('attachments', $msg);
|
||||
Log::error($msg);
|
||||
|
||||
@@ -345,7 +350,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$name = e($file->getClientOriginalName());
|
||||
$result = true;
|
||||
if ($size > $this->maxUploadSize) {
|
||||
$msg = (string)trans('validation.file_too_large', ['name' => $name]);
|
||||
$msg = (string) trans('validation.file_too_large', ['name' => $name]);
|
||||
$this->errors->add('attachments', $msg);
|
||||
Log::error($msg);
|
||||
|
||||
|
Reference in New Issue
Block a user