mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-20 16:40:10 +00:00
Code cleanup.
This commit is contained in:
@@ -23,8 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Attachment;
|
||||
|
||||
use Crypt;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\AttachmentFactory;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
@@ -36,11 +34,9 @@ use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use League\Flysystem\UnableToDeleteFile;
|
||||
use LogicException;
|
||||
|
||||
/**
|
||||
* Class AttachmentRepository.
|
||||
*
|
||||
*/
|
||||
class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
{
|
||||
@@ -48,10 +44,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(Attachment $attachment): bool
|
||||
{
|
||||
@@ -59,6 +52,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
$helper = app(AttachmentHelperInterface::class);
|
||||
|
||||
$path = $helper->getAttachmentLocation($attachment);
|
||||
|
||||
try {
|
||||
Storage::disk('upload')->delete($path);
|
||||
} catch (UnableToDeleteFile $e) {
|
||||
@@ -69,11 +63,6 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(Attachment $attachment): string
|
||||
{
|
||||
// create a disk.
|
||||
@@ -83,8 +72,9 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
|
||||
if ($disk->exists($file)) {
|
||||
$encryptedContent = (string)$disk->get($file);
|
||||
|
||||
try {
|
||||
$unencryptedContent = Crypt::decrypt($encryptedContent); // verified
|
||||
$unencryptedContent = \Crypt::decrypt($encryptedContent); // verified
|
||||
} catch (DecryptException $e) {
|
||||
app('log')->debug(sprintf('Could not decrypt attachment #%d but this is fine: %s', $attachment->id, $e->getMessage()));
|
||||
$unencryptedContent = $encryptedContent;
|
||||
@@ -94,11 +84,6 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
return $unencryptedContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function exists(Attachment $attachment): bool
|
||||
{
|
||||
/** @var Storage $disk */
|
||||
@@ -107,9 +92,6 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
return $disk->exists($attachment->fileName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->attachments()->get();
|
||||
@@ -117,10 +99,6 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
|
||||
/**
|
||||
* Get attachment note text or empty string.
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNoteText(Attachment $attachment): ?string
|
||||
{
|
||||
@@ -133,9 +111,6 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(array $data): Attachment
|
||||
@@ -151,22 +126,13 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
public function setUser(null|Authenticatable|User $user): void
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment
|
||||
*/
|
||||
public function update(Attachment $attachment, array $data): Attachment
|
||||
{
|
||||
if (array_key_exists('title', $data)) {
|
||||
@@ -192,12 +158,6 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param string $note
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateNote(Attachment $attachment, string $note): bool
|
||||
{
|
||||
if ('' === $note) {
|
||||
@@ -205,7 +165,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
if (null !== $dbNote) {
|
||||
try {
|
||||
$dbNote->delete();
|
||||
} catch (LogicException $e) {
|
||||
} catch (\LogicException $e) {
|
||||
app('log')->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user