Some cleaning up courtesy of PHPStorm.

This commit is contained in:
James Cole
2016-01-15 19:37:09 +01:00
parent dcbfe90cf7
commit 4e3c59a2da
8 changed files with 40 additions and 37 deletions

View File

@@ -380,6 +380,9 @@ class CategoryController extends Controller
* @param Carbon $end * @param Carbon $end
* @param Collection $accounts * @param Collection $accounts
* *
* @SuppressWarnings(PHPMD.ExcessiveParameterList) // need all parameters
* @SuppressWarnings(PHPMD.ExcessuveMethodLength) // need the length
*
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function spentInPeriod(CRI $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts) public function spentInPeriod(CRI $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts)
@@ -405,17 +408,14 @@ class CategoryController extends Controller
while ($start < $end) { // filter the set: while ($start < $end) { // filter the set:
$row = [clone $start]; $row = [clone $start];
// get possibly relevant entries from the big $set $currentSet = $set->filter(// get possibly relevant entries from the big $set
$currentSet = $set->filter(
function (Category $category) use ($start) { function (Category $category) use ($start) {
return $category->dateFormatted == $start->format("Y-m"); return $category->dateFormatted == $start->format("Y-m");
} }
); );
// check for each category if its in the current set.
/** @var Category $category */ /** @var Category $category */
foreach ($categories as $category) { foreach ($categories as $category) {// check for each category if its in the current set.
// if its in there, use the value. $entry = $currentSet->filter(// if its in there, use the value.
$entry = $currentSet->filter(
function (Category $cat) use ($category) { function (Category $cat) use ($category) {
return ($cat->id == $category->id); return ($cat->id == $category->id);
} }

View File

@@ -41,7 +41,7 @@ class ReportController extends Controller
* @param Carbon $end * @param Carbon $end
* @param Collection $accounts * @param Collection $accounts
* *
* @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.ExcessiveParameterList) // cant avoid it.
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */

View File

@@ -375,6 +375,9 @@ class CsvController extends Controller
* *
* STEP TWO * STEP TWO
* *
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // need the length.
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // its exactly 5, its ok
*
* @param Request $request * @param Request $request
* *
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse

View File

@@ -21,6 +21,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property boolean $encrypted * @property boolean $encrypted
* @property-read Collection|TransactionJournal[] $transactionjournals * @property-read Collection|TransactionJournal[] $transactionjournals
* @property-read User $user * @property-read User $user
* @property string $dateFormatted
*/ */
class Category extends Model class Category extends Model
{ {

View File

@@ -111,7 +111,7 @@ class AccountRepository implements AccountRepositoryInterface
'accounts.*', 'accounts.*',
'ccType.data as ccType', 'ccType.data as ccType',
'accountRole.data as accountRole', '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 Account $account
* @param array $data * @param array $data
* *
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // need the complexity.
*
* @return Account * @return Account
*/ */
public function update(Account $account, array $data) public function update(Account $account, array $data)
@@ -390,15 +392,10 @@ class AccountRepository implements AccountRepositoryInterface
$this->updateMetadata($account, $data); $this->updateMetadata($account, $data);
$openingBalance = $this->openingBalanceTransaction($account); $openingBalance = $this->openingBalanceTransaction($account);
// if has openingbalance?
if ($data['openingBalance'] != 0) { if ($data['openingBalance'] != 0) {
// if opening balance, do an update:
if ($openingBalance) { if ($openingBalance) {
// update existing opening balance.
$this->updateInitialBalance($account, $openingBalance, $data); $this->updateInitialBalance($account, $openingBalance, $data);
} else { } else {
// create new opening balance.
$type = $data['openingBalance'] < 0 ? 'expense' : 'revenue'; $type = $data['openingBalance'] < 0 ? 'expense' : 'revenue';
$opposingData = [ $opposingData = [
'user' => $data['user'], 'user' => $data['user'],
@@ -480,7 +477,7 @@ class AccountRepository implements AccountRepositoryInterface
[ [
'account_id' => $account->id, 'account_id' => $account->id,
'name' => $field, 'name' => $field,
'data' => $data[$field] 'data' => $data[$field],
] ]
); );
$metaData->save(); $metaData->save();
@@ -509,7 +506,7 @@ class AccountRepository implements AccountRepositoryInterface
'description' => 'Initial balance for "' . $account->name . '"', 'description' => 'Initial balance for "' . $account->name . '"',
'completed' => true, 'completed' => true,
'date' => $data['openingBalanceDate'], 'date' => $data['openingBalanceDate'],
'encrypted' => true 'encrypted' => true,
] ]
); );
@@ -547,23 +544,23 @@ class AccountRepository implements AccountRepositoryInterface
foreach ($validFields as $field) { foreach ($validFields as $field) {
$entry = $account->accountMeta()->where('name', $field)->first(); $entry = $account->accountMeta()->where('name', $field)->first();
if (isset($data[$field])) {
// update if new data is present: // update if new data is present:
if ($entry && isset($data[$field])) { if (!is_null($entry)) {
$entry->data = $data[$field]; $entry->data = $data[$field];
$entry->save(); $entry->save();
} } else {
// no entry but data present?
if (!$entry && isset($data[$field])) {
$metaData = new AccountMeta( $metaData = new AccountMeta(
[ [
'account_id' => $account->id, 'account_id' => $account->id,
'name' => $field, 'name' => $field,
'data' => $data[$field] 'data' => $data[$field],
] ]
); );
$metaData->save(); $metaData->save();
} }
} }
}
} }

View File

@@ -575,6 +575,8 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* *
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // it's a query.
*
* @return array * @return array
*/ */
public function getBudgetsAndExpensesPerYear(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end) public function getBudgetsAndExpensesPerYear(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end)

View File

@@ -365,6 +365,8 @@ class TagRepository implements TagRepositoryInterface
* @param TransactionJournal $journal * @param TransactionJournal $journal
* @param Tag $tag * @param Tag $tag
* *
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's complex but nothing can be done.
*
* @return bool * @return bool
*/ */
protected function matchAll(TransactionJournal $journal, Tag $tag) protected function matchAll(TransactionJournal $journal, Tag $tag)

View File

@@ -381,17 +381,16 @@ class FireflyValidator extends Validator
* @param $value * @param $value
* @param $parameters * @param $parameters
* *
* @SuppressWarnings(PHPMD.UnusedFormalParameter) * @SuppressWarnings(PHPMD.UnusedFormalParameter) // cant remove it
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // its as simple as I can get it.
* *
* @return bool * @return bool
*/ */
public function validateUniquePiggyBankForUser($attribute, $value, $parameters) public function validateUniquePiggyBankForUser($attribute, $value, $parameters)
{ {
$exclude = isset($parameters[0]) ? $parameters[0] : null; $exclude = isset($parameters[0]) ? $parameters[0] : null;
$query = DB::table('piggy_banks'); $query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
$query->whereNull('piggy_banks.deleted_at'); ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id);
$query->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id');
$query->where('accounts.user_id', Auth::user()->id);
if (!is_null($exclude)) { if (!is_null($exclude)) {
$query->where('piggy_banks.id', '!=', $exclude); $query->where('piggy_banks.id', '!=', $exclude);
} }
@@ -406,7 +405,6 @@ class FireflyValidator extends Validator
} }
return true; return true;
} }
/** /**