mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code optimisations.
This commit is contained in:
@@ -37,6 +37,7 @@ use Storage;
|
||||
|
||||
/**
|
||||
* Class AttachmentRepository.
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
{
|
||||
@@ -58,7 +59,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
try {
|
||||
unlink($file);
|
||||
} catch (Exception $e) {
|
||||
Log::error(sprintf('Could not delete file for attachment %d.', $attachment->id));
|
||||
Log::error(sprintf('Could not delete file for attachment %d: %s', $attachment->id, $e->getMessage()));
|
||||
}
|
||||
$attachment->delete();
|
||||
|
||||
@@ -78,21 +79,6 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
return $disk->exists($attachment->fileName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return Attachment
|
||||
*/
|
||||
public function find(int $id): Attachment
|
||||
{
|
||||
$attachment = $this->user->attachments()->find($id);
|
||||
if (null === $attachment) {
|
||||
return new Attachment;
|
||||
}
|
||||
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
@@ -100,6 +86,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
*/
|
||||
public function findWithoutUser(int $id): Attachment
|
||||
{
|
||||
|
||||
$attachment = Attachment::find($id);
|
||||
if (null === $attachment) {
|
||||
return new Attachment;
|
||||
|
@@ -48,13 +48,6 @@ interface AttachmentRepositoryInterface
|
||||
*/
|
||||
public function exists(Attachment $attachment): bool;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return Attachment
|
||||
*/
|
||||
public function find(int $id): Attachment;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
|
Reference in New Issue
Block a user