From ebf4b0028886996079cd7f4d154558df4169df63 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 21 Dec 2023 05:15:46 +0100 Subject: [PATCH] Fix various code. --- .../Authentication/RemoteUserGuard.php | 2 +- .../Authentication/RemoteUserProvider.php | 23 +++++- app/Support/ParseDateString.php | 5 -- app/Support/Steam.php | 4 - app/Validation/FireflyValidator.php | 76 +++++++++++-------- routes/breadcrumbs.php | 2 + 6 files changed, 66 insertions(+), 46 deletions(-) diff --git a/app/Support/Authentication/RemoteUserGuard.php b/app/Support/Authentication/RemoteUserGuard.php index 3c45154ebc..51937d0c2d 100644 --- a/app/Support/Authentication/RemoteUserGuard.php +++ b/app/Support/Authentication/RemoteUserGuard.php @@ -162,7 +162,7 @@ class RemoteUserGuard implements Guard app('log')->error(sprintf('Did not set user at %s', __METHOD__)); } - public function validate(array $credentials = []): void + public function validate(array $credentials = []): bool { app('log')->debug(sprintf('Now at %s', __METHOD__)); diff --git a/app/Support/Authentication/RemoteUserProvider.php b/app/Support/Authentication/RemoteUserProvider.php index 5d3d0cd487..7c0f62bd4e 100644 --- a/app/Support/Authentication/RemoteUserProvider.php +++ b/app/Support/Authentication/RemoteUserProvider.php @@ -36,13 +36,21 @@ use Illuminate\Contracts\Auth\UserProvider; */ class RemoteUserProvider implements UserProvider { - public function retrieveByCredentials(array $credentials): void + /** + * @throws FireflyException + */ + public function retrieveByCredentials(array $credentials): null|Authenticatable { app('log')->debug(sprintf('Now at %s', __METHOD__)); throw new FireflyException(sprintf('Did not implement %s', __METHOD__)); } + /** + * @param mixed $identifier + * + * @throws FireflyException + */ public function retrieveById($identifier): User { app('log')->debug(sprintf('Now at %s(%s)', __METHOD__, $identifier)); @@ -70,7 +78,13 @@ class RemoteUserProvider implements UserProvider return $user; } - public function retrieveByToken($identifier, $token): void + /** + * @param mixed $identifier + * @param mixed $token + * + * @throws FireflyException + */ + public function retrieveByToken($identifier, $token): null|Authenticatable { app('log')->debug(sprintf('Now at %s', __METHOD__)); @@ -84,7 +98,10 @@ class RemoteUserProvider implements UserProvider throw new FireflyException(sprintf('B) Did not implement %s', __METHOD__)); } - public function validateCredentials(Authenticatable $user, array $credentials): void + /** + * @throws FireflyException + */ + public function validateCredentials(Authenticatable $user, array $credentials): bool { app('log')->debug(sprintf('Now at %s', __METHOD__)); diff --git a/app/Support/ParseDateString.php b/app/Support/ParseDateString.php index 0df4de8c8c..ba89a562ab 100644 --- a/app/Support/ParseDateString.php +++ b/app/Support/ParseDateString.php @@ -249,14 +249,9 @@ class ParseDateString /** * Returns true if this matches regex for xxxx-xx-DD: - * - * @param string $date - * - * @return bool */ protected function isDayRange(string $date): bool { - $pattern = '/^xxxx-xx-(0[1-9]|[12]\d|3[01])$/'; $result = preg_match($pattern, $date); if (false !== $result && 0 !== $result) { diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 08c2065e83..57f3dbd7db 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -697,10 +697,6 @@ class Steam /** * Get user's locale. - * - * @throws FireflyException - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface */ public function getLocale(): string // get preference { diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index 5bdbebae50..dbefd8a128 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -212,7 +212,7 @@ class FireflyValidator extends Validator // take $first = substr($value, 0, 4); $last = substr($value, 4); - $iban = $last . $first; + $iban = $last.$first; $iban = trim(str_replace($search, $replace, $iban)); if ('' === $iban) { return false; @@ -507,10 +507,11 @@ class FireflyValidator extends Validator } $query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') - ->whereNull('accounts.deleted_at') - ->where('accounts.user_id', auth()->user()->id) - ->where('account_meta.name', 'account_number') - ->where('account_meta.data', json_encode($value)); + ->whereNull('accounts.deleted_at') + ->where('accounts.user_id', auth()->user()->id) + ->where('account_meta.name', 'account_number') + ->where('account_meta.data', json_encode($value)) + ; if ($accountId > 0) { // exclude current account from check. @@ -552,7 +553,7 @@ class FireflyValidator extends Validator /** * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function validateUniqueCurrencyCode(null | string $attribute, null | string $value): bool + public function validateUniqueCurrencyCode(null|string $attribute, null|string $value): bool { return $this->validateUniqueCurrency('code', (string) $attribute, (string) $value); } @@ -565,12 +566,12 @@ class FireflyValidator extends Validator return 0 === \DB::table('transaction_currencies')->where($field, $value)->whereNull('deleted_at')->count(); } - public function validateUniqueCurrencyName(null | string $attribute, null | string $value): bool + public function validateUniqueCurrencyName(null|string $attribute, null|string $value): bool { return $this->validateUniqueCurrency('name', (string) $attribute, (string) $value); } - public function validateUniqueCurrencySymbol(null | string $attribute, null | string $value): bool + public function validateUniqueCurrencySymbol(null|string $attribute, null|string $value): bool { return $this->validateUniqueCurrency('symbol', (string) $attribute, (string) $value); } @@ -613,11 +614,12 @@ class FireflyValidator extends Validator $userId = auth()->user()->id; return 0 === Webhook::whereUserId($userId) - ->where('trigger', $trigger) - ->where('response', $response) - ->where('delivery', $delivery) - ->where('id', '!=', $existingId) - ->where('url', $url)->count(); + ->where('trigger', $trigger) + ->where('response', $response) + ->where('delivery', $delivery) + ->where('id', '!=', $existingId) + ->where('url', $url)->count() + ; } return false; @@ -651,9 +653,10 @@ class FireflyValidator extends Validator } // get entries from table $result = \DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at') - ->where('id', '!=', $exclude) - ->where($field, $value) - ->first([$field]); + ->where('id', '!=', $exclude) + ->where($field, $value) + ->first([$field]) + ; if (null === $result) { return true; // not found, so true. } @@ -673,9 +676,10 @@ class FireflyValidator extends Validator { $exclude = $parameters[0] ?? null; $query = \DB::table('object_groups') - ->whereNull('object_groups.deleted_at') - ->where('object_groups.user_id', auth()->user()->id) - ->where('object_groups.title', $value); + ->whereNull('object_groups.deleted_at') + ->where('object_groups.user_id', auth()->user()->id) + ->where('object_groups.title', $value) + ; if (null !== $exclude) { $query->where('object_groups.id', '!=', (int) $exclude); } @@ -694,7 +698,8 @@ class FireflyValidator extends Validator { $exclude = $parameters[0] ?? null; $query = \DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at') - ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id); + ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id) + ; if (null !== $exclude) { $query->where('piggy_banks.id', '!=', (int) $exclude); } @@ -724,10 +729,11 @@ class FireflyValidator extends Validator $userId = auth()->user()->id; return 0 === Webhook::whereUserId($userId) - ->where('trigger', $trigger) - ->where('response', $response) - ->where('delivery', $delivery) - ->where('url', $url)->count(); + ->where('trigger', $trigger) + ->where('response', $response) + ->where('delivery', $delivery) + ->where('url', $url)->count() + ; } return false; @@ -753,7 +759,7 @@ class FireflyValidator extends Validator private function validateByAccountTypeString(string $value, array $parameters, string $type): bool { /** @var null|array $search */ - $search = \Config::get('firefly.accountTypeByIdentifier.' . $type); + $search = \Config::get('firefly.accountTypeByIdentifier.'.$type); if (null === $search) { return false; @@ -765,8 +771,9 @@ class FireflyValidator extends Validator /** @var null|Account $result */ $result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore) - ->where('name', $value) - ->first(); + ->where('name', $value) + ->first() + ; return null === $result; } @@ -782,8 +789,9 @@ class FireflyValidator extends Validator /** @var null|Account $result */ $result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore) - ->where('name', $value) - ->first(); + ->where('name', $value) + ->first() + ; return null === $result; } @@ -800,8 +808,9 @@ class FireflyValidator extends Validator $ignore = $existingAccount->id; $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore) - ->where('name', $value) - ->first(); + ->where('name', $value) + ->first() + ; return null === $entry; } @@ -818,8 +827,9 @@ class FireflyValidator extends Validator $ignore = $existingAccount->id; $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore) - ->where('name', $value) - ->first(); + ->where('name', $value) + ->first() + ; return null === $entry; } diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php index 2b17956637..03c26ff955 100644 --- a/routes/breadcrumbs.php +++ b/routes/breadcrumbs.php @@ -291,6 +291,7 @@ Breadcrumbs::for( Breadcrumbs::for( 'attachments.edit', static function (Generator $breadcrumbs, Attachment $attachment): void { + /** @var Account|Bill|TransactionJournal $object */ $object = $attachment->attachable; if ($object instanceof TransactionJournal) { $group = $object->transactionGroup; @@ -311,6 +312,7 @@ Breadcrumbs::for( Breadcrumbs::for( 'attachments.delete', static function (Generator $breadcrumbs, Attachment $attachment): void { + /** @var Account|Bill|TransactionJournal $object */ $object = $attachment->attachable; if ($object instanceof TransactionJournal) { $breadcrumbs->parent('transactions.show', $object->transactionGroup);