Reverse logic operators.

This commit is contained in:
James Cole 2020-10-24 16:59:56 +02:00
parent 179a710c5b
commit b3f1737495
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
11 changed files with 52 additions and 31 deletions

View File

@ -43,11 +43,13 @@ class OtherCurrenciesCorrections extends Command
public 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 Command
break;
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) {

View File

@ -87,7 +87,7 @@ trait VerifiesAccessToken
return 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));

View File

@ -252,7 +252,7 @@ class DebugController extends Controller
if (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;
}

View File

@ -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');
}
/**

View File

@ -87,4 +87,6 @@ class Note extends Model
{
return $this->morphTo();
}
}

View File

@ -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;
}
}

View File

@ -60,6 +60,6 @@ class ZeroOrMore implements Rule
}
$res = bccomp('0', $value);
return !($res > 0);
return $res <= 0;
}
}

View File

@ -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; // @codeCoverageIgnore
Log::debug(sprintf('URI is now %s (uri contains jscript)', $uri));
}

View File

@ -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');

View File

@ -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';
}

View File

@ -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';