Skip to content

Firefly III: a personal finances manager

Some cleaning up courtesy of PHPStorm.

James Cole4e3c59a2da97
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index 199319e62b..f2a0623118 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -380,6 +380,9 @@ 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
*/
public function spentInPeriod(CRI $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts)
@@ -404,18 +407,15 @@ class CategoryController extends Controller
$entries = new Collection;
while ($start < $end) { // filter the set:
- $row = [clone $start];
- // get possibly relevant entries from the big $set
- $currentSet = $set->filter(
+ $row = [clone $start];
+ $currentSet = $set->filter(// get possibly relevant entries from the big $set
function (Category $category) use ($start) {
return $category->dateFormatted == $start->format("Y-m");
}
);
- // check for each category if its in the current set.
/** @var Category $category */
- foreach ($categories as $category) {
- // if its in there, use the value.
- $entry = $currentSet->filter(
+ foreach ($categories as $category) {// check for each category if its in the current set.
+ $entry = $currentSet->filter(// if its in there, use the value.
function (Category $cat) use ($category) {
return ($cat->id == $category->id);
}
diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php
index 97bb03be11..3ffb128691 100644
--- a/app/Http/Controllers/Chart/ReportController.php
+++ b/app/Http/Controllers/Chart/ReportController.php
@@ -41,7 +41,7 @@ class ReportController extends Controller
* @param Carbon $end
* @param Collection $accounts
*
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
+ * @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 0006d6cfa5..f041562c15 100644
--- a/app/Http/Controllers/CsvController.php
+++ b/app/Http/Controllers/CsvController.php
@@ -375,6 +375,9 @@ 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/Models/Category.php b/app/Models/Category.php
index 50342d1785..037b32af0c 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -21,6 +21,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property boolean $encrypted
* @property-read Collection|TransactionJournal[] $transactionjournals
* @property-read User $user
+ * @property string $dateFormatted
*/
class Category extends Model
{
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index 0dd0573754..94d4ae59e4 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -111,7 +111,7 @@ class AccountRepository implements AccountRepositoryInterface
'accounts.*',
'ccType.data as ccType',
'accountRole.data as accountRole',
- DB::Raw('SUM(`transactions`.`amount`) AS `balance`')
+ DB::Raw('SUM(`transactions`.`amount`) AS `balance`'),
]
);
@@ -377,6 +377,8 @@ 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)
@@ -390,15 +392,10 @@ class AccountRepository implements AccountRepositoryInterface
$this->updateMetadata($account, $data);
$openingBalance = $this->openingBalanceTransaction($account);
-
- // if has openingbalance?
if ($data['openingBalance'] != 0) {
- // if opening balance, do an update:
if ($openingBalance) {
- // update existing opening balance.
$this->updateInitialBalance($account, $openingBalance, $data);
} else {
- // create new opening balance.
$type = $data['openingBalance'] < 0 ? 'expense' : 'revenue';
$opposingData = [
'user' => $data['user'],
@@ -480,7 +477,7 @@ class AccountRepository implements AccountRepositoryInterface
[
'account_id' => $account->id,
'name' => $field,
- 'data' => $data[$field]
+ 'data' => $data[$field],
]
);
$metaData->save();
@@ -509,7 +506,7 @@ class AccountRepository implements AccountRepositoryInterface
'description' => 'Initial balance for "' . $account->name . '"',
'completed' => true,
'date' => $data['openingBalanceDate'],
- 'encrypted' => true
+ 'encrypted' => true,
]
);
@@ -547,21 +544,21 @@ class AccountRepository implements AccountRepositoryInterface
foreach ($validFields as $field) {
$entry = $account->accountMeta()->where('name', $field)->first();
- // update if new data is present:
- if ($entry && isset($data[$field])) {
- $entry->data = $data[$field];
- $entry->save();
- }
- // no entry but data present?
- if (!$entry && isset($data[$field])) {
- $metaData = new AccountMeta(
- [
- 'account_id' => $account->id,
- 'name' => $field,
- 'data' => $data[$field]
- ]
- );
- $metaData->save();
+ if (isset($data[$field])) {
+ // update if new data is present:
+ if (!is_null($entry)) {
+ $entry->data = $data[$field];
+ $entry->save();
+ } else {
+ $metaData = new AccountMeta(
+ [
+ 'account_id' => $account->id,
+ 'name' => $field,
+ 'data' => $data[$field],
+ ]
+ );
+ $metaData->save();
+ }
}
}
diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php
index 75c9ca247f..70d9e71b4b 100644
--- a/app/Repositories/Budget/BudgetRepository.php
+++ b/app/Repositories/Budget/BudgetRepository.php
@@ -575,6 +575,8 @@ 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)
diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php
index f13f5bcc92..410ea191de 100644
--- a/app/Repositories/Tag/TagRepository.php
+++ b/app/Repositories/Tag/TagRepository.php
@@ -365,6 +365,8 @@ class TagRepository implements TagRepositoryInterface
* @param TransactionJournal $journal
* @param Tag $tag
*
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's complex but nothing can be done.
+ *
* @return bool
*/
protected function matchAll(TransactionJournal $journal, Tag $tag)
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index 90e65fb36a..d386645292 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -381,17 +381,16 @@ class FireflyValidator extends Validator
* @param $value
* @param $parameters
*
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ * @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)
{
$exclude = isset($parameters[0]) ? $parameters[0] : null;
- $query = DB::table('piggy_banks');
- $query->whereNull('piggy_banks.deleted_at');
- $query->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id');
- $query->where('accounts.user_id', Auth::user()->id);
+ $query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
+ ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id);
if (!is_null($exclude)) {
$query->where('piggy_banks.id', '!=', $exclude);
}
@@ -406,7 +405,6 @@ class FireflyValidator extends Validator
}
return true;
-
}
/**