Skip to content

Firefly III: a personal finances manager

Some code cleanup courtesy of PHPStorm.

James Cole820722f44e57
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php
index 1e54fff73b..7913d17568 100755
--- a/app/Exceptions/Handler.php
+++ b/app/Exceptions/Handler.php
@@ -40,7 +40,7 @@ class Handler extends ExceptionHandler
*/
public function report(Exception $e)
{
- return parent::report($e);
+ parent::report($e);
}
/**
diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php
index 37b79fdd7a..41489928db 100644
--- a/app/Http/Controllers/RuleController.php
+++ b/app/Http/Controllers/RuleController.php
@@ -101,44 +101,12 @@ class RuleController extends Controller
// has old input?
if (Input::old()) {
// process old triggers.
- $newIndex = 0;
- foreach (Input::old('rule-trigger') as $index => $entry) {
- $count = ($newIndex + 1);
- $triggerCount++;
- $oldTrigger = $entry;
- $oldValue = Input::old('rule-trigger-value')[$index];
- $oldChecked = isset(Input::old('rule-trigger-stop')[$index]) ? true : false;
- $oldTriggers[] = view(
- 'rules.partials.trigger',
- [
- 'oldTrigger' => $oldTrigger,
- 'oldValue' => $oldValue,
- 'oldChecked' => $oldChecked,
- 'count' => $count,
- ]
- )->render();
- $newIndex++;
- }
+ $oldTriggers = $this->getPreviousTriggers();
+ $triggerCount = count($oldTriggers);
// process old actions
- $newIndex = 0;
- foreach (Input::old('rule-action') as $index => $entry) {
- $count = ($newIndex + 1);
- $actionCount++;
- $oldAction = $entry;
- $oldValue = Input::old('rule-action-value')[$index];
- $oldChecked = isset(Input::old('rule-action-stop')[$index]) ? true : false;
- $oldActions[] = view(
- 'rules.partials.action',
- [
- 'oldTrigger' => $oldAction,
- 'oldValue' => $oldValue,
- 'oldChecked' => $oldChecked,
- 'count' => $count,
- ]
- )->render();
- $newIndex++;
- }
+ $oldActions = $this->getPreviousActions();
+ $actionCount = count($oldActions);
}
$subTitleIcon = 'fa-clone';
@@ -164,107 +132,23 @@ class RuleController extends Controller
*/
public function edit(Rule $rule)
{
-
- // count for current rule's triggers/actions.
- $triggerCount = 0;
- $actionCount = 0;
-
- // collection of those triggers/actions.
- $oldTriggers = [];
- $oldActions = [];
-
// has old input?
if (Input::old()) {
// process old triggers.
- $newIndex = 0;
- foreach (Input::old('rule-trigger') as $index => $entry) {
- $count = ($newIndex + 1);
- $triggerCount++;
- $oldTrigger = $entry;
- $oldValue = Input::old('rule-trigger-value')[$index];
- $oldChecked = isset(Input::old('rule-trigger-stop')[$index]) ? true : false;
- $oldTriggers[] = view(
- 'rules.partials.trigger',
- [
- 'oldTrigger' => $oldTrigger,
- 'oldValue' => $oldValue,
- 'oldChecked' => $oldChecked,
- 'count' => $count,
- ]
- )->render();
- $newIndex++;
- }
+ $oldTriggers = $this->getPreviousTriggers();
+ $triggerCount = count($oldTriggers);
// process old actions
- $newIndex = 0;
- foreach (Input::old('rule-action') as $index => $entry) {
- $count = ($newIndex + 1);
- $actionCount++;
- $oldAction = $entry;
- $oldValue = Input::old('rule-action-value')[$index];
- $oldChecked = isset(Input::old('rule-action-stop')[$index]) ? true : false;
- $oldActions[] = view(
- 'rules.partials.action',
- [
- 'oldTrigger' => $oldAction,
- 'oldValue' => $oldValue,
- 'oldChecked' => $oldChecked,
- 'count' => $count,
- ]
- )->render();
- $newIndex++;
- }
+ $oldActions = $this->getPreviousActions();
+ $actionCount = count($oldActions);
} else {
// get current triggers
- $newIndex = 0;
- /**
- * @var int $index
- * @var RuleTrigger $entry
- */
- foreach ($rule->ruleTriggers as $index => $entry) {
- if ($entry->trigger_type != 'user_action') {
- $count = ($newIndex + 1);
- $triggerCount++;
- $oldTrigger = $entry->trigger_type;
- $oldValue = $entry->trigger_value;
- $oldChecked = $entry->stop_processing;
- $oldTriggers[] = view(
- 'rules.partials.trigger',
- [
- 'oldTrigger' => $oldTrigger,
- 'oldValue' => $oldValue,
- 'oldChecked' => $oldChecked,
- 'count' => $count,
- ]
- )->render();
- $newIndex++;
- }
-
- }
+ $oldTriggers = $this->getCurrentTriggers($rule);
+ $triggerCount = count($oldTriggers);
// get current actions
- $newIndex = 0;
- /**
- * @var int $index
- * @var RuleAction $entry
- */
- foreach ($rule->ruleActions as $index => $entry) {
- $count = ($newIndex + 1);
- $actionCount++;
- $oldAction = $entry->action_type;
- $oldValue = $entry->action_value;
- $oldChecked = $entry->stop_processing;
- $oldActions[] = view(
- 'rules.partials.action',
- [
- 'oldTrigger' => $oldAction,
- 'oldValue' => $oldValue,
- 'oldChecked' => $oldChecked,
- 'count' => $count,
- ]
- )->render();
- $newIndex++;
- }
+ $oldActions = $this->getCurrentActions($rule);
+ $actionCount = count($oldActions);
}
// get rule trigger for update / store-journal:
@@ -283,9 +167,9 @@ class RuleController extends Controller
return view(
'rules.rule.edit', compact(
- 'rule', 'subTitle', 'primaryTrigger',
- 'oldTriggers', 'oldActions', 'triggerCount', 'actionCount'
- )
+ 'rule', 'subTitle', 'primaryTrigger',
+ 'oldTriggers', 'oldActions', 'triggerCount', 'actionCount'
+ )
);
}
@@ -459,5 +343,111 @@ class RuleController extends Controller
}
+ /**
+ * @param Rule $rule
+ */
+ private function getCurrentActions(Rule $rule)
+ {
+ $index = 0;
+ $actions = [];
+
+ /** @var RuleAction $entry */
+ foreach ($rule->ruleActions as $entry) {
+ $count = ($index + 1);
+ $actions[] = view(
+ 'rules.partials.action',
+ [
+ 'oldTrigger' => $entry->action_type,
+ 'oldValue' => $entry->action_value,
+ 'oldChecked' => $entry->stop_processing,
+ 'count' => $count,
+ ]
+ )->render();
+ $index++;
+ }
+
+ return $actions;
+ }
+
+ /**
+ * @param Rule $rule
+ *
+ * @return array
+ */
+ private function getCurrentTriggers(Rule $rule)
+ {
+ $index = 0;
+ $triggers = [];
+
+ /** @var RuleTrigger $entry */
+ foreach ($rule->ruleTriggers as $entry) {
+ if ($entry->trigger_type != 'user_action') {
+ $count = ($index + 1);
+ $triggers[] = view(
+ 'rules.partials.trigger',
+ [
+ 'oldTrigger' => $entry->trigger_type,
+ 'oldValue' => $entry->trigger_value,
+ 'oldChecked' => $entry->stop_processing,
+ 'count' => $count,
+ ]
+ )->render();
+ $index++;
+ }
+ }
+
+ return $triggers;
+ }
+
+ /**
+ * @return array
+ */
+ private function getPreviousActions()
+ {
+ $newIndex = 0;
+ $actions = [];
+ foreach (Input::old('rule-action') as $index => $entry) {
+ $count = ($newIndex + 1);
+ $checked = isset(Input::old('rule-action-stop')[$index]) ? true : false;
+ $actions[] = view(
+ 'rules.partials.action',
+ [
+ 'oldTrigger' => $entry,
+ 'oldValue' => Input::old('rule-action-value')[$index],
+ 'oldChecked' => $checked,
+ 'count' => $count,
+ ]
+ )->render();
+ $newIndex++;
+ }
+
+ return $actions;
+ }
+
+ /**
+ * @return array
+ */
+ private function getPreviousTriggers()
+ {
+ $newIndex = 0;
+ $triggers = [];
+ foreach (Input::old('rule-trigger') as $index => $entry) {
+ $count = ($newIndex + 1);
+ $oldChecked = isset(Input::old('rule-trigger-stop')[$index]) ? true : false;
+ $triggers[] = view(
+ 'rules.partials.trigger',
+ [
+ 'oldTrigger' => $entry,
+ 'oldValue' => Input::old('rule-trigger-value')[$index],
+ 'oldChecked' => $oldChecked,
+ 'count' => $count,
+ ]
+ )->render();
+ $newIndex++;
+ }
+
+ return $triggers;
+ }
+
}
diff --git a/app/Models/Account.php b/app/Models/Account.php
index d381f6b4c1..7545b3b9e1 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\JoinClause;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Watson\Validating\ValidatingTrait;
-
+use Illuminate\Database\Query\Builder;
/**
* FireflyIII\Models\Account
@@ -30,8 +30,8 @@ use Watson\Validating\ValidatingTrait;
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBank[] $piggyBanks
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Transaction[] $transactions
* @property-read \FireflyIII\User $user
- * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account accountTypeIn($types)
- * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account hasMetaValue($name, $value)
+ * @method static Builder|\FireflyIII\Models\Account accountTypeIn($types)
+ * @method static Builder|\FireflyIII\Models\Account hasMetaValue($name, $value)
* @property string $startBalance
* @property string $endBalance
*/
@@ -293,6 +293,11 @@ class Account extends Model
return $this->belongsTo('FireflyIII\User');
}
+ /**
+ * @param Account $value
+ *
+ * @return Account
+ */
public static function routeBinder(Account $value)
{
diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php
index 4d90fc06a1..f57d1d31b5 100644
--- a/app/Models/Attachment.php
+++ b/app/Models/Attachment.php
@@ -175,6 +175,11 @@ class Attachment extends Model
$this->attributes['notes'] = Crypt::encrypt($value);
}
+ /**
+ * @param Attachment $value
+ *
+ * @return Attachment
+ */
public static function routeBinder(Attachment $value)
{
if (Auth::check()) {
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
index 79cf30bbfe..4558cdb4e7 100644
--- a/app/Models/Bill.php
+++ b/app/Models/Bill.php
@@ -28,6 +28,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property boolean $match_encrypted
* @property-read Collection|TransactionJournal[] $transactionjournals
* @property-read User $user
+ * @property Carbon $nextExpectedMatch
+ * @property Carbon $lastFoundMatch
*/
class Bill extends Model
{
@@ -127,6 +129,11 @@ class Bill extends Model
}
+ /**
+ * @param Bill $value
+ *
+ * @return Bill
+ */
public static function routeBinder(Bill $value)
{
if (Auth::check()) {
diff --git a/app/Models/Budget.php b/app/Models/Budget.php
index 4000306a2c..a10bb8926d 100644
--- a/app/Models/Budget.php
+++ b/app/Models/Budget.php
@@ -23,6 +23,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property-read Collection|BudgetLimit[] $budgetlimits
* @property-read Collection|TransactionJournal[] $transactionjournals
* @property-read User $user
+ * @property string $dateFormatted
+ * @property string $budgeted
*/
class Budget extends Model
{
@@ -125,6 +127,11 @@ class Budget extends Model
return $this->belongsTo('FireflyIII\User');
}
+ /**
+ * @param Budget $value
+ *
+ * @return Budget
+ */
public static function routeBinder(Budget $value)
{
if (Auth::check()) {
diff --git a/app/Models/Category.php b/app/Models/Category.php
index b331b5960a..50342d1785 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -112,6 +112,11 @@ class Category extends Model
return $this->belongsTo('FireflyIII\User');
}
+ /**
+ * @param Category $value
+ *
+ * @return Category
+ */
public static function routeBinder(Category $value)
{
if (Auth::check()) {
diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php
index bd91fbf8a6..e4c3d105eb 100644
--- a/app/Models/LimitRepetition.php
+++ b/app/Models/LimitRepetition.php
@@ -47,6 +47,11 @@ class LimitRepetition extends Model
}
+ /**
+ * @param $value
+ *
+ * @return mixed
+ */
public static function routeBinder($value)
{
if (Auth::check()) {
diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php
index c1c7513934..efce246557 100644
--- a/app/Models/PiggyBank.php
+++ b/app/Models/PiggyBank.php
@@ -122,6 +122,11 @@ class PiggyBank extends Model
$this->attributes['targetamount'] = strval(round($value, 2));
}
+ /**
+ * @param PiggyBank $value
+ *
+ * @return PiggyBank
+ */
public static function routeBinder(PiggyBank $value)
{
if (Auth::check()) {
diff --git a/app/Models/Tag.php b/app/Models/Tag.php
index f9aa51a1a0..68868b0da4 100644
--- a/app/Models/Tag.php
+++ b/app/Models/Tag.php
@@ -170,6 +170,11 @@ class Tag extends Model
}
+ /**
+ * @param Tag $value
+ *
+ * @return Tag
+ */
public static function routeBinder(Tag $value)
{
if (Auth::check()) {
diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php
index 168bfb9bf5..6a223428b4 100644
--- a/app/Models/TransactionCurrency.php
+++ b/app/Models/TransactionCurrency.php
@@ -44,6 +44,8 @@ class TransactionCurrency extends Model
/**
* @param TransactionCurrency $currency
+ *
+ * @return TransactionCurrency
*/
public static function routeBinder(TransactionCurrency $currency)
{
diff --git a/app/Repositories/Category/SingleCategoryRepository.php b/app/Repositories/Category/SingleCategoryRepository.php
index 3b52f6c04b..95c41a26fa 100644
--- a/app/Repositories/Category/SingleCategoryRepository.php
+++ b/app/Repositories/Category/SingleCategoryRepository.php
@@ -25,7 +25,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
*/
public function countJournals(Category $category)
{
- return $category->transactionJournals()->count();
+ return $category->transactionjournals()->count();
}
@@ -39,7 +39,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
*/
public function countJournalsInRange(Category $category, Carbon $start, Carbon $end)
{
- return $category->transactionJournals()->before($end)->after($start)->count();
+ return $category->transactionjournals()->before($end)->after($start)->count();
}
/**
diff --git a/app/Repositories/RuleGroup/RuleGroupRepository.php b/app/Repositories/RuleGroup/RuleGroupRepository.php
index 171468a6ac..4593d1d1fe 100644
--- a/app/Repositories/RuleGroup/RuleGroupRepository.php
+++ b/app/Repositories/RuleGroup/RuleGroupRepository.php
@@ -8,6 +8,11 @@ use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use Illuminate\Support\Collection;
+/**
+ * Class RuleGroupRepository
+ *
+ * @package FireflyIII\Repositories\RuleGroup
+ */
class RuleGroupRepository implements RuleGroupRepositoryInterface
{
/**
diff --git a/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php b/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php
index 060f5c5b17..f1dd3f317b 100644
--- a/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php
+++ b/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php
@@ -52,6 +52,8 @@ interface RuleGroupRepositoryInterface
public function resetRuleGroupOrder();
/**
+ * @param RuleGroup $ruleGroup
+ *
* @return bool
*/
public function resetRulesInGroupOrder(RuleGroup $ruleGroup);
diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php
index aa604b2859..391e78f21d 100644
--- a/app/Repositories/Shared/ComponentRepository.php
+++ b/app/Repositories/Shared/ComponentRepository.php
@@ -35,7 +35,7 @@ class ComponentRepository
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->whereIn('accounts.id', $ids)
->after($start)
- ->first([DB::Raw('SUM(`transactions`.`amount`) as `journalAmount`')]);
+ ->first([DB::raw('SUM(`transactions`.`amount`) as `journalAmount`')]);
$amount = $entry->journalAmount;
return $amount;
diff --git a/app/Rules/Actions/ClearBudget.php b/app/Rules/Actions/ClearBudget.php
index f74b633537..e1558afdcd 100644
--- a/app/Rules/Actions/ClearBudget.php
+++ b/app/Rules/Actions/ClearBudget.php
@@ -10,11 +10,8 @@
namespace FireflyIII\Rules\Actions;
-use Auth;
-use FireflyIII\Models\Category;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
-use Log;
/**
* Class ClearBudget
diff --git a/app/Rules/Actions/ClearCategory.php b/app/Rules/Actions/ClearCategory.php
index 107f2241e0..76569523b8 100644
--- a/app/Rules/Actions/ClearCategory.php
+++ b/app/Rules/Actions/ClearCategory.php
@@ -10,11 +10,8 @@
namespace FireflyIII\Rules\Actions;
-use Auth;
-use FireflyIII\Models\Category;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
-use Log;
/**
* Class ClearCategory
diff --git a/app/Rules/Processor.php b/app/Rules/Processor.php
index 45692c8603..49c7bd202b 100644
--- a/app/Rules/Processor.php
+++ b/app/Rules/Processor.php
@@ -39,6 +39,9 @@ class Processor
/**
* Processor constructor.
+ *
+ * @param Rule $rule
+ * @param TransactionJournal $journal
*/
public function __construct(Rule $rule, TransactionJournal $journal)
{
diff --git a/app/Support/Amount.php b/app/Support/Amount.php
index 6298bc61f6..00a13f85bd 100644
--- a/app/Support/Amount.php
+++ b/app/Support/Amount.php
@@ -136,7 +136,7 @@ class Amount
{
$currency = $transaction->transactionJournal->transactionCurrency;
- return $this->formatAnything($currency, $transaction->amount);
+ return $this->formatAnything($currency, $transaction->amount, $coloured);
}
/**
diff --git a/app/Support/Binder/CategoryList.php b/app/Support/Binder/CategoryList.php
index ff787b85b5..4f39ca6e2f 100644
--- a/app/Support/Binder/CategoryList.php
+++ b/app/Support/Binder/CategoryList.php
@@ -19,7 +19,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @package FireflyIII\Support\Binder
*/
class CategoryList implements BinderInterface
-
{
/**
diff --git a/app/Support/Binder/Date.php b/app/Support/Binder/Date.php
index 2aa4fe26de..db75e43d18 100644
--- a/app/Support/Binder/Date.php
+++ b/app/Support/Binder/Date.php
@@ -9,6 +9,7 @@
namespace FireflyIII\Support\Binder;
+use Auth;
use Carbon\Carbon;
use Exception;
use Log;
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index 216d5528e4..647b75f138 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -28,7 +28,7 @@ class Steam
$set = Auth::user()->transactions()
->whereIn('account_id', $accounts)
->groupBy('account_id')
- ->get(['transactions.account_id', DB::Raw('MAX(`transaction_journals`.`date`) as `max_date`')]);
+ ->get(['transactions.account_id', DB::raw('MAX(`transaction_journals`.`date`) as `max_date`')]);
foreach ($set as $entry) {
$list[intval($entry->account_id)] = new Carbon($entry->max_date);
diff --git a/app/Support/Twig/Rule.php b/app/Support/Twig/Rule.php
index 8cd9ef6779..6b0a9e181d 100644
--- a/app/Support/Twig/Rule.php
+++ b/app/Support/Twig/Rule.php
@@ -8,18 +8,18 @@ use Twig_SimpleFunction;
/**
* Class Rule
+ *
* @package FireflyIII\Support\Twig
*/
class Rule extends Twig_Extension
{
+
/**
- *
+ * @return Twig_SimpleFunction
*/
- public function getFunctions()
+ public function allJournalTriggers()
{
- $functions = [];
-
- $functions[] = new Twig_SimpleFunction(
+ return new Twig_SimpleFunction(
'allJournalTriggers', function () {
return [
'store-journal' => trans('firefly.rule_trigger_store_journal'),
@@ -27,8 +27,14 @@ class Rule extends Twig_Extension
];
}
);
+ }
- $functions[] = new Twig_SimpleFunction(
+ /**
+ * @return Twig_SimpleFunction
+ */
+ public function allRuleTriggers()
+ {
+ return new Twig_SimpleFunction(
'allRuleTriggers', function () {
$ruleTriggers = array_keys(Config::get('firefly.rule-triggers'));
$possibleTriggers = [];
@@ -44,7 +50,15 @@ class Rule extends Twig_Extension
);
- $functions[] = new Twig_SimpleFunction('allRuleActions', function () {
+ }
+
+ /**
+ * @return Twig_SimpleFunction
+ */
+ public function allActionTriggers()
+ {
+ return new Twig_SimpleFunction(
+ 'allRuleActions', function () {
// array of valid values for actions
$ruleActions = array_keys(Config::get('firefly.rule-actions'));
$possibleActions = [];
@@ -54,9 +68,21 @@ class Rule extends Twig_Extension
unset($key, $ruleActions);
return $possibleActions;
- });
+ }
+ );
+ }
+
+ /**
+ * @return array
+ */
+ public function getFunctions()
+ {
+ return [
+ $this->allJournalTriggers(),
+ $this->allRuleTriggers(),
+ $this->allActionTriggers(),
+ ];
- return $functions;
}
/**
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index 6ca1067c65..728881a19d 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -40,12 +40,10 @@ class FireflyValidator extends Validator
/**
* @param $attribute
- * @param $value
- * @param $parameters
*
* @return bool
*/
- public function validateRuleTriggerValue($attribute, $value, $parameters)
+ public function validateRuleTriggerValue($attribute)
{
// get the index from a string like "rule-trigger-value.2".
$parts = explode('.', $attribute);
@@ -76,12 +74,10 @@ class FireflyValidator extends Validator
/**
* @param $attribute
- * @param $value
- * @param $parameters
*
* @return bool
*/
- public function validateRuleActionValue($attribute, $value, $parameters)
+ public function validateRuleActionValue($attribute)
{
// get the index from a string like "rule-action-value.2".
$parts = explode('.', $attribute);