diff --git a/app/Helpers/Help/Help.php b/app/Helpers/Help/Help.php index 584e8d5a73..c1b1af2293 100644 --- a/app/Helpers/Help/Help.php +++ b/app/Helpers/Help/Help.php @@ -27,11 +27,10 @@ use Route; */ class Help implements HelpInterface { + const CACHEKEY = 'help_%s_%s'; /** @var string */ protected $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36'; - const CACHEKEY = 'help_%s_%s'; - /** * @param string $route * @param string $language diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 6ea0eb2119..73c0d4dfe6 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -138,14 +138,14 @@ class HomeController extends Controller } return view( - 'index', compact('count', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage', 'billCount') + 'index', compact('count', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage', 'billCount') ); } public function routes() { $set = RouteFacade::getRoutes(); - $ignore = ['chart.','javascript.','json.','report-data.','popup.','debugbar.']; + $ignore = ['chart.', 'javascript.', 'json.', 'report-data.', 'popup.', 'debugbar.']; /** @var Route $route */ foreach ($set as $route) { $name = $route->getName(); @@ -157,7 +157,7 @@ class HomeController extends Controller } } if (!$found) { - echo 'touch '.$route->getName() . '.md;'; + echo 'touch ' . $route->getName() . '.md;'; } } diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index 207f98cd6f..c9fbe8dba4 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -89,7 +89,7 @@ class PiggyBankController extends Controller /** @var Carbon $date */ $date = session('end', Carbon::now()->endOfMonth()); $leftOnAccount = $piggyBank->leftOnAccount($date); - $savedSoFar = $piggyBank->currentRelevantRep()->currentamount?? '0'; + $savedSoFar = $piggyBank->currentRelevantRep()->currentamount ?? '0'; $leftToSave = bcsub($piggyBank->targetamount, $savedSoFar); $maxAmount = min($leftOnAccount, $leftToSave); diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index a3c01f998d..65fdb571e0 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -213,11 +213,11 @@ class MassController extends Controller if ($journal) { // get optional fields: $what = strtolower($journal->transactionTypeStr()); - $sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0; + $sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0; $sourceAccountName = $request->get('source_account_name')[$journal->id] ?? ''; - $destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0; + $destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0; $destAccountName = $request->get('destination_account_name')[$journal->id] ?? ''; - $budgetId = $request->get('budget_id')[$journal->id] ?? 0; + $budgetId = $request->get('budget_id')[$journal->id] ?? 0; $category = $request->get('category')[$journal->id]; $tags = $journal->tags->pluck('tag')->toArray(); $amount = round($request->get('amount')[$journal->id], 12); diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index df835e940a..a9db6ca7c4 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -10,6 +10,7 @@ */ declare(strict_types=1); + use Carbon\Carbon; use DaveJamesMiller\Breadcrumbs\Generator as BreadCrumbGenerator; use FireflyIII\Exceptions\FireflyException; diff --git a/app/Import/Object/ImportBill.php b/app/Import/Object/ImportBill.php index b8bbb18161..1760b33126 100644 --- a/app/Import/Object/ImportBill.php +++ b/app/Import/Object/ImportBill.php @@ -180,8 +180,8 @@ class ImportBill Log::debug('Finding a mapped bill based on', $array); - $search = intval($array['mapped']); - $bill = $this->repository->find($search); + $search = intval($array['mapped']); + $bill = $this->repository->find($search); if (is_null($bill->id)) { Log::error(sprintf('There is no bill with id #%d. Invalid mapping will be ignored!', $search)); diff --git a/app/Import/Object/ImportBudget.php b/app/Import/Object/ImportBudget.php index cbc1e05460..07124ec0f2 100644 --- a/app/Import/Object/ImportBudget.php +++ b/app/Import/Object/ImportBudget.php @@ -180,7 +180,7 @@ class ImportBudget Log::debug('Finding a mapped budget based on', $array); - $search = intval($array['mapped']); + $search = intval($array['mapped']); $budget = $this->repository->find($search); if (is_null($budget->id)) { diff --git a/app/Import/Object/ImportCategory.php b/app/Import/Object/ImportCategory.php index b86a73d6ec..f9e56425d1 100644 --- a/app/Import/Object/ImportCategory.php +++ b/app/Import/Object/ImportCategory.php @@ -174,7 +174,7 @@ class ImportCategory Log::debug('Finding a mapped category based on', $array); - $search = intval($array['mapped']); + $search = intval($array['mapped']); $category = $this->repository->find($search); if (is_null($category->id)) { diff --git a/app/Import/Object/ImportJournal.php b/app/Import/Object/ImportJournal.php index c4aa0feaa3..3a0b74ade5 100644 --- a/app/Import/Object/ImportJournal.php +++ b/app/Import/Object/ImportJournal.php @@ -65,19 +65,6 @@ class ImportJournal /** @var User */ private $user; - /** - * @return string - */ - public function getDescription(): string - { - if ($this->description === '') { - return '(no description)'; - } - - return $this->description; - } - - /** * ImportEntry constructor. */ @@ -157,6 +144,18 @@ class ImportJournal return $date; } + /** + * @return string + */ + public function getDescription(): string + { + if ($this->description === '') { + return '(no description)'; + } + + return $this->description; + } + /** * @param string $hash */ diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.php index 7a4f4ab78f..ad0904b866 100644 --- a/app/Import/Storage/ImportStorage.php +++ b/app/Import/Storage/ImportStorage.php @@ -474,31 +474,32 @@ class ImportStorage private function verifyDoubleTransfer(TransactionType $transactionType, ImportJournal $importJournal): bool { if ($transactionType->type === TransactionType::TRANSFER) { - $amount = Steam::positive($importJournal->getAmount()); - $date = $importJournal->getDate($this->dateFormat); - $set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->leftJoin( - 'transactions AS source', function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 'source.transaction_journal_id')->where('source.amount', '<', 0); - } - ) - ->leftJoin( - 'transactions AS destination', function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 'destination.transaction_journal_id')->where( - 'destination.amount', '>', 0 - ); - } - ) - ->leftJoin('accounts as source_accounts', 'source.account_id', '=', 'source_accounts.id') - ->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id') - ->where('transaction_journals.user_id', $this->job->user_id) - ->where('transaction_types.type', TransactionType::TRANSFER) - ->where('transaction_journals.date', $date->format('Y-m-d')) - ->where('destination.amount', $amount) - ->get( - ['transaction_journals.id', 'transaction_journals.encrypted', 'transaction_journals.description', - 'source_accounts.name as source_name', 'destination_accounts.name as destination_name'] - ); + $amount = Steam::positive($importJournal->getAmount()); + $date = $importJournal->getDate($this->dateFormat); + $set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->leftJoin( + 'transactions AS source', function (JoinClause $join) { + $join->on('transaction_journals.id', '=', 'source.transaction_journal_id')->where('source.amount', '<', 0); + } + ) + ->leftJoin( + 'transactions AS destination', function (JoinClause $join) { + $join->on('transaction_journals.id', '=', 'destination.transaction_journal_id')->where( + 'destination.amount', '>', 0 + ); + } + ) + ->leftJoin('accounts as source_accounts', 'source.account_id', '=', 'source_accounts.id') + ->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id') + ->where('transaction_journals.user_id', $this->job->user_id) + ->where('transaction_types.type', TransactionType::TRANSFER) + ->where('transaction_journals.date', $date->format('Y-m-d')) + ->where('destination.amount', $amount) + ->get( + ['transaction_journals.id', 'transaction_journals.encrypted', 'transaction_journals.description', + 'source_accounts.name as source_name', 'destination_accounts.name as destination_name'] + ); + return $this->filterTransferSet($set, $importJournal); } diff --git a/app/Support/Amount.php b/app/Support/Amount.php index 071c3e48b6..5662f8261b 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -311,7 +311,7 @@ class Amount $coloured = false; $format = '%s'; } - if($transaction->transaction_type_type === TransactionType::OPENING_BALANCE) { + if ($transaction->transaction_type_type === TransactionType::OPENING_BALANCE) { $amount = strval($transaction->transaction_amount); } diff --git a/app/Support/Import/Configuration/Csv/Roles.php b/app/Support/Import/Configuration/Csv/Roles.php index 445628aeab..f53a01abf7 100644 --- a/app/Support/Import/Configuration/Csv/Roles.php +++ b/app/Support/Import/Configuration/Csv/Roles.php @@ -135,7 +135,7 @@ class Roles implements ConfigurationInterface $count = $config['column-count']; for ($i = 0; $i < $count; $i++) { $role = $config['column-roles'][$i] ?? '_ignore'; - $mapping = $config['column-do-mapping'][$i] ?? false; + $mapping = $config['column-do-mapping'][$i] ?? false; if ($role === '_ignore' && $mapping === true) { $mapping = false; @@ -160,7 +160,7 @@ class Roles implements ConfigurationInterface $count = $config['column-count']; $toBeMapped = 0; for ($i = 0; $i < $count; $i++) { - $mapping = $config['column-do-mapping'][$i] ?? false; + $mapping = $config['column-do-mapping'][$i] ?? false; if ($mapping === true) { $toBeMapped++; } diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 7b08463261..c77e3cf3be 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -249,21 +249,6 @@ class Steam return $value; } - /** - * @param $value - * - * @return mixed - */ - public function tryDecrypt($value) - { - try { - $value = Crypt::decrypt($value); - } catch (DecryptException $e) { - // do not care. - } - - return $value; - } /** * @param array $accounts @@ -361,4 +346,20 @@ class Steam return $amount; } + /** + * @param $value + * + * @return mixed + */ + public function tryDecrypt($value) + { + try { + $value = Crypt::decrypt($value); + } catch (DecryptException $e) { + // do not care. + } + + return $value; + } + } diff --git a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php index feed6fb66e..f470c14799 100644 --- a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php +++ b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php @@ -41,10 +41,6 @@ class TwoFactorControllerTest extends TestCase Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once(); - $falsePref = new Preference; - $falsePref->data = false; - Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.index', false])->andReturn($falsePref)->once(); - $response = $this->get(route('two-factor.index')); $response->assertStatus(200); } @@ -61,7 +57,6 @@ class TwoFactorControllerTest extends TestCase Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference)->twice(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn(null)->once(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null)->once(); - Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.index', false])->andReturn($falsePreference)->once(); $response = $this->get(route('two-factor.index')); $response->assertStatus(302); @@ -84,10 +79,6 @@ class TwoFactorControllerTest extends TestCase Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once(); - $falsePref = new Preference; - $falsePref->data = false; - Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.index', false])->andReturn($falsePref)->once(); - $response = $this->get(route('two-factor.index')); $response->assertStatus(500); } @@ -107,10 +98,6 @@ class TwoFactorControllerTest extends TestCase Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference); - $falsePref = new Preference; - $falsePref->data = false; - Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.lost', false])->andReturn($falsePref)->once(); - $response = $this->get(route('two-factor.lost')); $response->assertStatus(200); } diff --git a/tests/Feature/Controllers/HelpControllerTest.php b/tests/Feature/Controllers/HelpControllerTest.php index 24740f766b..a499512fd6 100644 --- a/tests/Feature/Controllers/HelpControllerTest.php +++ b/tests/Feature/Controllers/HelpControllerTest.php @@ -56,12 +56,9 @@ class HelpControllerTest extends TestCase $help->shouldReceive('getFromGithub')->withArgs(['index', 'nl_NL'])->andReturn('')->once(); // is US in cache? - $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(true)->twice(); + $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(true)->once(); $help->shouldReceive('getFromCache')->withArgs(['index', 'en_US'])->andReturn('US from cache.')->once(); - // put US in cache: - $help->shouldReceive('putInCache')->once(); - $this->be($this->user()); $response = $this->get(route('help.show', ['index'])); $response->assertStatus(200); @@ -87,12 +84,9 @@ class HelpControllerTest extends TestCase $help->shouldReceive('getFromGithub')->withArgs(['index', 'nl_NL'])->andReturn('')->once(); // is US in cache? - $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->twice(); + $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once(); $help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once(); - // put US in cache: - $help->shouldReceive('putInCache')->once(); - $this->be($this->user()); $response = $this->get(route('help.show', ['index'])); $response->assertStatus(200);