Code optimisations.

This commit is contained in:
James Cole
2018-07-22 18:50:27 +02:00
parent ea2c48bca5
commit ca096852a5
56 changed files with 221 additions and 427 deletions

View File

@@ -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;

View File

@@ -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
*