Fix various code.

This commit is contained in:
James Cole 2023-12-21 05:15:46 +01:00
parent a445bc53cd
commit ebf4b00288
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
6 changed files with 66 additions and 46 deletions

View File

@ -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__));

View File

@ -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__));

View File

@ -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) {

View File

@ -697,10 +697,6 @@ class Steam
/**
* Get user's locale.
*
* @throws FireflyException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getLocale(): string // get preference
{

View File

@ -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;
}

View File

@ -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);