Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Simplify method.
James Colec90b26c18131
diff --git a/app/Api/V1/Requests/TransactionUpdateRequest.php b/app/Api/V1/Requests/TransactionUpdateRequest.phpindex 045ff11a3e..36531a269e 100644--- a/app/Api/V1/Requests/TransactionUpdateRequest.php+++ b/app/Api/V1/Requests/TransactionUpdateRequest.php@@ -278,60 +278,132 @@ class TransactionUpdateRequest extends Request}/**- * Get transaction data.+ * @param array $current+ * @param array $transaction** @return array*/- private function getTransactionData(): array+ private function getArrayData(array $current, array $transaction): array{- Log::debug('Now in getTransactionData()');- $return = [];- /**- * @var int $index- * @var array $transaction- */- foreach ($this->get('transactions') as $index => $transaction) {- // default response is to update nothing in the transaction:- $current = [];-- // for each field, add it to the array if a reference is present in the request:- foreach ($this->integerFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]);- }+ foreach ($this->arrayFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);}+ }++ return $current;+ }- foreach ($this->stringFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]);- }+ /**+ * @param array $current+ * @param array $transaction+ *+ * @return array+ */+ private function getBooleanData(array $current, array $transaction): array+ {+ foreach ($this->booleanFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]);}+ }- foreach ($this->textareaFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]);- }+ return $current;+ }++ /**+ * @param array $current+ * @param array $transaction+ *+ * @return array+ */+ private function getDateData(array $current, array $transaction): array+ {+ foreach ($this->dateFields as $fieldName) {+ Log::debug(sprintf('Now at date field %s', $fieldName));+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);+ Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName]));}+ }++ return $current;+ }- foreach ($this->dateFields as $fieldName) {- Log::debug(sprintf('Now at date field %s', $fieldName));- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);- Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName]));- }+ /**+ * For each field, add it to the array if a reference is present in the request:+ *+ * @param array $current+ *+ * @return array+ */+ private function getIntegerData(array $current, array $transaction): array+ {+ foreach ($this->integerFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]);}+ }++ return $current;+ }- foreach ($this->booleanFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]);- }+ /**+ * @param array $current+ * @param array $transaction+ *+ * @return array+ */+ private function getNlStringData(array $current, array $transaction): array+ {+ foreach ($this->textareaFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]);}+ }- foreach ($this->arrayFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);- }+ return $current;+ }++ /**+ * @param array $current+ * @param array $transaction+ *+ * @return array+ */+ private function getStringData(array $current, array $transaction): array+ {+ foreach ($this->stringFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]);}+ }++ return $current;+ }++ /**+ * Get transaction data.+ *+ * @return array+ */+ private function getTransactionData(): array+ {+ Log::debug('Now in getTransactionData()');+ $return = [];+ /**+ * @var int $index+ * @var array $transaction+ */+ foreach ($this->get('transactions') as $index => $transaction) {+ // default response is to update nothing in the transaction:+ $current = [];+ $current = $this->getIntegerData($current, $transaction);+ $current = $this->getStringData($current, $transaction);+ $current = $this->getNlStringData($current, $transaction);+ $current = $this->getDateData($current, $transaction);+ $current = $this->getBooleanData($current, $transaction);+ $current = $this->getArrayData($current, $transaction);$return[] = $current;}