Use PSR-12 code style

This commit is contained in:
James Cole
2022-10-30 14:24:10 +01:00
parent 1667b88dcd
commit 64ff5eed27
28 changed files with 96 additions and 129 deletions

View File

@@ -43,5 +43,4 @@ enum AccountTypeEnum: string
case MORTGAGE = 'Mortgage';
case RECONCILIATION = 'Reconciliation account';
case REVENUE = 'Revenue account';
}

View File

@@ -29,5 +29,4 @@ enum WebhookResponse: int
case TRANSACTIONS = 200;
case ACCOUNTS = 210;
case NONE = 220;
}

View File

@@ -38,7 +38,9 @@ use Log;
*/
class RequestedReportOnJournals
{
use Dispatchable, InteractsWithSockets, SerializesModels;
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
public Collection $groups;
public int $userId;

View File

@@ -45,5 +45,4 @@ class StoredAccount extends Event
{
$this->account = $account;
}
}

View File

@@ -31,7 +31,6 @@ use Illuminate\Queue\SerializesModels;
* Class TriggeredAuditLog
*/
class TriggeredAuditLog extends Event
{
use SerializesModels;
@@ -52,5 +51,4 @@ class TriggeredAuditLog extends Event
$this->before = $before;
$this->after = $after;
}
}

View File

@@ -22,7 +22,6 @@
declare(strict_types=1);
namespace FireflyIII\Events;
use FireflyIII\Models\Account;
@@ -46,5 +45,4 @@ class UpdatedAccount extends Event
{
$this->account = $account;
}
}

View File

@@ -132,7 +132,6 @@ class GracefulNotFoundHandler extends ExceptionHandler
return parent::render($request, $e);
}
}
/**
@@ -200,7 +199,6 @@ class GracefulNotFoundHandler extends ExceptionHandler
}
return redirect(route('transactions.index', [strtolower($type)]));
}
/**
@@ -232,7 +230,6 @@ class GracefulNotFoundHandler extends ExceptionHandler
if (null !== $journal) {
return redirect(route('transactions.show', [$journal->transaction_group_id]));
}
}
if (Bill::class === $attachment->attachable_type) {
// is linked to bill.
@@ -247,5 +244,4 @@ class GracefulNotFoundHandler extends ExceptionHandler
return parent::render($request, $exception);
}
}

View File

@@ -96,7 +96,7 @@ class Handler extends ExceptionHandler
// somehow Laravel handler does not catch this:
return response()->json(['message' => $e->getMessage(), 'exception' => 'OAuthServerException'], 401);
}
if($e instanceof BadRequestHttpException) {
if ($e instanceof BadRequestHttpException) {
return response()->json(['message' => $e->getMessage(), 'exception' => 'BadRequestHttpException'], 400);
}
@@ -107,7 +107,7 @@ class Handler extends ExceptionHandler
if ($request->expectsJson()) {
$errorCode = 500;
$errorCode = $e instanceof MethodNotAllowedHttpException ? 405: $errorCode;
$errorCode = $e instanceof MethodNotAllowedHttpException ? 405 : $errorCode;
$isDebug = config('app.debug', false);
if ($isDebug) {
@@ -140,7 +140,7 @@ class Handler extends ExceptionHandler
return response()->view('errors.FireflyException', ['exception' => $e, 'debug' => $isDebug], 500);
}
// special view for database errors with extra instructions
if($e instanceof QueryException) {
if ($e instanceof QueryException) {
$isDebug = config('app.debug');
return response()->view('errors.DatabaseException', ['exception' => $e, 'debug' => $isDebug], 500);
@@ -215,9 +215,10 @@ class Handler extends ExceptionHandler
{
return !is_null(
Arr::first(
$this->dontReport, function ($type) use ($e) {
return $e instanceof $type;
}
$this->dontReport,
function ($type) use ($e) {
return $e instanceof $type;
}
)
);
}

View File

@@ -43,7 +43,8 @@ use Log;
*/
class AccountFactory
{
use AccountServiceTrait, LocationServiceTrait;
use AccountServiceTrait;
use LocationServiceTrait;
protected AccountRepositoryInterface $accountRepository;
protected array $validAssetFields;
@@ -279,7 +280,6 @@ class AccountFactory
*/
private function storeMetaData(Account $account, array $data): void
{
$fields = $this->validFields;
if ($account->accountType->type === AccountType::ASSET) {
$fields = $this->validAssetFields;
@@ -292,7 +292,7 @@ class AccountFactory
$type = $account->accountType->type;
$list = config('firefly.valid_currency_account_types');
if (!in_array($type, $list, true)) {
$pos = array_search('currency_id', $fields);
$pos = array_search('currency_id', $fields, true);
if ($pos !== false) {
unset($fields[$pos]);
}
@@ -399,6 +399,4 @@ class AccountFactory
$this->user = $user;
$this->accountRepository->setUser($user);
}
}

View File

@@ -49,7 +49,6 @@ class AccountMetaFactory
$entry = $account->accountMeta()->where('name', $field)->first();
// must not be an empty string:
if ('' !== $value) {
// if $data has field and $entry is null, create new one:
if (null === $entry) {
Log::debug(sprintf('Created meta-field "%s":"%s" for account #%d ("%s") ', $field, $value, $account->id, $account->name));
@@ -84,5 +83,4 @@ class AccountMetaFactory
{
return AccountMeta::create($data);
}
}

View File

@@ -77,7 +77,7 @@ class AttachmentFactory
);
$notes = (string) ($data['notes'] ?? '');
if ('' !== $notes) {
$note = new Note;
$note = new Note();
$note->noteable()->associate($attachment);
$note->text = $notes;
$note->save();
@@ -93,5 +93,4 @@ class AttachmentFactory
{
$this->user = $user;
}
}

View File

@@ -37,7 +37,8 @@ use Log;
*/
class BillFactory
{
use BillServiceTrait, CreatesObjectGroups;
use BillServiceTrait;
use CreatesObjectGroups;
private User $user;
@@ -129,7 +130,6 @@ class BillFactory
}
return $bill;
}
/**
@@ -149,5 +149,4 @@ class BillFactory
{
$this->user = $user;
}
}

View File

@@ -83,5 +83,4 @@ class BudgetFactory
{
$this->user = $user;
}
}

View File

@@ -99,5 +99,4 @@ class CategoryFactory
{
$this->user = $user;
}
}

View File

@@ -64,7 +64,6 @@ class PiggyBankFactory
}
return null;
}
/**
@@ -83,7 +82,5 @@ class PiggyBankFactory
public function setUser(User $user): void
{
$this->user = $user;
}
}

View File

@@ -37,8 +37,8 @@ use Log;
*/
class RecurrenceFactory
{
use TransactionTypeTrait, RecurringTransactionTrait;
use TransactionTypeTrait;
use RecurringTransactionTrait;
private MessageBag $errors;
private User $user;
@@ -50,7 +50,7 @@ class RecurrenceFactory
*/
public function __construct()
{
$this->errors = new MessageBag;
$this->errors = new MessageBag();
}
/**
@@ -120,20 +120,17 @@ class RecurrenceFactory
if (array_key_exists('notes', $data['recurrence'])) {
$this->updateNote($recurrence, (string) $data['recurrence']['notes']);
}
$this->createRepetitions($recurrence, $data['repetitions'] ?? []);
try {
$this->createTransactions($recurrence, $data['transactions'] ?? []);
} catch (FireflyException $e) {
Log::error($e->getMessage());
$recurrence->forceDelete();
$message = sprintf('Could not create recurring transaction: %s', $e->getMessage());
$this->errors->add('store', $message);
throw new FireflyException($message, 0, $e);
}
@@ -155,6 +152,4 @@ class RecurrenceFactory
{
$this->user = $user;
}
}

View File

@@ -95,7 +95,7 @@ class TagFactory
$tag = Tag::create($array);
if (null !== $tag && null !== $latitude && null !== $longitude) {
// create location object.
$location = new Location;
$location = new Location();
$location->latitude = $latitude;
$location->longitude = $longitude;
$location->zoom_level = $zoomLevel;
@@ -113,5 +113,4 @@ class TagFactory
{
$this->user = $user;
}
}

View File

@@ -102,7 +102,6 @@ class TransactionFactory
];
try {
$result = Transaction::create($data);
} catch (QueryException $e) {
Log::error(sprintf('Could not create transaction: %s', $e->getMessage()), $data);
Log::error($e->getMessage());

View File

@@ -78,7 +78,7 @@ class TransactionGroupFactory
throw new FireflyException('Created zero transaction journals.');
}
$group = new TransactionGroup;
$group = new TransactionGroup();
$group->user()->associate($this->user);
$group->title = $title;
$group->save();

View File

@@ -106,12 +106,12 @@ class TransactionJournalFactory
$dataObject = new NullArrayObject($data);
Log::debug('Start of TransactionJournalFactory::create()');
$collection = new Collection;
$collection = new Collection();
$transactions = $dataObject['transactions'] ?? [];
if (empty($transactions)) {
Log::error('There are no transactions in the array, the TransactionJournalFactory cannot continue.');
return new Collection;
return new Collection();
}
try {
/** @var array $row */
@@ -312,10 +312,8 @@ class TransactionJournalFactory
unset($dataRow['import_hash_v2'], $dataRow['original_source']);
$json = json_encode($dataRow, JSON_THROW_ON_ERROR);
if (false === $json) {
$json = json_encode((string) microtime(), JSON_THROW_ON_ERROR);
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow);
}
$hash = hash('sha256', $json);
Log::debug(sprintf('The hash is: %s', $hash), $dataRow);

View File

@@ -87,5 +87,4 @@ class TransactionJournalMetaFactory
return $entry;
}
}

View File

@@ -40,5 +40,4 @@ class TransactionTypeFactory
{
return TransactionType::whereType(ucfirst($type))->first();
}
}

View File

@@ -104,76 +104,75 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
#[ArrayShape(['journals' => "array", 'currency' => "mixed", 'exists' => "bool", 'end' => "string", 'endBalance' => "mixed", 'dayBefore' => "string",
'dayBeforeBalance' => "mixed"])] public function getAuditReport(Account $account, Carbon $date): array
{
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountRepository->setUser($account->user);
{
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountRepository->setUser($account->user);
/** @var JournalRepositoryInterface $journalRepository */
$journalRepository = app(JournalRepositoryInterface::class);
$journalRepository->setUser($account->user);
/** @var JournalRepositoryInterface $journalRepository */
$journalRepository = app(JournalRepositoryInterface::class);
$journalRepository->setUser($account->user);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end)->withAccountInformation()
->withBudgetInformation()->withCategoryInformation()->withBillInformation();
$journals = $collector->getExtractedJournals();
$journals = array_reverse($journals, true);
$dayBeforeBalance = app('steam')->balance($account, $date);
$startBalance = $dayBeforeBalance;
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($account->user);
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end)->withAccountInformation()
->withBudgetInformation()->withCategoryInformation()->withBillInformation();
$journals = $collector->getExtractedJournals();
$journals = array_reverse($journals, true);
$dayBeforeBalance = app('steam')->balance($account, $date);
$startBalance = $dayBeforeBalance;
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($account->user);
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
foreach ($journals as $index => $journal) {
$journals[$index]['balance_before'] = $startBalance;
$transactionAmount = $journal['amount'];
foreach ($journals as $index => $journal) {
$journals[$index]['balance_before'] = $startBalance;
$transactionAmount = $journal['amount'];
// make sure amount is in the right "direction".
if ($account->id === $journal['destination_account_id']) {
$transactionAmount = app('steam')->positive($journal['amount']);
}
// make sure amount is in the right "direction".
if ($account->id === $journal['destination_account_id']) {
$transactionAmount = app('steam')->positive($journal['amount']);
}
if ($currency->id === $journal['foreign_currency_id']) {
$transactionAmount = $journal['foreign_amount'];
if ($account->id === $journal['destination_account_id']) {
$transactionAmount = app('steam')->positive($journal['foreign_amount']);
}
}
if ($currency->id === $journal['foreign_currency_id']) {
$transactionAmount = $journal['foreign_amount'];
if ($account->id === $journal['destination_account_id']) {
$transactionAmount = app('steam')->positive($journal['foreign_amount']);
}
}
$newBalance = bcadd($startBalance, $transactionAmount);
$journals[$index]['balance_after'] = $newBalance;
$startBalance = $newBalance;
$newBalance = bcadd($startBalance, $transactionAmount);
$journals[$index]['balance_after'] = $newBalance;
$startBalance = $newBalance;
// add meta dates for each journal.
$journals[$index]['interest_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'interest_date');
$journals[$index]['book_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'book_date');
$journals[$index]['process_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'process_date');
$journals[$index]['due_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'due_date');
$journals[$index]['payment_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'payment_date');
$journals[$index]['invoice_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'invoice_date');
// add meta dates for each journal.
$journals[$index]['interest_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'interest_date');
$journals[$index]['book_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'book_date');
$journals[$index]['process_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'process_date');
$journals[$index]['due_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'due_date');
$journals[$index]['payment_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'payment_date');
$journals[$index]['invoice_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'invoice_date');
}
$locale = app('steam')->getLocale();
}
$locale = app('steam')->getLocale();
return [
'journals' => $journals,
'currency' => $currency,
'exists' => !empty($journals),
'end' => $this->end->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)),
'endBalance' => app('steam')->balance($account, $this->end),
'dayBefore' => $date->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)),
'dayBeforeBalance' => $dayBeforeBalance,
];
}
return [
'journals' => $journals,
'currency' => $currency,
'exists' => !empty($journals),
'end' => $this->end->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)),
'endBalance' => app('steam')->balance($account, $this->end),
'dayBefore' => $date->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)),
'dayBeforeBalance' => $dayBeforeBalance,
];
}
/**
* Account collection setter.
*
* @param Collection $accounts
*
* @return ReportGeneratorInterface
* @codeCoverageIgnore
*/
* Account collection setter.
*
* @param Collection $accounts
*
* @return ReportGeneratorInterface
* @codeCoverageIgnore
*/
public function setAccounts(Collection $accounts): ReportGeneratorInterface
{
$this->accounts = $accounts;

View File

@@ -58,8 +58,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
#[Pure] public function __construct()
{
$this->income = new Collection;
$this->expenses = new Collection;
$this->income = new Collection();
$this->expenses = new Collection();
}
/**

View File

@@ -56,9 +56,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
#[Pure] public function __construct()
{
$this->expenses = new Collection;
$this->income = new Collection;
$this->tags = new Collection;
$this->expenses = new Collection();
$this->income = new Collection();
$this->tags = new Collection();
}
/**

View File

@@ -31,7 +31,6 @@ use Illuminate\Support\Collection;
*/
interface MessageGeneratorInterface
{
/**
*
*/

View File

@@ -147,7 +147,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$basicMessage['content'] = [];
break;
case WebhookResponse::TRANSACTIONS->value:
$transformer = new TransactionGroupTransformer;
$transformer = new TransactionGroupTransformer();
try {
$basicMessage['content'] = $transformer->transformObject($model);
} catch (FireflyException $e) {
@@ -161,8 +161,8 @@ class StandardMessageGenerator implements MessageGeneratorInterface
case WebhookResponse::ACCOUNTS->value:
$accounts = $this->collectAccounts($model);
foreach ($accounts as $account) {
$transformer = new AccountTransformer;
$transformer->setParameters(new ParameterBag);
$transformer = new AccountTransformer();
$transformer->setParameters(new ParameterBag());
$basicMessage['content'][] = $transformer->transform($account);
}
}
@@ -184,7 +184,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
*/
private function collectAccounts(TransactionGroup $transactionGroup): Collection
{
$accounts = new Collection;
$accounts = new Collection();
/** @var TransactionJournal $journal */
foreach ($transactionGroup->transactionJournals as $journal) {
/** @var Transaction $transaction */
@@ -204,7 +204,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
*/
private function storeMessage(Webhook $webhook, array $message): void
{
$webhookMessage = new WebhookMessage;
$webhookMessage = new WebhookMessage();
$webhookMessage->webhook()->associate($webhook);
$webhookMessage->sent = false;
$webhookMessage->errored = false;
@@ -212,7 +212,6 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$webhookMessage->message = $message;
$webhookMessage->save();
Log::debug(sprintf('Stored new webhook message #%d', $webhookMessage->id));
}
/**

View File

@@ -165,7 +165,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
*/
class User extends Authenticatable
{
use Notifiable, HasApiTokens;
use Notifiable;
use HasApiTokens;
/**
* The attributes that should be cast to native types.
@@ -212,7 +213,7 @@ class User extends Authenticatable
return $user;
}
}
throw new NotFoundHttpException;
throw new NotFoundHttpException();
}
/**
@@ -537,7 +538,7 @@ class User extends Authenticatable
*/
public function userGroup(): BelongsTo
{
return $this->belongsTo(UserGroup::class,);
return $this->belongsTo(UserGroup::class, );
}
/**
@@ -605,5 +606,4 @@ class User extends Authenticatable
}
return app('preferences')->getForUser($this, 'slack_webhook_url', '')->data;
}
}