Various PSR12 code cleanup

This commit is contained in:
James Cole
2022-12-29 19:41:57 +01:00
parent 0022009dd5
commit dbf3e76ecc
340 changed files with 4079 additions and 3816 deletions

View File

@@ -1,4 +1,5 @@
<?php
/**
* AttachmentHelper.php
* Copyright (c) 2019 james@firefly-iii.org
@@ -57,8 +58,8 @@ class AttachmentHelper implements AttachmentHelperInterface
*/
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();
@@ -70,13 +71,13 @@ class AttachmentHelper implements AttachmentHelperInterface
*
* @codeCoverageIgnore
*
* @param Attachment $attachment
* @param Attachment $attachment
*
* @return string
*/
public function getAttachmentContent(Attachment $attachment): string
{
$encryptedData = (string) $this->uploadDisk->get(sprintf('at-%d.data', $attachment->id));
$encryptedData = (string)$this->uploadDisk->get(sprintf('at-%d.data', $attachment->id));
try {
$unencryptedData = Crypt::decrypt($encryptedData); // verified
} catch (DecryptException $e) {
@@ -90,14 +91,14 @@ class AttachmentHelper implements AttachmentHelperInterface
/**
* Returns the file path relative to upload disk for an attachment,
*
* @param Attachment $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);
}
/**
@@ -136,8 +137,8 @@ class AttachmentHelper implements AttachmentHelperInterface
/**
* Uploads a file as a string.
*
* @param Attachment $attachment
* @param string $content
* @param Attachment $attachment
* @param string $content
*
* @return bool
*/
@@ -185,8 +186,8 @@ class AttachmentHelper implements AttachmentHelperInterface
/**
* Save attachments that get uploaded with models, through the app.
*
* @param object $model
* @param array|null $files
* @param object $model
* @param array|null $files
*
* @return bool
* @throws FireflyException
@@ -218,8 +219,8 @@ class AttachmentHelper implements AttachmentHelperInterface
/**
* Process the upload of a file.
*
* @param UploadedFile $file
* @param Model $model
* @param UploadedFile $file
* @param Model $model
*
* @return Attachment|null
* @throws FireflyException
@@ -265,7 +266,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);
}
@@ -275,8 +276,8 @@ class AttachmentHelper implements AttachmentHelperInterface
/**
* Verify if the file was uploaded correctly.
*
* @param UploadedFile $file
* @param Model $model
* @param UploadedFile $file
* @param Model $model
*
* @return bool
*/
@@ -308,7 +309,7 @@ class AttachmentHelper implements AttachmentHelperInterface
/**
* Verify if the mime of a file is valid.
*
* @param UploadedFile $file
* @param UploadedFile $file
*
* @return bool
*/
@@ -322,7 +323,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);
@@ -337,7 +338,7 @@ class AttachmentHelper implements AttachmentHelperInterface
*
* @codeCoverageIgnore
*
* @param UploadedFile $file
* @param UploadedFile $file
*
* @return bool
*/
@@ -347,7 +348,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);
@@ -360,8 +361,8 @@ class AttachmentHelper implements AttachmentHelperInterface
/**
* Check if a model already has this file attached.
*
* @param UploadedFile $file
* @param Model $model
* @param UploadedFile $file
* @param Model $model
*
* @return bool
*/
@@ -379,7 +380,7 @@ class AttachmentHelper implements AttachmentHelperInterface
}
$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;

View File

@@ -1,4 +1,5 @@
<?php
/**
* AttachmentHelperInterface.php
* Copyright (c) 2019 james@firefly-iii.org
@@ -34,7 +35,7 @@ interface AttachmentHelperInterface
/**
* Get content of an attachment.
*
* @param Attachment $attachment
* @param Attachment $attachment
*
* @return string
*/
@@ -43,7 +44,7 @@ interface AttachmentHelperInterface
/**
* Get the location of an attachment.
*
* @param Attachment $attachment
* @param Attachment $attachment
*
* @return string
*/
@@ -73,8 +74,8 @@ interface AttachmentHelperInterface
/**
* Uploads a file as a string.
*
* @param Attachment $attachment
* @param string $content
* @param Attachment $attachment
* @param string $content
*
* @return bool
*/
@@ -83,8 +84,8 @@ interface AttachmentHelperInterface
/**
* Save attachments that got uploaded.
*
* @param object $model
* @param null|array $files
* @param object $model
* @param null|array $files
*
* @return bool
*/