Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Reverse logic operators.
James Coleb3f17374953c
diff --git a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.phpindex c72b014e06..ba3999405a 100644--- a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php+++ b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php@@ -43,11 +43,13 @@ class OtherCurrenciesCorrections extends Commandpublic const CONFIG_NAME = '480_other_currencies';/*** The console command description.+ ** @var string*/protected $description = 'Update all journal currency information.';/*** The name and signature of the console command.+ ** @var string*/protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}';@@ -67,6 +69,7 @@ class OtherCurrenciesCorrections extends Command/*** Execute the console command.+ ** @return int*/public function handle(): int@@ -93,6 +96,7 @@ class OtherCurrenciesCorrections extends Command/*** @param Account $account+ ** @return TransactionCurrency|null*/private function getCurrency(Account $account): ?TransactionCurrency@@ -120,7 +124,9 @@ class OtherCurrenciesCorrections extends Command/*** Gets the transaction that determines the transaction that "leads" and will determine* the currency to be used by all transactions, and the journal itself.+ ** @param TransactionJournal $journal+ ** @return Transaction|null*/private function getLeadTransaction(TransactionJournal $journal): ?Transaction@@ -138,11 +144,15 @@ class OtherCurrenciesCorrections extends Commandbreak;case TransactionType::OPENING_BALANCE:// whichever isn't an initial balance account:- $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']);+ $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(+ 'account_types', 'accounts.account_type_id', '=', 'account_types.id'+ )->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']);break;case TransactionType::RECONCILIATION:// whichever isn't the reconciliation account:- $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']);+ $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(+ 'account_types', 'accounts.account_type_id', '=', 'account_types.id'+ )->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']);break;}@@ -174,6 +184,7 @@ class OtherCurrenciesCorrections extends Command* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should* be called from the handle method instead of using the constructor to initialize the command.+ ** @codeCoverageIgnore*/private function stupidLaravel(): void@@ -211,27 +222,33 @@ class OtherCurrenciesCorrections extends Command$currency = $this->getCurrency($account);if (null === $currency) {// @codeCoverageIgnoreStart- $this->error(sprintf('Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', $account->id, $account->name, $journal->id));+ $this->error(+ sprintf(+ 'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', $account->id, $account->name, $journal->id+ )+ );$this->count++;return;// @codeCoverageIgnoreEnd}// fix each transaction:- $journal->transactions->each(static function (Transaction $transaction) use ($currency) {- if (null === $transaction->transaction_currency_id) {- $transaction->transaction_currency_id = $currency->id;- $transaction->save();- }+ $journal->transactions->each(+ static function (Transaction $transaction) use ($currency) {+ if (null === $transaction->transaction_currency_id) {+ $transaction->transaction_currency_id = $currency->id;+ $transaction->save();+ }- // when mismatch in transaction:- if (!((int)$transaction->transaction_currency_id === (int)$currency->id)) {- $transaction->foreign_currency_id = (int)$transaction->transaction_currency_id;- $transaction->foreign_amount = $transaction->amount;- $transaction->transaction_currency_id = $currency->id;- $transaction->save();+ // when mismatch in transaction:+ if ((int)$transaction->transaction_currency_id !== (int)$currency->id) {+ $transaction->foreign_currency_id = (int)$transaction->transaction_currency_id;+ $transaction->foreign_amount = $transaction->amount;+ $transaction->transaction_currency_id = $currency->id;+ $transaction->save();+ }}- });+ );// also update the journal, of course:$journal->transaction_currency_id = $currency->id;$this->count++;@@ -246,7 +263,9 @@ class OtherCurrenciesCorrections extends Command*/private function updateOtherJournalsCurrencies(): void{- $set = $this->cliRepos->getAllJournals([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]);+ $set = $this->cliRepos->getAllJournals(+ [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]+ );/** @var TransactionJournal $journal */foreach ($set as $journal) {diff --git a/app/Console/Commands/VerifiesAccessToken.php b/app/Console/Commands/VerifiesAccessToken.phpindex 9c7afe03e6..89fa96fc76 100644--- a/app/Console/Commands/VerifiesAccessToken.php+++ b/app/Console/Commands/VerifiesAccessToken.php@@ -87,7 +87,7 @@ trait VerifiesAccessTokenreturn false;}- if (!($accessToken->data === $token)) {+ if ($accessToken->data !== $token) {Log::error(sprintf('Invalid access token for user #%d.', $userId));Log::error(sprintf('Token given is "%s", expected something else.', $token));diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.phpindex 01a64ad9e6..d8396b1c5b 100644--- a/app/Http/Controllers/DebugController.php+++ b/app/Http/Controllers/DebugController.php@@ -252,7 +252,7 @@ class DebugController extends Controllerif (in_array('GET', $route->methods(), true)) {$found = false;foreach ($ignore as $string) {- if (!(false === stripos($name, $string))) {+ if (false !== stripos($name, $string)) {$found = true;break;}diff --git a/app/Http/Middleware/Installer.php b/app/Http/Middleware/Installer.phpindex 01bf1100c9..613af9d41e 100644--- a/app/Http/Middleware/Installer.php+++ b/app/Http/Middleware/Installer.php@@ -61,7 +61,7 @@ class Installer// don't run installer when already in installer.$url = $request->url();$strpos = stripos($url, '/install');- if (!(false === $strpos)) {+ if (false !== $strpos) {Log::debug(sprintf('URL is %s, will NOT run installer middleware', $url));return $next($request);@@ -90,7 +90,7 @@ class Installer*/protected function isAccessDenied(string $message): bool{- return !(false === stripos($message, 'Access denied'));+ return false !== stripos($message, 'Access denied');}/**@@ -102,7 +102,7 @@ class Installer*/protected function noTablesExist(string $message): bool{- return !(false === stripos($message, 'Base table or view not found'));+ return false !== stripos($message, 'Base table or view not found');}/**diff --git a/app/Models/Note.php b/app/Models/Note.phpindex aa11e1408e..55da6764b6 100644--- a/app/Models/Note.php+++ b/app/Models/Note.php@@ -87,4 +87,6 @@ class Note extends Model{return $this->morphTo();}++}\ No newline at end of filediff --git a/app/Rules/IsTransferAccount.php b/app/Rules/IsTransferAccount.phpindex 8ec34933c7..8f01c63d75 100644--- a/app/Rules/IsTransferAccount.php+++ b/app/Rules/IsTransferAccount.php@@ -71,6 +71,6 @@ class IsTransferAccount implements Rule$validAccount = $validator->validateSource((int)$value, null, null);Log::debug(sprintf('Search by id (%d), result is %s.', (int)$value, var_export($validAccount, true)));- return !(false === $validAccount);+ return false !== $validAccount;}}diff --git a/app/Rules/ZeroOrMore.php b/app/Rules/ZeroOrMore.phpindex 3b354431c9..d1bd6639c5 100644--- a/app/Rules/ZeroOrMore.php+++ b/app/Rules/ZeroOrMore.php@@ -60,6 +60,6 @@ class ZeroOrMore implements Rule}$res = bccomp('0', $value);- return !($res > 0);+ return $res <= 0;}}diff --git a/app/Support/Http/Controllers/UserNavigation.php b/app/Support/Http/Controllers/UserNavigation.phpindex 10c3ccbd74..c324434c92 100644--- a/app/Support/Http/Controllers/UserNavigation.php+++ b/app/Support/Http/Controllers/UserNavigation.php@@ -154,7 +154,7 @@ trait UserNavigation$uri = (string)session($identifier);Log::debug(sprintf('The URI is %s', $uri));- if (!(false === strpos($uri, 'jscript'))) {+ if (false !== strpos($uri, 'jscript')) {$uri = $this->redirectUri; // @codeCoverageIgnoreLog::debug(sprintf('URI is now %s (uri contains jscript)', $uri));}diff --git a/app/Support/Steam.php b/app/Support/Steam.phpindex 39e66aa551..d73518b2e8 100644--- a/app/Support/Steam.php+++ b/app/Support/Steam.php@@ -531,21 +531,21 @@ class Steam{$string = strtolower($string);- if (!(false === stripos($string, 'k'))) {+ if (false !== stripos($string, 'k')) {// has a K in it, remove the K and multiply by 1024.$bytes = bcmul(rtrim($string, 'kK'), '1024');return (int)$bytes;}- if (!(false === stripos($string, 'm'))) {+ if (false !== stripos($string, 'm')) {// has a M in it, remove the M and multiply by 1048576.$bytes = bcmul(rtrim($string, 'mM'), '1048576');return (int)$bytes;}- if (!(false === stripos($string, 'g'))) {+ if (false !== stripos($string, 'g')) {// has a G in it, remove the G and multiply by (1024)^3.$bytes = bcmul(rtrim($string, 'gG'), '1073741824');diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.phpindex 16d210fb5b..acc13aaf5e 100644--- a/app/Support/Twig/General.php+++ b/app/Support/Twig/General.php@@ -95,7 +95,7 @@ class General extends AbstractExtension$args = func_get_args();$route = $args[0]; // name of the route.$name = Route::getCurrentRoute()->getName() ?? '';- if (!(false === strpos($name, $route))) {+ if (false !== strpos($name, $route)) {return 'active';}@@ -118,7 +118,7 @@ class General extends AbstractExtension$args = func_get_args();$route = $args[0]; // name of the route.$name = Route::getCurrentRoute()->getName() ?? '';- if (!(false === strpos($name, $route))) {+ if (false !== strpos($name, $route)) {return 'menu-open';}@@ -141,7 +141,7 @@ class General extends AbstractExtension[, $route, $objectType] = func_get_args();$activeObjectType = $context['objectType'] ?? false;- if ($objectType === $activeObjectType && !(false === stripos(Route::getCurrentRoute()->getName(), $route))) {+ if ($objectType === $activeObjectType && false !== stripos(Route::getCurrentRoute()->getName(), $route)) {return 'active';}diff --git a/config/database.php b/config/database.phpindex 9a40073397..e4a1338577 100644--- a/config/database.php+++ b/config/database.php@@ -30,7 +30,7 @@ $password = '';$database = '';$port = '';-if (!(false === $databaseUrl)) {+if (false !== $databaseUrl) {$options = parse_url($databaseUrl);$host = $options['host'] ?? 'firefly_iii_db';$username = $options['user'] ?? 'firefly';