mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 16:13:54 +00:00
Code cleanup that (hopefully) matches style CI
This commit is contained in:
@@ -26,7 +26,9 @@ use Crypt;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Contracts\Encryption\EncryptException;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -50,18 +52,19 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
/** @var int Max upload size. */
|
||||
protected $maxUploadSize = 0;
|
||||
|
||||
/** @var \Illuminate\Contracts\Filesystem\Filesystem The disk where attachments are stored. */
|
||||
/** @var Filesystem The disk where attachments are stored. */
|
||||
protected $uploadDisk;
|
||||
|
||||
|
||||
/**
|
||||
* AttachmentHelper constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
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;
|
||||
@@ -104,16 +107,18 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
* Returns the file path relative to upload disk for an 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all attachments.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -198,8 +203,8 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
* @param object $model
|
||||
* @param array|null $files
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
* @return bool
|
||||
*/
|
||||
public function saveAttachmentsForModel(object $model, ?array $files): bool
|
||||
{
|
||||
@@ -242,7 +247,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$count = $model->user->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
|
||||
$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;
|
||||
@@ -257,9 +262,9 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
* @param UploadedFile $file
|
||||
* @param Model $model
|
||||
*
|
||||
* @return Attachment|null
|
||||
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
||||
* @throws EncryptException
|
||||
* @throws FireflyException
|
||||
* @return Attachment|null
|
||||
*/
|
||||
protected function processFile(UploadedFile $file, Model $model): ?Attachment
|
||||
{
|
||||
@@ -286,7 +291,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
throw new FireflyException('Cannot upload empty or non-existent file.'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$content = $fileObject->fread($file->getSize());
|
||||
$content = $fileObject->fread($file->getSize());
|
||||
Log::debug(sprintf('Full file length is %d and upload size is %d.', strlen($content), $file->getSize()));
|
||||
|
||||
// store it:
|
||||
@@ -296,7 +301,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);
|
||||
}
|
||||
|
||||
@@ -320,7 +325,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);
|
||||
|
||||
@@ -345,7 +350,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);
|
||||
|
||||
|
@@ -57,13 +57,6 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function amountLess(string $amount): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Add basic info on attachments of transactions.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withAttachmentInformation(): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Get transactions where the amount is more than.
|
||||
*
|
||||
@@ -128,15 +121,6 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Either account can be set, but NOT both. This effectively excludes internal transfers.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setXorAccounts(Collection $accounts): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Collect transactions after a specific date.
|
||||
*
|
||||
@@ -146,24 +130,6 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setAfter(Carbon $date): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Collect transactions created on a specific date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setCreatedAt(Carbon $date): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Collect transactions updated on a specific date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setUpdatedAt(Carbon $date): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Collect transactions before a specific date.
|
||||
*
|
||||
@@ -236,6 +202,14 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setCategory(Category $category): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Collect transactions created on a specific date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setCreatedAt(Carbon $date): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Limit results to a specific currency, either foreign or normal one.
|
||||
@@ -355,6 +329,15 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setTypes(array $types): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Collect transactions updated on a specific date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setUpdatedAt(Carbon $date): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Set the user object and start the query.
|
||||
*
|
||||
@@ -364,6 +347,15 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setUser(User $user): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Either account can be set, but NOT both. This effectively excludes internal transfers.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setXorAccounts(Collection $accounts): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Automatically include all stuff required to make API calls work.
|
||||
*
|
||||
@@ -378,6 +370,13 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function withAccountInformation(): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Add basic info on attachments of transactions.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withAttachmentInformation(): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Include bill name + ID.
|
||||
*
|
||||
|
@@ -79,7 +79,7 @@ class FiscalHelper implements FiscalHelperInterface
|
||||
if (true === $this->useCustomFiscalYear) {
|
||||
$prefStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
|
||||
[$mth, $day] = explode('-', $prefStartStr);
|
||||
$startDate->day((int)$day)->month((int)$mth);
|
||||
$startDate->day((int) $day)->month((int) $mth);
|
||||
|
||||
// if start date is after passed date, sub 1 year.
|
||||
if ($startDate > $date) {
|
||||
|
@@ -99,7 +99,7 @@ class NetWorth implements NetWorthInterface
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name));
|
||||
$currencyId = (int)$this->accountRepository->getMetaValue($account, 'currency_id');
|
||||
$currencyId = (int) $this->accountRepository->getMetaValue($account, 'currency_id');
|
||||
$currencyId = 0 === $currencyId ? $default->id : $currencyId;
|
||||
|
||||
Log::debug(sprintf('Currency ID is #%d', $currencyId));
|
||||
@@ -111,9 +111,9 @@ class NetWorth implements NetWorthInterface
|
||||
|
||||
// if the account is a credit card, subtract the virtual balance from the balance,
|
||||
// to better reflect that this is not money that is actually "yours".
|
||||
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
|
||||
$virtualBalance = (string)$account->virtual_balance;
|
||||
if ('ccAsset' === $role && '' !== $virtualBalance && (float)$virtualBalance > 0) {
|
||||
$role = (string) $this->accountRepository->getMetaValue($account, 'account_role');
|
||||
$virtualBalance = (string) $account->virtual_balance;
|
||||
if ('ccAsset' === $role && '' !== $virtualBalance && (float) $virtualBalance > 0) {
|
||||
$balance = bcsub($balance, $virtualBalance);
|
||||
}
|
||||
|
||||
|
@@ -87,7 +87,7 @@ class PopupReport implements PopupReportInterface
|
||||
if (null !== $currencyId) {
|
||||
/** @var CurrencyRepositoryInterface $repos */
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = $repos->find((int)$currencyId);
|
||||
$currency = $repos->find((int) $currencyId);
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ class PopupReport implements PopupReportInterface
|
||||
if (null !== $currencyId) {
|
||||
/** @var CurrencyRepositoryInterface $repos */
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = $repos->find((int)$currencyId);
|
||||
$currency = $repos->find((int) $currencyId);
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ class PopupReport implements PopupReportInterface
|
||||
* Collect journals by a category.
|
||||
*
|
||||
* @param Category|null $category
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -166,7 +166,7 @@ class PopupReport implements PopupReportInterface
|
||||
if (null !== $currencyId) {
|
||||
/** @var CurrencyRepositoryInterface $repos */
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = $repos->find((int)$currencyId);
|
||||
$currency = $repos->find((int) $currencyId);
|
||||
}
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
@@ -179,10 +179,10 @@ class PopupReport implements PopupReportInterface
|
||||
->withCategoryInformation()
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])->withAccountInformation();
|
||||
|
||||
if(null!== $category) {
|
||||
if (null !== $category) {
|
||||
$collector->setCategory($category);
|
||||
}
|
||||
if(null === $category) {
|
||||
if (null === $category) {
|
||||
$collector->withoutCategory();
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ class PopupReport implements PopupReportInterface
|
||||
if (null !== $currencyId) {
|
||||
/** @var CurrencyRepositoryInterface $repos */
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = $repos->find((int)$currencyId);
|
||||
$currency = $repos->find((int) $currencyId);
|
||||
}
|
||||
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
|
@@ -25,7 +25,6 @@ namespace FireflyIII\Helpers\Report;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Category;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface PopupReportInterface.
|
||||
@@ -68,7 +67,7 @@ interface PopupReportInterface
|
||||
* Group by category.
|
||||
*
|
||||
* @param Category|null $category
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -43,6 +43,7 @@ class ReportHelper implements ReportHelperInterface
|
||||
|
||||
/**
|
||||
* ReportHelper constructor.
|
||||
*
|
||||
* @param BudgetRepositoryInterface $budgetRepository
|
||||
*/
|
||||
public function __construct(BudgetRepositoryInterface $budgetRepository)
|
||||
@@ -62,8 +63,8 @@ class ReportHelper implements ReportHelperInterface
|
||||
*
|
||||
* Excludes bills which have not had a payment on the mentioned accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
|
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collection\Bill as BillCollection;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user