From 980393232406d1918b13b6c981034ec5c5a1d44b Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 12 Aug 2017 10:27:45 +0200 Subject: [PATCH] Various code clean up. --- app/Console/Commands/UseEncryption.php | 2 ++ app/Http/Controllers/HomeController.php | 2 +- app/Http/Controllers/TagController.php | 2 +- app/Http/Controllers/Transaction/MassController.php | 3 +-- app/Http/Controllers/Transaction/SplitController.php | 2 +- app/Import/FileProcessor/CsvProcessor.php | 4 ++-- app/Import/Storage/ImportStorage.php | 5 ++--- app/Mail/RegisteredUser.php | 2 ++ app/Mail/RequestedNewPassword.php | 2 ++ app/Repositories/Account/AccountTasker.php | 3 ++- app/Support/Import/Configuration/Csv/Initial.php | 3 ++- app/Support/Import/Configuration/Csv/Map.php | 8 +++++--- app/Support/Import/Configuration/Csv/Roles.php | 3 ++- app/Support/Search/Search.php | 4 ++-- config/auth.php | 2 ++ config/broadcasting.php | 2 ++ config/cache.php | 2 ++ config/compile.php | 2 ++ config/database.php | 2 ++ config/filesystems.php | 2 ++ config/mail.php | 2 ++ config/queue.php | 2 ++ config/services.php | 2 ++ config/twigbridge.php | 2 ++ .../2016_10_09_150037_expand_transactions_table.php | 2 ++ .../migrations/2016_10_22_075804_changes_for_v410.php | 2 ++ .../migrations/2016_11_24_210552_changes_for_v420.php | 2 ++ .../migrations/2016_12_22_150431_changes_for_v430.php | 2 ++ .../migrations/2016_12_28_203205_changes_for_v431.php | 2 ++ .../migrations/2017_04_13_163623_changes_for_v440.php | 3 +++ .../migrations/2017_06_02_105232_changes_for_v450.php | 3 +++ resources/lang/en_US/auth.php | 2 ++ resources/lang/en_US/breadcrumbs.php | 2 ++ resources/lang/en_US/config.php | 2 ++ resources/lang/en_US/demo.php | 2 ++ resources/lang/en_US/firefly.php | 2 ++ resources/lang/en_US/form.php | 2 ++ resources/lang/en_US/help.php | 2 ++ resources/lang/en_US/intro.php | 4 +++- resources/lang/en_US/list.php | 2 ++ resources/lang/en_US/pagination.php | 2 ++ resources/lang/en_US/passwords.php | 2 ++ resources/lang/en_US/validation.php | 2 ++ resources/views/partials/password-modal.twig | 2 +- tests/CreatesApplication.php | 7 +++++++ tests/Feature/Controllers/AccountControllerTest.php | 3 +++ .../Controllers/Admin/ConfigurationControllerTest.php | 3 +++ tests/Feature/Controllers/Admin/HomeControllerTest.php | 3 +++ tests/Feature/Controllers/Admin/UserControllerTest.php | 3 +++ tests/Feature/Controllers/AttachmentControllerTest.php | 8 ++++++++ .../Controllers/Auth/ForgotPasswordControllerTest.php | 8 ++++++++ .../Controllers/Auth/TwoFactorControllerTest.php | 3 +++ tests/Feature/Controllers/BillControllerTest.php | 8 ++++++++ tests/Feature/Controllers/BudgetControllerTest.php | 8 ++++++++ tests/Feature/Controllers/CategoryControllerTest.php | 8 ++++++++ .../Controllers/Chart/AccountControllerTest.php | 3 +++ tests/Feature/Controllers/Chart/BillControllerTest.php | 3 +++ .../Feature/Controllers/Chart/BudgetControllerTest.php | 3 +++ .../Controllers/Chart/BudgetReportControllerTest.php | 8 ++++++++ .../Controllers/Chart/CategoryControllerTest.php | 3 +++ .../Controllers/Chart/CategoryReportControllerTest.php | 3 +++ .../Controllers/Chart/PiggyBankControllerTest.php | 3 +++ .../Feature/Controllers/Chart/ReportControllerTest.php | 3 +++ .../Controllers/Chart/TagReportControllerTest.php | 3 +++ tests/Feature/Controllers/CurrencyControllerTest.php | 3 +++ tests/Feature/Controllers/ExportControllerTest.php | 3 +++ tests/Feature/Controllers/HelpControllerTest.php | 3 +++ tests/Feature/Controllers/HomeControllerTest.php | 3 +++ .../Feature/Controllers/Import/FileControllerTest.php | 9 ++++++++- tests/Feature/Controllers/ImportControllerTest.php | 3 +++ tests/Feature/Controllers/JavascriptControllerTest.php | 3 +++ .../Controllers/Json/ExchangeControllerTest.php | 3 +++ tests/Feature/Controllers/JsonControllerTest.php | 3 +++ tests/Feature/Controllers/NewUserControllerTest.php | 3 +++ tests/Feature/Controllers/PiggyBankControllerTest.php | 3 +++ .../Feature/Controllers/Popup/ReportControllerTest.php | 3 +++ .../Feature/Controllers/PreferencesControllerTest.php | 3 +++ tests/Feature/Controllers/ProfileControllerTest.php | 3 +++ .../Controllers/Report/AccountControllerTest.php | 3 +++ .../Controllers/Report/BalanceControllerTest.php | 3 +++ .../Controllers/Report/BudgetControllerTest.php | 3 +++ .../Controllers/Report/CategoryControllerTest.php | 8 ++++++++ .../Controllers/Report/OperationsControllerTest.php | 3 +++ tests/Feature/Controllers/ReportControllerTest.php | 3 +++ tests/Feature/Controllers/RuleControllerTest.php | 3 +++ tests/Feature/Controllers/RuleGroupControllerTest.php | 3 +++ tests/Feature/Controllers/SearchControllerTest.php | 3 +++ tests/Feature/Controllers/TagControllerTest.php | 3 +++ .../Controllers/Transaction/ConvertControllerTest.php | 3 +++ .../Controllers/Transaction/MassControllerTest.php | 3 +++ .../Controllers/Transaction/SingleControllerTest.php | 3 +++ .../Controllers/Transaction/SplitControllerTest.php | 3 +++ .../Feature/Controllers/TransactionControllerTest.php | 8 ++++++++ tests/Feature/ExampleTest.php | 8 +++++++- tests/TestCase.php | 3 ++- tests/Unit/ExampleTest.php | 10 +++++++++- tests/Unit/Handlers/Events/UserEventHandlerTest.php | 8 ++++++++ tests/Unit/Helpers/AttachmentHelperTest.php | 3 +++ tests/Unit/Helpers/MetaPieChartTest.php | 8 ++++++++ 99 files changed, 322 insertions(+), 24 deletions(-) diff --git a/app/Console/Commands/UseEncryption.php b/app/Console/Commands/UseEncryption.php index 8cf70208b9..89e6bf012d 100644 --- a/app/Console/Commands/UseEncryption.php +++ b/app/Console/Commands/UseEncryption.php @@ -1,4 +1,6 @@ $journal) { + foreach ($journals as $journal) { $sources = $journal->sourceAccountList(); $destinations = $journal->destinationAccountList(); if ($sources->count() > 1) { diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.php index 32f0807c3b..23225eae8f 100644 --- a/app/Http/Controllers/Transaction/SplitController.php +++ b/app/Http/Controllers/Transaction/SplitController.php @@ -114,7 +114,7 @@ class SplitController extends Controller 'transactions.split.edit', compact( 'subTitleIcon', 'currencies', 'optionalFields', - 'preFilled', 'subTitle', 'amount', 'sourceAccounts', 'uploadSize', 'destinationAccounts', 'assetAccounts', + 'preFilled', 'subTitle', 'uploadSize', 'assetAccounts', 'budgets', 'journal' ) ); diff --git a/app/Import/FileProcessor/CsvProcessor.php b/app/Import/FileProcessor/CsvProcessor.php index b10549c703..10657c35bb 100644 --- a/app/Import/FileProcessor/CsvProcessor.php +++ b/app/Import/FileProcessor/CsvProcessor.php @@ -260,8 +260,8 @@ class CsvProcessor implements FileProcessorInterface private function specifics(array $row): array { $config = $this->job->configuration; - // - foreach ($config['specifics'] as $name => $enabled) { + $names = array_keys($config['specifics']); + foreach ($names as $name) { if (!in_array($name, $this->validSpecifics)) { throw new FireflyException(sprintf('"%s" is not a valid class name', $name)); diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.php index eea594fdbf..8e417efc61 100644 --- a/app/Import/Storage/ImportStorage.php +++ b/app/Import/Storage/ImportStorage.php @@ -252,12 +252,11 @@ class ImportStorage /** * @param ImportJournal $importJournal - * @param Account $account * @param TransactionCurrency $localCurrency * * @return int|null */ - private function getForeignCurrencyId(ImportJournal $importJournal, Account $account, TransactionCurrency $localCurrency): ?int + private function getForeignCurrencyId(ImportJournal $importJournal, TransactionCurrency $localCurrency): ?int { // get journal currency, if any: $currency = $importJournal->getCurrency()->getTransactionCurrency(); @@ -394,7 +393,7 @@ class ImportStorage $asset = $importJournal->asset->getAccount(); $amount = $importJournal->getAmount(); $currency = $this->getCurrency($importJournal, $asset); - $foreignCurrencyId = $this->getForeignCurrencyId($importJournal, $asset, $currency); + $foreignCurrencyId = $this->getForeignCurrencyId($importJournal, $currency); $date = $importJournal->getDate($this->dateFormat); $transactionType = $this->getTransactionType($amount); $opposing = $this->getOpposingAccount($importJournal->opposing, $amount); diff --git a/app/Mail/RegisteredUser.php b/app/Mail/RegisteredUser.php index eba52d7dfa..01d7f675cd 100644 --- a/app/Mail/RegisteredUser.php +++ b/app/Mail/RegisteredUser.php @@ -1,4 +1,6 @@ $entry) { + $keys = array_keys($expenses); + foreach ($keys as $key) { if ($expenses[$key]['count'] > 1) { $expenses[$key]['average'] = bcdiv($expenses[$key]['sum'], strval($expenses[$key]['count'])); } diff --git a/app/Support/Import/Configuration/Csv/Initial.php b/app/Support/Import/Configuration/Csv/Initial.php index 1c3363eac1..fec13649e9 100644 --- a/app/Support/Import/Configuration/Csv/Initial.php +++ b/app/Support/Import/Configuration/Csv/Initial.php @@ -134,7 +134,8 @@ class Initial implements ConfigurationInterface { // loop specifics. if (isset($data['specifics']) && is_array($data['specifics'])) { - foreach ($data['specifics'] as $name => $enabled) { + $names = array_keys($data['specifics']); + foreach ($names as $name) { // verify their content. $className = sprintf('FireflyIII\Import\Specifics\%s', $name); if (class_exists($className)) { diff --git a/app/Support/Import/Configuration/Csv/Map.php b/app/Support/Import/Configuration/Csv/Map.php index cad59d1dd2..fd038857bd 100644 --- a/app/Support/Import/Configuration/Csv/Map.php +++ b/app/Support/Import/Configuration/Csv/Map.php @@ -90,10 +90,12 @@ class Map implements ConfigurationInterface } } } - foreach ($this->data as $index => $entry) { + $setIndexes = array_keys($this->data); + foreach ($setIndexes as $index) { $this->data[$index]['values'] = array_unique($this->data[$index]['values']); asort($this->data[$index]['values']); } + unset($setIndexes); // save number of rows, thus number of steps, in job: $steps = $rowIndex * 5; @@ -233,8 +235,8 @@ class Map implements ConfigurationInterface { // run specifics here: // and this is the point where the specifix go to work. - foreach ($this->configuration['specifics'] as $name => $enabled) { - + $names = array_keys($this->configuration['specifics']); + foreach ($names as $name) { if (!in_array($name, $this->validSpecifics)) { throw new FireflyException(sprintf('"%s" is not a valid class name', $name)); } diff --git a/app/Support/Import/Configuration/Csv/Roles.php b/app/Support/Import/Configuration/Csv/Roles.php index eb1d49ea3e..f75c82f4bc 100644 --- a/app/Support/Import/Configuration/Csv/Roles.php +++ b/app/Support/Import/Configuration/Csv/Roles.php @@ -228,7 +228,8 @@ class Roles implements ConfigurationInterface */ private function processSpecifics(array $row): array { - foreach ($this->job->configuration['specifics'] as $name => $enabled) { + $names = array_keys($this->configuration['specifics']); + foreach ($names as $name) { /** @var SpecificInterface $specific */ $specific = app('FireflyIII\Import\Specifics\\' . $name); $row = $specific->run($row); diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index ce7b271973..5da8c674cb 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -119,7 +119,7 @@ class Search implements SearchInterface // Filter transactions that match the given triggers. $filtered = $set->filter( - function (Transaction $transaction) use ($words) { + function (Transaction $transaction) { if ($this->matchModifiers($transaction)) { return $transaction; @@ -237,7 +237,7 @@ class Search implements SearchInterface return false; } foreach ($needle as $what) { - if (($pos = strpos($haystack, $what)) !== false) { + if (strpos($haystack, $what) !== false) { return true; } } diff --git a/config/auth.php b/config/auth.php index 9145ce8641..ddf966efc8 100644 --- a/config/auth.php +++ b/config/auth.php @@ -1,4 +1,6 @@ 'This code should be ISO compliant (Google it for your new currency).', -]; \ No newline at end of file +]; diff --git a/resources/lang/en_US/list.php b/resources/lang/en_US/list.php index 91254e401d..c44721b8d5 100644 --- a/resources/lang/en_US/list.php +++ b/resources/lang/en_US/list.php @@ -1,4 +1,6 @@ - \ No newline at end of file + diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 0574e65161..b4cc8b15b2 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -1,4 +1,6 @@