Code cleanup

This commit is contained in:
James Cole
2024-12-22 08:43:12 +01:00
parent 5751f7e5a3
commit 565bd87959
574 changed files with 4600 additions and 4604 deletions

View File

@@ -48,14 +48,14 @@ trait AppendsLocationData
private function validLongitude(string $longitude): bool
{
$number = (float)$longitude;
$number = (float) $longitude;
return $number >= -180 && $number <= 180;
}
private function validLatitude(string $latitude): bool
{
$number = (float)$latitude;
$number = (float) $latitude;
return $number >= -90 && $number <= 90;
}

View File

@@ -86,10 +86,10 @@ trait ChecksLogin
$userGroup = $this->route()?->parameter('userGroup');
if (null === $userGroup) {
app('log')->debug('Request class has no userGroup parameter, but perhaps there is a parameter.');
$userGroupId = (int)$this->get('user_group_id');
$userGroupId = (int) $this->get('user_group_id');
if (0 === $userGroupId) {
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;
$userGroupId = (int) $user->user_group_id;
}
$userGroup = UserGroup::find($userGroupId);
if (null === $userGroup) {

View File

@@ -89,19 +89,17 @@ trait ConvertsDataTypes
"\r", // carriage return
];
/**
* Return integer value.
*/
public function convertInteger(string $field): int
public function clearIban(?string $string): ?string
{
return (int)$this->get($field);
$string = $this->clearString($string);
return Steam::filterSpaces($string);
}
/**
* Abstract method that always exists in the Request classes that use this
* trait, OR a stub needs to be added by any other class that uses this train.
*/
abstract public function get(string $key, mixed $default = null): mixed;
public function convertIban(string $field): string
{
return Steam::filterSpaces($this->convertString($field));
}
/**
* Return string value.
@@ -113,12 +111,7 @@ trait ConvertsDataTypes
return $default;
}
return (string)$this->clearString((string)$entry);
}
public function convertIban(string $field): string
{
return Steam::filterSpaces($this->convertString($field));
return (string) $this->clearString((string) $entry);
}
public function clearString(?string $string): ?string
@@ -138,13 +131,6 @@ trait ConvertsDataTypes
return trim($string);
}
public function clearIban(?string $string): ?string
{
$string = $this->clearString($string);
return Steam::filterSpaces($string);
}
public function clearStringKeepNewlines(?string $string): ?string
{
if (null === $string) {
@@ -158,9 +144,23 @@ trait ConvertsDataTypes
// clear zalgo text (TODO also in API v2)
$string = preg_replace('/(\pM{2})\pM+/u', '\1', $string);
return trim((string)$string);
return trim((string) $string);
}
/**
* Return integer value.
*/
public function convertInteger(string $field): int
{
return (int) $this->get($field);
}
/**
* Abstract method that always exists in the Request classes that use this
* trait, OR a stub needs to be added by any other class that uses this train.
*/
abstract public function get(string $key, mixed $default = null): mixed;
/**
* TODO duplicate, see SelectTransactionsRequest
*
@@ -183,7 +183,7 @@ trait ConvertsDataTypes
$collection = new Collection();
if (is_array($set)) {
foreach ($set as $accountId) {
$account = $repository->find((int)$accountId);
$account = $repository->find((int) $accountId);
if (null !== $account) {
$collection->push($account);
}
@@ -198,7 +198,7 @@ trait ConvertsDataTypes
*/
public function stringWithNewlines(string $field): string
{
return (string)$this->clearStringKeepNewlines((string)($this->get($field) ?? ''));
return (string) $this->clearStringKeepNewlines((string) ($this->get($field) ?? ''));
}
/**
@@ -242,7 +242,7 @@ trait ConvertsDataTypes
protected function convertDateTime(?string $string): ?Carbon
{
$value = $this->get((string)$string);
$value = $this->get((string) $string);
if (null === $value) {
return null;
}
@@ -297,7 +297,7 @@ trait ConvertsDataTypes
return null;
}
return (float)$res;
return (float) $res;
}
protected function dateFromValue(?string $string): ?Carbon
@@ -360,7 +360,7 @@ trait ConvertsDataTypes
$result = null;
try {
$result = '' !== (string)$this->get($field) ? new Carbon((string)$this->get($field), config('app.timezone')) : null;
$result = '' !== (string) $this->get($field) ? new Carbon((string) $this->get($field), config('app.timezone')) : null;
} catch (InvalidFormatException $e) {
// @ignoreException
}
@@ -383,7 +383,7 @@ trait ConvertsDataTypes
return null;
}
return (int)$string;
return (int) $string;
}
/**
@@ -395,11 +395,11 @@ trait ConvertsDataTypes
return null;
}
$value = (string)$this->get($field);
$value = (string) $this->get($field);
if ('' === $value) {
return null;
}
return (int)$value;
return (int) $value;
}
}

View File

@@ -38,12 +38,12 @@ trait GetRecurrenceData
foreach ($stringKeys as $key) {
if (array_key_exists($key, $transaction)) {
$return[$key] = (string)$transaction[$key];
$return[$key] = (string) $transaction[$key];
}
}
foreach ($intKeys as $key) {
if (array_key_exists($key, $transaction)) {
$return[$key] = (int)$transaction[$key];
$return[$key] = (int) $transaction[$key];
}
}
foreach ($keys as $key) {