Fix various phpstan errors

This commit is contained in:
James Cole
2023-11-05 16:11:09 +01:00
parent 998fed7782
commit 5b05fb07ae
5 changed files with 17 additions and 19 deletions

View File

@@ -37,7 +37,7 @@ class RenameMetaFields extends Command
protected $description = 'Rename changed meta fields.';
protected $signature = 'firefly-iii:rename-meta-fields';
private int $count;
private int $count = 0;
/**
* Execute the console command.
@@ -46,8 +46,6 @@ class RenameMetaFields extends Command
*/
public function handle(): int
{
$this->count = 0;
$changes = [
'original-source' => 'original_source',
'importHash' => 'import_hash',

View File

@@ -54,7 +54,6 @@ class CreateDatabase extends Command
return 0;
}
// try to set up a raw connection:
$pdo = false;
$exists = false;
$checked = false; // checked for existence of DB?
$dsn = sprintf('mysql:host=%s;port=%d;charset=utf8mb4', env('DB_HOST', 'localhost'), env('DB_PORT', '3306'));
@@ -79,26 +78,23 @@ class CreateDatabase extends Command
}
// only continue when no error.
if (false !== $pdo) {
// with PDO, try to list DB's (
$stmt = $pdo->query('SHOW DATABASES;');
$checked = true;
// slightly more complex but less error prone.
foreach ($stmt as $row) {
$name = $row['Database'] ?? false;
if ($name === env('DB_DATABASE')) {
$exists = true;
}
// with PDO, try to list DB's (
$stmt = $pdo->query('SHOW DATABASES;');
// slightly more complex but less error-prone.
foreach ($stmt as $row) {
$name = $row['Database'] ?? false;
if ($name === env('DB_DATABASE')) {
$exists = true;
}
}
if (false === $exists && true === $checked) {
if (false === $exists) {
$this->friendlyError(sprintf('Database "%s" does not exist.', env('DB_DATABASE')));
// try to create it.
$pdo->exec(sprintf('CREATE DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;', env('DB_DATABASE')));
$this->friendlyInfo(sprintf('Created database "%s"', env('DB_DATABASE')));
}
if (true === $exists && true === $checked) {
if (true === $exists) {
$this->friendlyInfo(sprintf('Database "%s" exists.', env('DB_DATABASE')));
}

View File

@@ -25,7 +25,9 @@ namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\User;
use Illuminate\Console\Command;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@@ -65,8 +67,10 @@ class BudgetLimitCurrency extends Command
/** @var BudgetLimit $budgetLimit */
foreach ($budgetLimits as $budgetLimit) {
if (null === $budgetLimit->transaction_currency_id) {
/** @var Budget|null $budget */
$budget = $budgetLimit->budget;
if (null !== $budget) {
/** @var User|null $user */
$user = $budget->user;
if (null !== $user) {
$currency = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);

View File

@@ -212,7 +212,7 @@ class DecryptDatabase extends Command
return;
}
/** @var Preference $object */
/** @var Preference|null $object */
$object = Preference::find($id);
if (null !== $object) {
$object->data = $newValue;

View File

@@ -226,7 +226,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
// get bindable.
if (TransactionJournal::class === $attachment->attachable_type) {
// is linked to journal, get group of journal (if not also deleted)
/** @var TransactionJournal $journal */
/** @var TransactionJournal|null $journal */
$journal = $user->transactionJournals()->withTrashed()->find($attachment->attachable_id);
if (null !== $journal) {
return redirect(route('transactions.show', [$journal->transaction_group_id]));
@@ -234,7 +234,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
}
if (Bill::class === $attachment->attachable_type) {
// is linked to bill.
/** @var Bill $bill */
/** @var Bill|null $bill */
$bill = $user->bills()->withTrashed()->find($attachment->attachable_id);
if (null !== $bill) {
return redirect(route('bills.show', [$bill->id]));