mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	Refactor some duplicated code
This commit is contained in:
		| @@ -31,14 +31,14 @@ class UpdatedJournalEventHandler | ||||
|     /** | ||||
|      * This method will check all the rules when a journal is updated. | ||||
|      * | ||||
|      * @param UpdatedTransactionJournal $event | ||||
|      * @param UpdatedTransactionJournal $updatedJournalEvent | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function processRules(UpdatedTransactionJournal $event):bool | ||||
|     public function processRules(UpdatedTransactionJournal $updatedJournalEvent):bool | ||||
|     { | ||||
|         // get all the user's rule groups, with the rules, order by 'order'. | ||||
|         $journal = $event->journal; | ||||
|         $journal = $updatedJournalEvent->journal; | ||||
|         $groups  = $journal->user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get(); | ||||
|         // | ||||
|         /** @var RuleGroup $group */ | ||||
| @@ -67,13 +67,13 @@ class UpdatedJournalEventHandler | ||||
|     /** | ||||
|      * This method calls a special bill scanner that will check if the updated journal is part of a bill. | ||||
|      * | ||||
|      * @param UpdatedTransactionJournal $event | ||||
|      * @param UpdatedTransactionJournal $updatedJournalEvent | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function scanBills(UpdatedTransactionJournal $event): bool | ||||
|     public function scanBills(UpdatedTransactionJournal $updatedJournalEvent): bool | ||||
|     { | ||||
|         $journal = $event->journal; | ||||
|         $journal = $updatedJournalEvent->journal; | ||||
|         BillScanner::scan($journal); | ||||
|  | ||||
|         return true; | ||||
|   | ||||
| @@ -40,20 +40,7 @@ class ExpandedForm | ||||
|      */ | ||||
|     public function amount(string $name, $value = null, array $options = []): string | ||||
|     { | ||||
|         $label           = $this->label($name, $options); | ||||
|         $options         = $this->expandOptionArray($name, $label, $options); | ||||
|         $classes         = $this->getHolderClasses($name); | ||||
|         $value           = $this->fillFieldValue($name, $value); | ||||
|         $options['step'] = 'any'; | ||||
|         $options['min']  = '0.01'; | ||||
|         $defaultCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency(); | ||||
|         $currencies      = Amt::getAllCurrencies(); | ||||
|         unset($options['currency']); | ||||
|         unset($options['placeholder']); | ||||
|         $html = view('form.amount', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); | ||||
|  | ||||
|         return $html; | ||||
|  | ||||
|         return $this->currencyField($name, 'amount', $value, $options); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -65,20 +52,7 @@ class ExpandedForm | ||||
|      */ | ||||
|     public function amountSmall(string $name, $value = null, array $options = []): string | ||||
|     { | ||||
|         $label           = $this->label($name, $options); | ||||
|         $options         = $this->expandOptionArray($name, $label, $options); | ||||
|         $classes         = $this->getHolderClasses($name); | ||||
|         $value           = $this->fillFieldValue($name, $value); | ||||
|         $options['step'] = 'any'; | ||||
|         $options['min']  = '0.01'; | ||||
|         $defaultCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency(); | ||||
|         $currencies      = Amt::getAllCurrencies(); | ||||
|         unset($options['currency']); | ||||
|         unset($options['placeholder']); | ||||
|         $html = view('form.amount-small', compact('defaultCurrency', 'currencies', 'classes', 'name', 'value', 'options'))->render(); | ||||
|  | ||||
|         return $html; | ||||
|  | ||||
|         return $this->currencyField($name, 'amount-small', $value, $options); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -90,18 +64,7 @@ class ExpandedForm | ||||
|      */ | ||||
|     public function balance(string $name, $value = null, array $options = []): string | ||||
|     { | ||||
|         $label           = $this->label($name, $options); | ||||
|         $options         = $this->expandOptionArray($name, $label, $options); | ||||
|         $classes         = $this->getHolderClasses($name); | ||||
|         $value           = round($this->fillFieldValue($name, $value), 2); | ||||
|         $options['step'] = 'any'; | ||||
|         $defaultCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency(); | ||||
|         $currencies      = Amt::getAllCurrencies(); | ||||
|         unset($options['currency']); | ||||
|         unset($options['placeholder']); | ||||
|         $html = view('form.balance', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); | ||||
|  | ||||
|         return $html; | ||||
|         return $this->currencyField($name, 'balance', $value, $options); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -320,7 +283,6 @@ class ExpandedForm | ||||
|         return $html; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @param       $name | ||||
|      * @param array $list | ||||
| @@ -500,4 +462,29 @@ class ExpandedForm | ||||
|         return strval(trans('form.' . $name)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param string $name | ||||
|      * @param string $view | ||||
|      * @param null   $value | ||||
|      * @param array  $options | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     private function currencyField(string $name, string $view, $value = null, array $options = []): string | ||||
|     { | ||||
|         $label           = $this->label($name, $options); | ||||
|         $options         = $this->expandOptionArray($name, $label, $options); | ||||
|         $classes         = $this->getHolderClasses($name); | ||||
|         $value           = $this->fillFieldValue($name, $value); | ||||
|         $options['step'] = 'any'; | ||||
|         $options['min']  = '0.01'; | ||||
|         $defaultCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency(); | ||||
|         $currencies      = Amt::getAllCurrencies(); | ||||
|         unset($options['currency']); | ||||
|         unset($options['placeholder']); | ||||
|         $html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); | ||||
|  | ||||
|         return $html; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user