Fix various phpstan issues.

This commit is contained in:
James Cole
2023-11-04 07:18:03 +01:00
parent dc45131f73
commit ef428a0226
42 changed files with 104 additions and 174 deletions

View File

@@ -305,20 +305,4 @@ class Amount
return $format;
}
/**
* @param string $value
*
* @return string
*/
private function tryDecrypt(string $value): string
{
try {
$value = Crypt::decrypt($value); // verified
} catch (DecryptException $e) {
// @ignoreException
}
return $value;
}
}

View File

@@ -54,7 +54,7 @@ class RemoteUserGuard implements Guard
*/
public function __construct(UserProvider $provider, Application $app)
{
/** @var Request $request */
/** @var Request|null $request */
$request = $app->get('request');
app('log')->debug(sprintf('Created RemoteUserGuard for %s "%s"', $request?->getMethod(), $request?->getRequestUri()));
$this->application = $app;

View File

@@ -54,7 +54,7 @@ class BudgetList implements BinderInterface
$list = array_unique(array_map('\intval', explode(',', $value)));
if (0 === count($list)) {
if (0 === count($list)) { // @phpstan-ignore-line
app('log')->warning('Budget list count is zero, return 404.');
throw new NotFoundHttpException();
}

View File

@@ -51,7 +51,7 @@ class CategoryList implements BinderInterface
}
$list = array_unique(array_map('\intval', explode(',', $value)));
if (0 === count($list)) {
if (0 === count($list)) { // @phpstan-ignore-line
throw new NotFoundHttpException();
}

View File

@@ -71,7 +71,7 @@ class Date implements BinderInterface
try {
$result = new Carbon($value);
} catch (InvalidDateException $e) {
} catch (InvalidDateException $e) { // @phpstan-ignore-line
$message = sprintf('Could not parse date "%s" for user #%d: %s', $value, auth()->user()->id, $e->getMessage());
app('log')->error($message);
throw new NotFoundHttpException($message, $e);

View File

@@ -70,7 +70,7 @@ class JournalList implements BinderInterface
protected static function parseList(string $value): array
{
$list = array_unique(array_map('\intval', explode(',', $value)));
if (0 === count($list)) {
if (0 === count($list)) { // @phpstan-ignore-line
throw new NotFoundHttpException();
}

View File

@@ -52,7 +52,7 @@ class TagList implements BinderInterface
$list = array_unique(array_map('\strtolower', explode(',', $value)));
app('log')->debug('List of tags is', $list);
if (0 === count($list)) {
if (0 === count($list)) { // @phpstan-ignore-line
app('log')->error('Tag list is empty.');
throw new NotFoundHttpException();
}

View File

@@ -266,10 +266,10 @@ trait ConvertsDataTypes
// probably a date format.
try {
$carbon = Carbon::createFromFormat('Y-m-d', $value);
} catch (InvalidDateException $e) {
} catch (InvalidDateException $e) { // @phpstan-ignore-line
app('log')->error(sprintf('[1] "%s" is not a valid date: %s', $value, $e->getMessage()));
return null;
} catch (InvalidFormatException $e) {
} catch (InvalidFormatException $e) { // @phpstan-ignore-line
app('log')->error(sprintf('[2] "%s" is of an invalid format: %s', $value, $e->getMessage()));
return null;
@@ -279,7 +279,7 @@ trait ConvertsDataTypes
// is an atom string, I hope?
try {
$carbon = Carbon::parse($value);
} catch (InvalidDateException $e) {
} catch (InvalidDateException $e) { // @phpstan-ignore-line
app('log')->error(sprintf('[3] "%s" is not a valid date or time: %s', $value, $e->getMessage()));
return null;

View File

@@ -312,9 +312,9 @@ class Steam
continue;
}
// otherwise, convert 'amount' to the necessary currency:
$currencyId = (int)$transaction['transaction_currency_id'];
$currency = $currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
$currencyId = (int)$transaction['transaction_currency_id'];
$currency = $currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
$currencies[$currencyId] = $currency;
$rate = $converter->getCurrencyRate($currency, $native, $day);
$convertedAmount = bcmul($transaction['amount'], $rate);
@@ -322,15 +322,15 @@ class Steam
$balances[$format] = $currentBalance;
app('log')->debug(sprintf(
'%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',
$format,
$currency->code,
$rate,
$currency->code,
$transaction['amount'],
$native->code,
$convertedAmount
));
'%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',
$format,
$currency->code,
$rate,
$currency->code,
$transaction['amount'],
$native->code,
$convertedAmount
));
}