Clean up balance methods.

This commit is contained in:
James Cole
2024-12-22 20:32:58 +01:00
parent a0e92b6969
commit d90ac519f7
93 changed files with 1233 additions and 1853 deletions

View File

@@ -82,12 +82,12 @@ trait AppendsLocationData
$data['latitude'] = null;
$data['zoom_level'] = null;
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
$isValidPOST = $this->isValidPost($prefix);
$isValidPUT = $this->isValidPUT($prefix);
$isValidEmptyPUT = $this->isValidEmptyPUT($prefix);
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
$isValidPOST = $this->isValidPost($prefix);
$isValidPUT = $this->isValidPUT($prefix);
$isValidEmptyPUT = $this->isValidEmptyPUT($prefix);
// for a POST (store), all fields must be present and not NULL.
if ($isValidPOST) {
@@ -245,9 +245,9 @@ trait AppendsLocationData
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
return (
null === $this->get($longitudeKey)
&& null === $this->get($latitudeKey)
&& null === $this->get($zoomLevelKey))
null === $this->get($longitudeKey)
&& null === $this->get($latitudeKey)
&& null === $this->get($zoomLevelKey))
&& (
'PUT' === $this->method()
|| ('POST' === $this->method() && $this->routeIs('*.update'))

View File

@@ -40,7 +40,7 @@ trait ChecksLogin
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
// Only allow logged-in users
$check = auth()->check();
$check = auth()->check();
if (!$check) {
return false;
}
@@ -79,7 +79,7 @@ trait ChecksLogin
public function getUserGroup(): ?UserGroup
{
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
app('log')->debug('Now in getUserGroup()');
/** @var null|UserGroup $userGroup */
@@ -91,7 +91,7 @@ trait ChecksLogin
app('log')->debug(sprintf('Request class has no user_group_id parameter, grab default from user (group #%d).', $user->user_group_id));
$userGroupId = (int) $user->user_group_id;
}
$userGroup = UserGroup::find($userGroupId);
$userGroup = UserGroup::find($userGroupId);
if (null === $userGroup) {
app('log')->error(sprintf('Request class has user_group_id (#%d), but group does not exist.', $userGroupId));

View File

@@ -27,4 +27,6 @@ namespace FireflyIII\Support\Request;
/**
* Trait ConvertAPIDataTypes
*/
trait ConvertAPIDataTypes {}
trait ConvertAPIDataTypes
{
}

View File

@@ -96,24 +96,6 @@ trait ConvertsDataTypes
return Steam::filterSpaces($string);
}
public function convertIban(string $field): string
{
return Steam::filterSpaces($this->convertString($field));
}
/**
* Return string value.
*/
public function convertString(string $field, string $default = ''): string
{
$entry = $this->get($field);
if (!is_scalar($entry)) {
return $default;
}
return (string) $this->clearString((string) $entry);
}
public function clearString(?string $string): ?string
{
$string = $this->clearStringKeepNewlines($string);
@@ -147,12 +129,22 @@ trait ConvertsDataTypes
return trim((string) $string);
}
/**
* Return integer value.
*/
public function convertInteger(string $field): int
public function convertIban(string $field): string
{
return (int) $this->get($field);
return Steam::filterSpaces($this->convertString($field));
}
/**
* Return string value.
*/
public function convertString(string $field, string $default = ''): string
{
$entry = $this->get($field);
if (!is_scalar($entry)) {
return $default;
}
return (string) $this->clearString((string) $entry);
}
/**
@@ -161,6 +153,14 @@ trait ConvertsDataTypes
*/
abstract public function get(string $key, mixed $default = null): mixed;
/**
* Return integer value.
*/
public function convertInteger(string $field): int
{
return (int) $this->get($field);
}
/**
* TODO duplicate, see SelectTransactionsRequest
*

View File

@@ -38,13 +38,13 @@ trait GetFilterInstructions
return [];
}
foreach ($set as $info) {
$column = $info['column'] ?? 'NOPE';
$filterValue = (string) ($info['filter'] ?? self::INVALID_FILTER);
$column = $info['column'] ?? 'NOPE';
$filterValue = (string) ($info['filter'] ?? self::INVALID_FILTER);
if (false === in_array($column, $allowed, true)) {
// skip invalid column
continue;
}
$filterType = $config[$column] ?? false;
$filterType = $config[$column] ?? false;
switch ($filterType) {
default:

View File

@@ -35,8 +35,8 @@ trait GetSortInstructions
return [];
}
foreach ($set as $info) {
$column = $info['column'] ?? 'NOPE';
$direction = $info['direction'] ?? 'NOPE';
$column = $info['column'] ?? 'NOPE';
$direction = $info['direction'] ?? 'NOPE';
if ('asc' !== $direction && 'desc' !== $direction) {
// skip invalid direction
continue;