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 MORTGAGE = 'Mortgage';
case RECONCILIATION = 'Reconciliation account'; case RECONCILIATION = 'Reconciliation account';
case REVENUE = 'Revenue account'; case REVENUE = 'Revenue account';
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -215,7 +215,8 @@ class Handler extends ExceptionHandler
{ {
return !is_null( return !is_null(
Arr::first( Arr::first(
$this->dontReport, function ($type) use ($e) { $this->dontReport,
function ($type) use ($e) {
return $e instanceof $type; return $e instanceof $type;
} }
) )

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -151,7 +151,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
$journals[$index]['due_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'due_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]['payment_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'payment_date');
$journals[$index]['invoice_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'invoice_date'); $journals[$index]['invoice_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'invoice_date');
} }
$locale = app('steam')->getLocale(); $locale = app('steam')->getLocale();

View File

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

View File

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

View File

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

View File

@@ -147,7 +147,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$basicMessage['content'] = []; $basicMessage['content'] = [];
break; break;
case WebhookResponse::TRANSACTIONS->value: case WebhookResponse::TRANSACTIONS->value:
$transformer = new TransactionGroupTransformer; $transformer = new TransactionGroupTransformer();
try { try {
$basicMessage['content'] = $transformer->transformObject($model); $basicMessage['content'] = $transformer->transformObject($model);
} catch (FireflyException $e) { } catch (FireflyException $e) {
@@ -161,8 +161,8 @@ class StandardMessageGenerator implements MessageGeneratorInterface
case WebhookResponse::ACCOUNTS->value: case WebhookResponse::ACCOUNTS->value:
$accounts = $this->collectAccounts($model); $accounts = $this->collectAccounts($model);
foreach ($accounts as $account) { foreach ($accounts as $account) {
$transformer = new AccountTransformer; $transformer = new AccountTransformer();
$transformer->setParameters(new ParameterBag); $transformer->setParameters(new ParameterBag());
$basicMessage['content'][] = $transformer->transform($account); $basicMessage['content'][] = $transformer->transform($account);
} }
} }
@@ -184,7 +184,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
*/ */
private function collectAccounts(TransactionGroup $transactionGroup): Collection private function collectAccounts(TransactionGroup $transactionGroup): Collection
{ {
$accounts = new Collection; $accounts = new Collection();
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($transactionGroup->transactionJournals as $journal) { foreach ($transactionGroup->transactionJournals as $journal) {
/** @var Transaction $transaction */ /** @var Transaction $transaction */
@@ -204,7 +204,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
*/ */
private function storeMessage(Webhook $webhook, array $message): void private function storeMessage(Webhook $webhook, array $message): void
{ {
$webhookMessage = new WebhookMessage; $webhookMessage = new WebhookMessage();
$webhookMessage->webhook()->associate($webhook); $webhookMessage->webhook()->associate($webhook);
$webhookMessage->sent = false; $webhookMessage->sent = false;
$webhookMessage->errored = false; $webhookMessage->errored = false;
@@ -212,7 +212,6 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$webhookMessage->message = $message; $webhookMessage->message = $message;
$webhookMessage->save(); $webhookMessage->save();
Log::debug(sprintf('Stored new webhook message #%d', $webhookMessage->id)); 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 class User extends Authenticatable
{ {
use Notifiable, HasApiTokens; use Notifiable;
use HasApiTokens;
/** /**
* The attributes that should be cast to native types. * The attributes that should be cast to native types.
@@ -212,7 +213,7 @@ class User extends Authenticatable
return $user; return $user;
} }
} }
throw new NotFoundHttpException; throw new NotFoundHttpException();
} }
/** /**
@@ -605,5 +606,4 @@ class User extends Authenticatable
} }
return app('preferences')->getForUser($this, 'slack_webhook_url', '')->data; return app('preferences')->getForUser($this, 'slack_webhook_url', '')->data;
} }
} }