Skip to content

Firefly III: a personal finances manager

Code clean up. [skip ci]

James Coledfbe6e5b6e7a
diff --git a/_development/phpmd/phpmd.xml b/_development/phpmd/phpmd.xml
index eee86d6582..b8b5db0e92 100644
--- a/_development/phpmd/phpmd.xml
+++ b/_development/phpmd/phpmd.xml
@@ -1,36 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+command line:
+
+phpmd app html ./_development/phpmd/phpmd.xml > ./public/result.html
+
+-->
<ruleset name="pcsg-generated-ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
- <description>Created with the PHP Coding Standard Generator. http://edorian.github.com/php-coding-standard-generator/
- </description>
+ <description>Bla bla</description>
+
+ <!-- Import the entire controversial code rule set, except one -->
+ <rule ref="rulesets/controversial.xml">
+ <exclude name="CamelCasePropertyName" />
+ </rule>
+
+ <!-- clean code -->
+ <!-- <rule ref="rulesets/cleancode.xml" /> -->
+ <rule ref="rulesets/codesize.xml" />
+ <rule ref="rulesets/design.xml" />
+ <rule ref="rulesets/naming.xml" />
+ <rule ref="rulesets/unusedcode.xml" />
+
+ <!-- clean code static calling rule can be a little more lax: -->
+ <rule ref="rulesets/cleancode.xml">
+ <exclude name="StaticAccess" />
+ </rule>
+
+
+ <!-- report level 5 for cyclomatic complexity -->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
- <properties>
- <property name="reportLevel" value="5"/>
- </properties>
+ <properties>
+ <property name="reportLevel" value="5"/>
+ </properties>
</rule>
<rule ref="rulesets/codesize.xml/NPathComplexity">
- <properties>
- <property name="minimum" value="128"/>
- </properties>
+ <properties>
+ <property name="minimum" value="128"/>
+ </properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
- <properties>
- <property name="minimum" value="40"/>
- </properties>
+ <properties>
+ <property name="minimum" value="40"/>
+ </properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList">
- <properties>
- <property name="minimum" value="5"/>
- </properties>
+ <properties>
+ <property name="minimum" value="5"/>
+ </properties>
</rule>
-
- <!-- Import rule set and exclude rules -->
- <rule ref="rulesets/controversial.xml">
- <exclude name="CamelCasePropertyName" />
- </rule>
-
-
-</ruleset>
+</ruleset>
\ No newline at end of file
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index bd2376f485..2ac5b06021 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -61,7 +61,6 @@ class Kernel extends ConsoleKernel
*
* @return void
*
- * @SuppressWarnings(PHPMD.UnusedFormalParameters)
*/
protected function schedule(Schedule $schedule)
{
diff --git a/app/Export/ConfigurationFile.php b/app/Export/ConfigurationFile.php
index 706b2550d7..46a22c6e8d 100644
--- a/app/Export/ConfigurationFile.php
+++ b/app/Export/ConfigurationFile.php
@@ -10,6 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Export;
+use FireflyIII\Export\Entry\Entry;
use FireflyIII\Models\ExportJob;
use Log;
use Storage;
diff --git a/app/Export/Entry.php b/app/Export/Entry/Entry.php
similarity index 99%
rename from app/Export/Entry.php
rename to app/Export/Entry/Entry.php
index 521f7928e0..d8e1b2203b 100644
--- a/app/Export/Entry.php
+++ b/app/Export/Entry/Entry.php
@@ -8,7 +8,7 @@ declare(strict_types = 1);
* of the MIT license. See the LICENSE file for details.
*/
-namespace FireflyIII\Export;
+namespace FireflyIII\Export\Entry;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
@@ -30,7 +30,7 @@ use FireflyIII\Models\TransactionJournal;
*
* Class Entry
*
- * @package FireflyIII\Export
+ * @package FireflyIII\Export\Entry
*/
class Entry
{
diff --git a/app/Export/Exporter/CsvExporter.php b/app/Export/Exporter/CsvExporter.php
index 8b8421d766..ca095951bb 100644
--- a/app/Export/Exporter/CsvExporter.php
+++ b/app/Export/Exporter/CsvExporter.php
@@ -10,7 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Export\Exporter;
-use FireflyIII\Export\Entry;
+use FireflyIII\Export\Entry\Entry;
use FireflyIII\Models\ExportJob;
use League\Csv\Writer;
use SplFileObject;
diff --git a/app/Export/Processor.php b/app/Export/Processor.php
index a42edbdd7c..46757891b8 100644
--- a/app/Export/Processor.php
+++ b/app/Export/Processor.php
@@ -13,6 +13,7 @@ namespace FireflyIII\Export;
use Auth;
use Config;
use FireflyIII\Exceptions\FireflyException;
+use FireflyIII\Export\Entry\Entry;
use FireflyIII\Models\ExportJob;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalCollector;
diff --git a/app/Helpers/Report/BalanceReportHelper.php b/app/Helpers/Report/BalanceReportHelper.php
index 1d23fbed31..9d919b97ba 100644
--- a/app/Helpers/Report/BalanceReportHelper.php
+++ b/app/Helpers/Report/BalanceReportHelper.php
@@ -178,7 +178,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
* @param Carbon $start
* @param Carbon $end
*
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ *
*
* @return BalanceLine
*/
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 07c0728fee..ff32d20343 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -232,7 +232,6 @@ class BudgetController extends Controller
* @param Collection $accounts
* @param Collection $budgets
*
- * @SuppressWarnings(PHPMD.ExcessiveParameterList) // need all parameters
*
* @return \Illuminate\Http\JsonResponse
*/
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index cdb10237d6..7f94bb0c4c 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -49,8 +49,6 @@ class CategoryController extends Controller
* @param SCRI $repository
* @param Category $category
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- *
* @return \Symfony\Component\HttpFoundation\Response
*/
public function all(SCRI $repository, Category $category)
@@ -115,10 +113,6 @@ class CategoryController extends Controller
* @param Carbon $end
* @param Collection $accounts
*
- * @SuppressWarnings(PHPMD.ExcessiveParameterList) // cant avoid it.
- * @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // it's long but ok.
- *
* @return \Illuminate\Http\JsonResponse
*/
public function earnedInPeriod(CRI $repository, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
@@ -307,8 +301,6 @@ class CategoryController extends Controller
* @param Carbon $end
* @param Collection $accounts
*
- * @SuppressWarnings(PHPMD.ExcessiveParameterList) // need all parameters
- * @SuppressWarnings(PHPMD.ExcessuveMethodLength) // need the length
*
* @return \Illuminate\Http\JsonResponse
*/
diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php
index 8bcff1ec36..1a3daad4de 100644
--- a/app/Http/Controllers/Chart/ReportController.php
+++ b/app/Http/Controllers/Chart/ReportController.php
@@ -88,7 +88,6 @@ class ReportController extends Controller
* @param Carbon $end
* @param Collection $accounts
*
- * @SuppressWarnings(PHPMD.ExcessiveParameterList) // cant avoid it.
*
* @return \Illuminate\Http\JsonResponse
*/
diff --git a/app/Http/Controllers/CsvController.php b/app/Http/Controllers/CsvController.php
index 3c86b55471..cec84760f3 100644
--- a/app/Http/Controllers/CsvController.php
+++ b/app/Http/Controllers/CsvController.php
@@ -337,7 +337,6 @@ class CsvController extends Controller
*
* STEP SIX
*
- * @SuppressWarnings(PHPMD.CyclomaticComplexity) it's 6, but it's allright.
*
* @return \Illuminate\Http\RedirectResponse
*/
@@ -383,9 +382,6 @@ class CsvController extends Controller
*
* STEP TWO
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // need the length.
- * @SuppressWarnings(PHPMD.CyclomaticComplexity) // its exactly 5, its ok
- *
* @param Request $request
*
* @return \Illuminate\Http\RedirectResponse
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index c07260159d..597fa5f14f 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -566,8 +566,6 @@ class AccountRepository implements AccountRepositoryInterface
* @param Account $account
* @param array $data
*
- * @SuppressWarnings(PHPMD.CyclomaticComplexity) // need the complexity.
- *
* @return Account
*/
public function update(Account $account, array $data): Account
diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php
index da1b34abed..befbdb7b29 100644
--- a/app/Repositories/Budget/BudgetRepository.php
+++ b/app/Repositories/Budget/BudgetRepository.php
@@ -310,8 +310,6 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
* @param Carbon $start
* @param Carbon $end
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // it's a query.
- *
* @return array
*/
public function getBudgetsAndExpensesPerYear(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array
diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php
index 8c72b8c490..fa86ab461e 100644
--- a/app/Repositories/Journal/JournalRepository.php
+++ b/app/Repositories/Journal/JournalRepository.php
@@ -388,7 +388,6 @@ class JournalRepository implements JournalRepositoryInterface
*
* @return array
* @throws FireflyException
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function storeAccounts(TransactionType $type, array $data): array
{
diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php
index 0dadc08733..c376c755e6 100644
--- a/app/Repositories/Tag/TagRepository.php
+++ b/app/Repositories/Tag/TagRepository.php
@@ -36,8 +36,6 @@ class TagRepository implements TagRepositoryInterface
* @param TransactionJournal $journal
* @param Tag $tag
*
- * @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
- *
* @return bool
*/
public function connect(TransactionJournal $journal, Tag $tag): bool
@@ -139,8 +137,6 @@ class TagRepository implements TagRepositoryInterface
* @param TransactionJournal $journal
* @param Tag $tag
*
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- *
* @return bool
*/
protected function connectAdvancePayment(TransactionJournal $journal, Tag $tag): bool
@@ -222,7 +218,6 @@ class TagRepository implements TagRepositoryInterface
* @param TransactionJournal $journal
* @param Tag $tag
*
- * @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's complex but nothing can be done.
*
* @return bool
*/
diff --git a/app/Support/Migration/TestData.php b/app/Support/Migration/TestData.php
index b79ef52e2c..0f707131f0 100644
--- a/app/Support/Migration/TestData.php
+++ b/app/Support/Migration/TestData.php
@@ -237,7 +237,6 @@ class TestData
* @param Carbon $date
*
* @return TransactionJournal
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public static function createCar(User $user, Carbon $date): TransactionJournal
{
@@ -283,7 +282,6 @@ class TestData
*
* @return bool
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public static function createDrinksAndOthers(User $user, Carbon $date): bool
{
@@ -350,7 +348,6 @@ class TestData
*
* @return bool
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public static function createGroceries(User $user, Carbon $date): bool
{
@@ -453,7 +450,6 @@ class TestData
*
* @return bool
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public static function createPiggybanks(User $user): bool
{
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index c11872f66f..337d005e3f 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -38,7 +38,6 @@ class FireflyValidator extends Validator
* @param array $messages
* @param array $customAttributes
*
- * @SuppressWarnings(PHPMD.ExcessiveParameterList) // inherited from Laravel.
*/
public function __construct(TranslatorInterface $translator, array $data, array $rules, array $messages = [], array $customAttributes = [])
{
@@ -50,7 +49,6 @@ class FireflyValidator extends Validator
* @param $value
* @param $parameters
*
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
*/
@@ -92,7 +90,6 @@ class FireflyValidator extends Validator
* @param $attribute
* @param $value
*
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
*/
@@ -214,7 +211,6 @@ class FireflyValidator extends Validator
* @param $value
* @param $parameters
*
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
*/
@@ -279,7 +275,6 @@ class FireflyValidator extends Validator
* @param $value
* @param $parameters
*
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
*/
@@ -310,7 +305,6 @@ class FireflyValidator extends Validator
* @param $value
* @param $parameters
*
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
*/
@@ -342,9 +336,6 @@ class FireflyValidator extends Validator
* @param $value
* @param $parameters
*
- * @SuppressWarnings(PHPMD.UnusedFormalParameter) // cant remove it
- * @SuppressWarnings(PHPMD.CyclomaticComplexity) // its as simple as I can get it.
- *
* @return bool
*/
public function validateUniquePiggyBankForUser($attribute, $value, $parameters): bool