Update various things. I know, great description.

This commit is contained in:
James Cole
2023-11-30 17:28:44 +01:00
parent 627db2c2df
commit 271e4271eb
100 changed files with 488 additions and 409 deletions

View File

@@ -39,9 +39,9 @@ use Psr\Container\NotFoundExceptionInterface;
*/
class RemoteUserGuard implements Guard
{
protected Application $application;
protected Application $application;
protected UserProvider $provider;
protected User|null $user;
protected User | null $user;
/**
* Create a new authentication guard.
@@ -156,8 +156,9 @@ class RemoteUserGuard implements Guard
/**
* @inheritDoc
* @SuppressWarnings(PHPMD.ShortMethodName)
*/
public function id(): int|string|null
public function id(): int | string | null
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
return $this->user?->id;

View File

@@ -45,6 +45,7 @@ class DynamicConfigKey
*
* @return string
* @throws NotFoundHttpException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public static function routeBinder(string $value, Route $route): string
{

View File

@@ -62,6 +62,8 @@ class EitherConfigKey
*
* @return string
* @throws NotFoundHttpException
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public static function routeBinder(string $value, Route $route): string
{

View File

@@ -935,7 +935,7 @@ class ExportDataGenerator
$journal['budget_name'],
$journal['bill_name'],
$this->mergeTags($journal['tags']),
$this->clearString($journal['notes'], true),
$this->clearStringKeepNewlines($journal['notes']),
// export also the optional fields (ALL)

View File

@@ -32,7 +32,7 @@ trait ReturnsIntegerIdTrait
{
/**
* Get the ID
*
* @SuppressWarnings(PHPMD.ShortMethodName)
* @return Attribute
*/
protected function id(): Attribute

View File

@@ -178,6 +178,7 @@ trait AppendsLocationData
* @param bool $default
*
* @return mixed
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
abstract public function boolean($key = null, $default = false);

View File

@@ -60,7 +60,8 @@ trait ChecksLogin
/** @var UserRoleEnum $role */
foreach ($this->acceptedRoles as $role) {
// system owner cannot overrule this, MUST be member of the group.
if ($user->hasRoleInGroup($userGroup, $role, true, false)) {
$access = $user->hasRoleInGroupOrOwner($userGroup, $role);
if ($access) {
return true;
}
}

View File

@@ -34,60 +34,8 @@ use Illuminate\Support\Collection;
*/
trait ConvertsDataTypes
{
/**
* Return integer value.
*
* @param string $field
*
* @return int
*/
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.
*
* @param string $key
* @param mixed|null $default
*
* @return mixed
*/
abstract public function get(string $key, mixed $default = null): mixed;
/**
* Return string value.
*
* @param string $field
*
* @return string
*/
public function convertString(string $field): string
{
$entry = $this->get($field);
if (!is_scalar($entry)) {
return '';
}
return (string) $this->clearString((string)$entry, false);
}
/**
* @param string|null $string
* @param bool $keepNewlines
*
* @return string|null
*/
public function clearString(?string $string, bool $keepNewlines = true): ?string
{
if (null === $string) {
return null;
}
if ('' === $string) {
return '';
}
$search = [
private array $characters
= [
"\0", // NUL
"\f", // form feed
"\v", // vertical tab
@@ -136,24 +84,91 @@ trait ConvertsDataTypes
"\u{202F}", // narrow no-break space
"\u{3000}", // ideographic space
"\u{FEFF}", // zero width no -break space
"\r", // carriage return
];
$replace = "\x20"; // plain old normal space
$string = str_replace($search, $replace, $string);
$secondSearch = $keepNewlines ? ["\r"] : ["\r", "\n", "\t", "\036", "\025"];
$string = str_replace($secondSearch, '', $string);
/**
* Return integer value.
*
* @param string $field
*
* @return int
*/
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.
*
* @param string $key
* @param mixed|null $default
*
* @return mixed
*/
abstract public function get(string $key, mixed $default = null): mixed;
/**
* Return string value.
*
* @param string $field
*
* @return string
*/
public function convertString(string $field): string
{
$entry = $this->get($field);
if (!is_scalar($entry)) {
return '';
}
return (string)$this->clearString((string)$entry);
}
/**
* @param string|null $string
*
* @return string|null
*/
public function clearString(?string $string): ?string
{
$string = $this->clearStringKeepNewlines($string);
// clear zalgo text (TODO also in API v2)
$string = preg_replace('/(\pM{2})\pM+/u', '\1', $string);
if (null === $string) {
return null;
}
if ('' === $string) {
return '';
}
// then remove newlines too:
$string = str_replace(["\r", "\n", "\t", "\036", "\025"], '', $string);
return trim($string);
}
/**
* @param string|null $string
*
* @return string|null
*/
public function clearStringKeepNewlines(?string $string): ?string
{
if (null === $string) {
return null;
}
if ('' === $string) {
return '';
}
$string = str_replace($this->characters, "\x20", $string);
// clear zalgo text (TODO also in API v2)
$string = preg_replace('/(\pM{2})\pM+/u', '\1', $string);
return trim((string)$string);
}
/**
* TODO duplicate, see SelectTransactionsRequest
*
@@ -166,7 +181,8 @@ trait ConvertsDataTypes
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
if (method_exists($this, 'validateUserGroup')) { /** @phpstan-ignore-line */
if (method_exists($this, 'validateUserGroup')) {
/** @phpstan-ignore-line */
$userGroup = $this->validateUserGroup($this);
if (null !== $userGroup) {
$repository->setUserGroup($userGroup);
@@ -199,7 +215,7 @@ trait ConvertsDataTypes
*/
public function stringWithNewlines(string $field): string
{
return (string) $this->clearString((string)($this->get($field) ?? ''));
return (string)$this->clearStringKeepNewlines((string)($this->get($field) ?? ''));
}
/**
@@ -274,7 +290,7 @@ trait ConvertsDataTypes
return null;
}
if(false === $carbon) {
if (false === $carbon) {
app('log')->error(sprintf('[2] "%s" is of an invalid format.', $value));
return null;
}
@@ -383,7 +399,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
}

View File

@@ -1363,6 +1363,7 @@ class OperatorQuerySearch implements SearchInterface
* @param int $searchDirection
* @param int $stringPosition
* @param bool $prohibited
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function searchAccount(string $value, int $searchDirection, int $stringPosition, bool $prohibited = false): void
{
@@ -1432,6 +1433,7 @@ class OperatorQuerySearch implements SearchInterface
}
/**
* TODO make enums
* searchDirection: 1 = source (default), 2 = destination, 3 = both
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
*
@@ -1439,6 +1441,7 @@ class OperatorQuerySearch implements SearchInterface
* @param int $searchDirection
* @param int $stringPosition
* @param bool $prohibited
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function searchAccountNr(string $value, int $searchDirection, int $stringPosition, bool $prohibited = false): void
{
@@ -1580,6 +1583,7 @@ class OperatorQuerySearch implements SearchInterface
/**
*
* @throws FireflyException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function setExactDateParams(array $range, bool $prohibited = false): void
{
@@ -1654,6 +1658,7 @@ class OperatorQuerySearch implements SearchInterface
/**
*
* @throws FireflyException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function setDateBeforeParams(array $range, bool $prohibited = false): void
{
@@ -1700,6 +1705,7 @@ class OperatorQuerySearch implements SearchInterface
/**
*
* @throws FireflyException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function setDateAfterParams(array $range, bool $prohibited = false): void
{
@@ -1745,6 +1751,7 @@ class OperatorQuerySearch implements SearchInterface
/**
* @throws FireflyException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function setExactMetaDateParams(string $field, array $range, bool $prohibited = false): void
{
@@ -1820,6 +1827,7 @@ class OperatorQuerySearch implements SearchInterface
/**
* @throws FireflyException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function setMetaDateBeforeParams(string $field, array $range, bool $prohibited = false): void
{
@@ -1865,6 +1873,7 @@ class OperatorQuerySearch implements SearchInterface
/**
* @throws FireflyException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function setMetaDateAfterParams(string $field, array $range, bool $prohibited = false): void
{
@@ -1910,6 +1919,7 @@ class OperatorQuerySearch implements SearchInterface
/**
* @throws FireflyException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function setExactObjectDateParams(string $field, array $range, bool $prohibited = false): void
{
@@ -1985,6 +1995,7 @@ class OperatorQuerySearch implements SearchInterface
/**
*
* @throws FireflyException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function setObjectDateBeforeParams(string $field, array $range, bool $prohibited = false): void
{
@@ -2031,6 +2042,7 @@ class OperatorQuerySearch implements SearchInterface
/**
*
* @throws FireflyException
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
private function setObjectDateAfterParams(string $field, array $range, bool $prohibited = false): void
{

View File

@@ -449,7 +449,7 @@ class Steam
// but we need to convert each transaction separately because the date difference may
// incur huge currency changes.
$converter = new ExchangeRateConverter();
foreach ($new as $index => $set) {
foreach ($new as $set) {
foreach ($set as $transaction) {
$date = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date']);
if(false === $date) {