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 Carbon|null $deleted_at
* @property int $recurrence_id * @property int $recurrence_id
* @property string $name * @property string $name
* @property string $value * @property mixed $value
* @property-read \FireflyIII\Models\Recurrence $recurrence * @property-read \FireflyIII\Models\Recurrence $recurrence
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newQuery() * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newQuery()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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