Various code cleanup.

This commit is contained in:
James Cole 2021-04-06 18:36:37 +02:00
parent 9c1cee738d
commit fe06a1f7a0
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
10 changed files with 31 additions and 27 deletions

View File

@ -38,7 +38,7 @@ use Illuminate\Support\Carbon;
* @property Carbon|null $deleted_at
* @property int $recurrence_id
* @property string $name
* @property string $value
* @property mixed $value
* @property-read \FireflyIII\Models\Recurrence $recurrence
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newQuery()

View File

@ -38,7 +38,7 @@ use Illuminate\Support\Carbon;
* @property Carbon|null $deleted_at
* @property int $rt_id
* @property string $name
* @property string $value
* @property mixed $value
* @property-read \FireflyIII\Models\RecurrenceTransaction $recurrenceTransaction
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceTransactionMeta newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceTransactionMeta newQuery()

View File

@ -46,8 +46,8 @@ class TransactionGroupDestroyService
}
try {
$transactionGroup->delete();
} catch (Exception $e) {
app('log')->error(sprintf('Could not delete transaction group: %s', $e->getMessage())); // @codeCoverageIgnore
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
}

View File

@ -66,6 +66,7 @@ trait AccountServiceTrait
return null;
}
return $iban;
}
@ -132,7 +133,7 @@ trait AccountServiceTrait
foreach ($fields as $field) {
// if the field is set but NULL, skip it.
// if the field is set but "", update it.
if (isset($data[$field]) && null !== $data[$field]) {
if (array_key_exists($field, $data) && null !== $data[$field]) {
// convert boolean value:
if (is_bool($data[$field]) && false === $data[$field]) {
@ -192,7 +193,7 @@ trait AccountServiceTrait
if ('' !== $data['opening_balance'] && 0 === bccomp($data['opening_balance'], '0')) {
$data['opening_balance'] = ''; // @codeCoverageIgnore
}
if ('' !== $data['opening_balance'] && isset($data['opening_balance'], $data['opening_balance_date'])) {
if ('' !== $data['opening_balance'] && array_key_exists('opening_balance_date', $data) && '' !== $data['opening_balance_date']) {
Log::debug('Array has valid opening balance data.');
return true;
@ -244,7 +245,7 @@ trait AccountServiceTrait
// find currency, or use default currency instead.
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
/** @var TransactionCurrency $currency */
/** @var TransactionCurrency|null $currency */
$currency = $factory->find($currencyId, $currencyCode);
if (null === $currency) {

View File

@ -74,8 +74,8 @@ trait BillServiceTrait
if (null !== $dbNote) {
try {
$dbNote->delete();
} catch (Exception $e) {
Log::debug(sprintf('Error deleting note: %s', $e->getMessage()));
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
}

View File

@ -185,7 +185,7 @@ trait JournalServiceTrait
// final attempt, create it.
if (AccountType::ASSET === $preferredType) {
throw new FireflyException('TransactionFactory: Cannot create asset account with these values', $data);
throw new FireflyException(sprintf('TransactionFactory: Cannot create asset account with these values: %s',json_encode($data)));
}
// fix name of account if only IBAN is given:
if ('' === (string)$data['name'] && '' !== (string)$data['iban']) {
@ -358,11 +358,9 @@ trait JournalServiceTrait
// try to delete existing notes.
try {
$note->delete();
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::debug(sprintf('Could not delete journal notes: %s', $e->getMessage()));
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
// @codeCoverageIgnoreEnd
}
}

View File

@ -41,6 +41,7 @@ use FireflyIII\Models\RecurrenceTransactionMeta;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Validation\AccountValidator;
use Log;
/**
* Trait RecurringTransactionTrait
*
@ -60,8 +61,8 @@ trait RecurringTransactionTrait
if (null !== $dbNote) {
try {
$dbNote->delete();
} catch (Exception $e) {
Log::debug(sprintf('Error deleting note: %s', $e->getMessage()));
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
}
@ -179,10 +180,9 @@ trait RecurringTransactionTrait
}
/**
* @param array $expectedTypes
* @param Account|null $account
* @param int|null $accountId
* @param string|null $accountName
* @param array $expectedTypes
* @param int|null $accountId
* @param string|null $accountName
*
* @return Account
*/
@ -212,6 +212,7 @@ trait RecurringTransactionTrait
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($this->user);
/** @var string $expectedType */
foreach ($expectedTypes as $expectedType) {
if (in_array($expectedType, $cannotCreate, true)) {
continue;
@ -287,7 +288,7 @@ trait RecurringTransactionTrait
$factory->setUser($transaction->recurrence->user);
$piggyBank = $factory->find($piggyId, null);
if (null !== $piggyBank) {
/** @var RecurrenceMeta $entry */
/** @var RecurrenceMeta|null $entry */
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'piggy_bank_id')->first();
if (null === $entry) {
$entry = RecurrenceTransactionMeta::create(['rt_id' => $transaction->id, 'name' => 'piggy_bank_id', 'value' => $piggyBank->id]);
@ -307,8 +308,8 @@ trait RecurringTransactionTrait
*/
protected function updateTags(RecurrenceTransaction $transaction, array $tags): void
{
if (!empty($tags)) {
/** @var RecurrenceMeta $entry */
if (count($tags) > 0) {
/** @var RecurrenceMeta|null $entry */
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'tags')->first();
if (null === $entry) {
$entry = RecurrenceTransactionMeta::create(['rt_id' => $transaction->id, 'name' => 'tags', 'value' => json_encode($tags)]);
@ -316,7 +317,7 @@ trait RecurringTransactionTrait
$entry->value = json_encode($tags);
$entry->save();
}
if (empty($tags)) {
if (0 === count($tags)) {
// delete if present
$transaction->recurrenceTransactionMeta()->where('name', 'tags')->delete();
}
@ -345,8 +346,8 @@ trait RecurringTransactionTrait
$transaction->recurrenceTransactionMeta()->delete();
try {
$transaction->delete();
} catch (Exception $e) {
Log::debug($e->getMessage());
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
}
}

View File

@ -153,7 +153,7 @@ class CategoryUpdateService
if (null !== $dbNote) {
try {
$dbNote->delete();
} catch (Exception $e) {
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
}

View File

@ -47,6 +47,7 @@ class RemoteUserGuard implements Guard
*
* @return void
*/
// @phpstan-ignore-next-line
public function __construct(UserProvider $provider, Application $app) // @phpstan-ignore-line
{
$this->application = $app;

View File

@ -275,6 +275,9 @@ class Preferences
if (null === $value) {
return new Preference;
}
if(null === $pref) {
$pref = new Preference;
}
$pref->data = $value;
$pref->save();
Cache::forever($fullName, $pref);