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:
		| @@ -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