mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various PSR12 code cleanup
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AttachmentRepository.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -44,7 +45,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
@@ -66,7 +67,32 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(Attachment $attachment): string
|
||||
{
|
||||
// create a disk.
|
||||
$disk = Storage::disk('upload');
|
||||
$file = $attachment->fileName();
|
||||
$unencryptedContent = '';
|
||||
|
||||
if ($disk->exists($file)) {
|
||||
$encryptedContent = (string)$disk->get($file);
|
||||
|
||||
try {
|
||||
$unencryptedContent = Crypt::decrypt($encryptedContent); // verified
|
||||
} catch (DecryptException $e) {
|
||||
$unencryptedContent = $encryptedContent;
|
||||
}
|
||||
}
|
||||
|
||||
return $unencryptedContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -86,35 +112,10 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
return $this->user->attachments()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(Attachment $attachment): string
|
||||
{
|
||||
// create a disk.
|
||||
$disk = Storage::disk('upload');
|
||||
$file = $attachment->fileName();
|
||||
$unencryptedContent = '';
|
||||
|
||||
if ($disk->exists($file)) {
|
||||
$encryptedContent = (string) $disk->get($file);
|
||||
|
||||
try {
|
||||
$unencryptedContent = Crypt::decrypt($encryptedContent); // verified
|
||||
} catch (DecryptException $e) {
|
||||
$unencryptedContent = $encryptedContent;
|
||||
}
|
||||
}
|
||||
|
||||
return $unencryptedContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachment note text or empty string.
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -122,22 +123,14 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
{
|
||||
$note = $attachment->notes()->first();
|
||||
if (null !== $note) {
|
||||
return (string) $note->text;
|
||||
return (string)$note->text;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment
|
||||
* @throws FireflyException
|
||||
@@ -156,8 +149,16 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param array $data
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment
|
||||
* @throws Exception
|
||||
@@ -168,28 +169,28 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
$attachment->title = $data['title'];
|
||||
}
|
||||
|
||||
if (array_key_exists('filename', $data) && '' !== (string) $data['filename'] && $data['filename'] !== $attachment->filename) {
|
||||
if (array_key_exists('filename', $data) && '' !== (string)$data['filename'] && $data['filename'] !== $attachment->filename) {
|
||||
$attachment->filename = $data['filename'];
|
||||
}
|
||||
// update model (move attachment)
|
||||
// should be validated already:
|
||||
if (array_key_exists('attachable_type', $data) && array_key_exists('attachable_id', $data)) {
|
||||
$attachment->attachable_id = (int) $data['attachable_id'];
|
||||
$attachment->attachable_id = (int)$data['attachable_id'];
|
||||
$attachment->attachable_type = sprintf('FireflyIII\\Models\\%s', $data['attachable_type']);
|
||||
}
|
||||
|
||||
$attachment->save();
|
||||
$attachment->refresh();
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->updateNote($attachment, (string) $data['notes']);
|
||||
$this->updateNote($attachment, (string)$data['notes']);
|
||||
}
|
||||
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param string $note
|
||||
* @param Attachment $attachment
|
||||
* @param string $note
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AttachmentRepositoryInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -33,14 +34,14 @@ use Illuminate\Support\Collection;
|
||||
interface AttachmentRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(Attachment $attachment): bool;
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -52,7 +53,7 @@ interface AttachmentRepositoryInterface
|
||||
public function get(): Collection;
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -61,19 +62,19 @@ interface AttachmentRepositoryInterface
|
||||
/**
|
||||
* Get attachment note text or empty string.
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNoteText(Attachment $attachment): ?string;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user);
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment
|
||||
* @throws FireflyException
|
||||
@@ -81,8 +82,8 @@ interface AttachmentRepositoryInterface
|
||||
public function store(array $data): Attachment;
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param array $attachmentData
|
||||
* @param Attachment $attachment
|
||||
* @param array $attachmentData
|
||||
*
|
||||
* @return Attachment
|
||||
*/
|
||||
|
Reference in New Issue
Block a user