mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix a lot of phpstan things
This commit is contained in:
@@ -79,6 +79,7 @@ class CreateDatabase extends Command
|
||||
|
||||
// only continue when no error.
|
||||
// with PDO, try to list DB's (
|
||||
/** @var array $stmt */
|
||||
$stmt = $pdo->query('SHOW DATABASES;');
|
||||
// slightly more complex but less error-prone.
|
||||
foreach ($stmt as $row) {
|
||||
|
@@ -253,13 +253,14 @@ class ForceDecimalSize extends Command
|
||||
}
|
||||
/** @var Account $account */
|
||||
foreach ($result as $account) {
|
||||
/** @var string $field */
|
||||
foreach ($fields as $field) {
|
||||
$value = $account->$field;
|
||||
if (null === $value) {
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$pow = 10** $currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyInfo(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct));
|
||||
Account::find($account->id)->update([$field => $correct]);
|
||||
@@ -286,6 +287,7 @@ class ForceDecimalSize extends Command
|
||||
/** @var Builder $query */
|
||||
$query = $class::where('transaction_currency_id', $currency->id)->where(
|
||||
static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression) {
|
||||
/** @var string $field */
|
||||
foreach ($fields as $field) {
|
||||
$q->orWhere(
|
||||
DB::raw(sprintf('CAST(%s AS %s)', $field, $cast)), // @phpstan-ignore-line
|
||||
@@ -304,13 +306,14 @@ class ForceDecimalSize extends Command
|
||||
}
|
||||
/** @var Model $item */
|
||||
foreach ($result as $item) {
|
||||
/** @var string $field */
|
||||
foreach ($fields as $field) {
|
||||
$value = $item->$field;
|
||||
if (null === $value) {
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$pow = 10** $currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(sprintf('%s #%d has %s with value "%s", this has been corrected to "%s".', $table, $item->id, $field, $value, $correct));
|
||||
$class::find($item->id)->update([$field => $correct]);
|
||||
@@ -356,13 +359,14 @@ class ForceDecimalSize extends Command
|
||||
}
|
||||
/** @var PiggyBankEvent $item */
|
||||
foreach ($result as $item) {
|
||||
/** @var string $field */
|
||||
foreach ($fields as $field) {
|
||||
$value = $item->$field;
|
||||
if (null === $value) {
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$pow = 10** $currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(
|
||||
sprintf('Piggy bank event #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
|
||||
@@ -410,13 +414,14 @@ class ForceDecimalSize extends Command
|
||||
}
|
||||
/** @var PiggyBankRepetition $item */
|
||||
foreach ($result as $item) {
|
||||
/** @var string $field */
|
||||
foreach ($fields as $field) {
|
||||
$value = $item->$field;
|
||||
if (null === $value) {
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$pow = 10** $currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(
|
||||
sprintf('Piggy bank repetition #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
|
||||
@@ -463,13 +468,14 @@ class ForceDecimalSize extends Command
|
||||
}
|
||||
/** @var PiggyBank $item */
|
||||
foreach ($result as $item) {
|
||||
/** @var string $field */
|
||||
foreach ($fields as $field) {
|
||||
$value = $item->$field;
|
||||
if (null === $value) {
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$pow = 10** $currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct));
|
||||
PiggyBank::find($item->id)->update([$field => $correct]);
|
||||
@@ -506,7 +512,7 @@ class ForceDecimalSize extends Command
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = (float)10** (int)$currency->decimal_places;
|
||||
$pow = (float)10** $currency->decimal_places;
|
||||
$correct = bcdiv((string)round((float)$value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct));
|
||||
Transaction::find($item->id)->update(['amount' => $correct]);
|
||||
@@ -533,7 +539,7 @@ class ForceDecimalSize extends Command
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = (float)10** (int)$currency->decimal_places;
|
||||
$pow = (float)10** $currency->decimal_places;
|
||||
$correct = bcdiv((string)round((float)$value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(
|
||||
sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)
|
||||
|
@@ -67,11 +67,13 @@ class ScanAttachments extends Command
|
||||
$decryptedContent = $encryptedContent;
|
||||
}
|
||||
$tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII');
|
||||
if(false === $tempFileName) {
|
||||
app('log')->error(sprintf('Could not create temporary file for attachment #%d', $attachment->id));
|
||||
exit(1);
|
||||
}
|
||||
file_put_contents($tempFileName, $decryptedContent);
|
||||
$md5 = md5_file($tempFileName);
|
||||
$mime = mime_content_type($tempFileName);
|
||||
$attachment->md5 = $md5;
|
||||
$attachment->mime = $mime;
|
||||
$attachment->md5 = (string) md5_file($tempFileName);
|
||||
$attachment->mime = (string) mime_content_type($tempFileName);
|
||||
$attachment->save();
|
||||
$this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id));
|
||||
}
|
||||
|
@@ -61,14 +61,15 @@ class UpgradeFireflyInstructions extends Command
|
||||
*/
|
||||
private function updateInstructions(): void
|
||||
{
|
||||
/** @var string $version */
|
||||
$version = config('firefly.version');
|
||||
$version = (string) config('firefly.version');
|
||||
/** @var array $config */
|
||||
$config = config('upgrade.text.upgrade');
|
||||
$text = '';
|
||||
/** @var string $compare */
|
||||
foreach (array_keys($config) as $compare) {
|
||||
// if string starts with:
|
||||
if (str_starts_with($version, $compare)) {
|
||||
$text = $config[$compare];
|
||||
$text = (string) $config[$compare];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +79,7 @@ class UpgradeFireflyInstructions extends Command
|
||||
$this->showLine();
|
||||
|
||||
$this->boxed('');
|
||||
if (null === $text || '' === $text) {
|
||||
if ('' === $text) {
|
||||
$this->boxed(sprintf('Thank you for updating to Firefly III, v%s', $version));
|
||||
$this->boxedInfo('There are no extra upgrade instructions.');
|
||||
$this->boxed('Firefly III should be ready for use.');
|
||||
@@ -174,14 +175,15 @@ class UpgradeFireflyInstructions extends Command
|
||||
*/
|
||||
private function installInstructions(): void
|
||||
{
|
||||
/** @var string $version */
|
||||
$version = config('firefly.version');
|
||||
$version = (string) config('firefly.version');
|
||||
/** @var array $config */
|
||||
$config = config('upgrade.text.install');
|
||||
$text = '';
|
||||
/** @var string $compare */
|
||||
foreach (array_keys($config) as $compare) {
|
||||
// if string starts with:
|
||||
if (str_starts_with($version, $compare)) {
|
||||
$text = $config[$compare];
|
||||
$text = (string) $config[$compare];
|
||||
}
|
||||
}
|
||||
$this->newLine();
|
||||
@@ -189,7 +191,7 @@ class UpgradeFireflyInstructions extends Command
|
||||
$this->newLine();
|
||||
$this->showLine();
|
||||
$this->boxed('');
|
||||
if (null === $text || '' === $text) {
|
||||
if ('' === $text) {
|
||||
$this->boxed(sprintf('Thank you for installing Firefly III, v%s!', $version));
|
||||
$this->boxedInfo('There are no extra installation instructions.');
|
||||
$this->boxed('Firefly III should be ready for use.');
|
||||
|
Reference in New Issue
Block a user