Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Refactor basic methods to trait
James Coleaa0758cd2b39
diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.phpindex b9e429ab91..1b393e7291 100644--- a/app/Http/Controllers/Account/IndexController.php+++ b/app/Http/Controllers/Account/IndexController.php@@ -27,6 +27,7 @@ use Carbon\Carbon;use FireflyIII\Http\Controllers\Controller;use FireflyIII\Models\Account;use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Support\Http\Controllers\BasicDataSupport;use Illuminate\Http\Request;use Illuminate\Pagination\LengthAwarePaginator;@@ -36,6 +37,7 @@ use Illuminate\Pagination\LengthAwarePaginator;*/class IndexController extends Controller{+ use BasicDataSupport;/** @var AccountRepositoryInterface The account repository */private $repository;@@ -119,23 +121,7 @@ class IndexController extends Controller}- /**- * Find the ID in a given array. Return '0' of not there (amount).- *- * @param array $array- * @param int $entryId- *- * @return null|mixed- */- protected function isInArray(array $array, int $entryId) // helper for data (math, calculations)- {- $result = '0';- if (isset($array[$entryId])) {- $result = $array[$entryId];- }- return $result;- }}diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.phpindex aea82b8330..c68d8d6a23 100644--- a/app/Http/Controllers/Chart/ReportController.php+++ b/app/Http/Controllers/Chart/ReportController.php@@ -27,6 +27,7 @@ use FireflyIII\Generator\Chart\Basic\GeneratorInterface;use FireflyIII\Http\Controllers\Controller;use FireflyIII\Repositories\Account\AccountTaskerInterface;use FireflyIII\Support\CacheProperties;+use FireflyIII\Support\Http\Controllers\BasicDataSupport;use Illuminate\Http\JsonResponse;use Illuminate\Support\Collection;use Log;@@ -36,6 +37,7 @@ use Log;*/class ReportController extends Controller{+ use BasicDataSupport;/** @var GeneratorInterface Chart generation methods. */protected $generator;@@ -219,23 +221,6 @@ class ReportController extends Controllerreturn response()->json($data);}- /**- * Sum up an array.- *- * @param array $array- *- * @return string- */- protected function arraySum(array $array): string // filter + group data- {- $sum = '0';- foreach ($array as $entry) {- $sum = bcadd($sum, $entry);- }-- return $sum;- }-/*** Collects the incomes and expenses for the given periods, grouped per month. Will cache its results.*diff --git a/app/Support/Http/Controllers/BasicDataSupport.php b/app/Support/Http/Controllers/BasicDataSupport.phpnew file mode 100644index 0000000000..7e29ab9452--- /dev/null+++ b/app/Support/Http/Controllers/BasicDataSupport.php@@ -0,0 +1,67 @@+<?php+/**+ * BasicDataSupport.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Support\Http\Controllers;++/**+ * Trait BasicDataSupport+ *+ * @package FireflyIII\Support\Http\Controllers+ */+trait BasicDataSupport+{+ /**+ * Find the ID in a given array. Return '0' of not there (amount).+ *+ * @param array $array+ * @param int $entryId+ *+ * @return null|mixed+ */+ protected function isInArray(array $array, int $entryId) // helper for data (math, calculations)+ {+ $result = '0';+ if (isset($array[$entryId])) {+ $result = $array[$entryId];+ }++ return $result;+ }++ /**+ * Sum up an array.+ *+ * @param array $array+ *+ * @return string+ */+ protected function arraySum(array $array): string // filter + group data+ {+ $sum = '0';+ foreach ($array as $entry) {+ $sum = bcadd($sum, $entry);+ }++ return $sum;+ }+}\ No newline at end of file