Various code cleanup.

This commit is contained in:
James Cole
2018-07-08 12:08:53 +02:00
parent 2f2f907ffe
commit b315882f58
56 changed files with 465 additions and 396 deletions

View File

@@ -35,6 +35,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Log;
use Preferences;
@@ -62,9 +63,9 @@ class AccountController extends Controller
*
* @param AccountRepositoryInterface $repository
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function expenseAccounts(AccountRepositoryInterface $repository)
public function expenseAccounts(AccountRepositoryInterface $repository): JsonResponse
{
$start = clone session('start', Carbon::now()->startOfMonth());
$end = clone session('end', Carbon::now()->endOfMonth());
@@ -99,14 +100,15 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* @param Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function expenseBudget(Account $account, Carbon $start, Carbon $end)
public function expenseBudget(Account $account, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties;
$cache->addProperty($account->id);
@@ -146,9 +148,9 @@ class AccountController extends Controller
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account)
public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account);
$end = Carbon::now();
@@ -156,14 +158,15 @@ class AccountController extends Controller
return $this->expenseBudget($account, $start, $end);
}
/**
* @param Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function expenseCategory(Account $account, Carbon $start, Carbon $end)
public function expenseCategory(Account $account, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties;
$cache->addProperty($account->id);
@@ -203,9 +206,9 @@ class AccountController extends Controller
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account)
public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account);
$end = Carbon::now();
@@ -218,9 +221,9 @@ class AccountController extends Controller
*
* @param AccountRepositoryInterface $repository
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function frontpage(AccountRepositoryInterface $repository)
public function frontpage(AccountRepositoryInterface $repository): JsonResponse
{
$start = clone session('start', Carbon::now()->startOfMonth());
$end = clone session('end', Carbon::now()->endOfMonth());
@@ -238,14 +241,15 @@ class AccountController extends Controller
return response()->json($this->accountBalanceChart($accounts, $start, $end));
}
/**
* @param Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function incomeCategory(Account $account, Carbon $start, Carbon $end)
public function incomeCategory(Account $account, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties;
$cache->addProperty($account->id);
@@ -285,9 +289,9 @@ class AccountController extends Controller
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account)
public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account);
$end = Carbon::now();
@@ -295,15 +299,16 @@ class AccountController extends Controller
return $this->incomeCategory($account, $start, $end);
}
/**
* @param Account $account
* @param Carbon $start
*
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function period(Account $account, Carbon $start, Carbon $end)
public function period(Account $account, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties;
$cache->addProperty('chart.account.period');
@@ -367,21 +372,22 @@ class AccountController extends Controller
* @param Carbon $end
* @param Collection $accounts
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function report(Collection $accounts, Carbon $start, Carbon $end)
public function report(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
return response()->json($this->accountBalanceChart($accounts, $start, $end));
}
/**
* Shows the balances for all the user's revenue accounts.
*
* @param AccountRepositoryInterface $repository
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function revenueAccounts(AccountRepositoryInterface $repository)
public function revenueAccounts(AccountRepositoryInterface $repository): JsonResponse
{
$start = clone session('start', Carbon::now()->startOfMonth());
$end = clone session('end', Carbon::now()->endOfMonth());
@@ -417,6 +423,7 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* @param Collection $accounts
* @param Carbon $start

View File

@@ -49,6 +49,7 @@ class BillController extends Controller
$this->generator = app(GeneratorInterface::class);
}
/**
* Shows all bills and whether or not they've been paid this month (pie chart).
*
@@ -81,6 +82,7 @@ class BillController extends Controller
return response()->json($data);
}
/**
* @param JournalCollectorInterface $collector
* @param Bill $bill

View File

@@ -42,7 +42,6 @@ use Steam;
/**
* Class BudgetController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) // can't realy be helped.
*/
class BudgetController extends Controller
{
@@ -69,6 +68,7 @@ class BudgetController extends Controller
);
}
/**
* @param Budget $budget
*
@@ -124,10 +124,10 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* Shows the amount left in a specific budget limit.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly five.
*
* @param Budget $budget
* @param BudgetLimit $budgetLimit
@@ -172,6 +172,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* @param Budget $budget
* @param BudgetLimit|null $budgetLimit
@@ -216,6 +217,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* @param Budget $budget
* @param BudgetLimit|null $budgetLimit
@@ -262,6 +264,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* @param Budget $budget
* @param BudgetLimit|null $budgetLimit
@@ -307,12 +310,10 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* Shows a budget list with spent/left/overspent.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly five.
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // 46 lines, I'm fine with this.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function frontpage()
@@ -361,8 +362,8 @@ class BudgetController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly five.
*
* @param Budget $budget
* @param Carbon $start
@@ -406,6 +407,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* @param Collection $accounts
* @param Carbon $start
@@ -514,8 +516,8 @@ class BudgetController extends Controller
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's 6 but ok.
*
* @param Collection $limits
* @param Budget $budget
@@ -550,7 +552,6 @@ class BudgetController extends Controller
}
/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly five.
*
* Returns an array with the following values:
* 0 =>

View File

@@ -66,6 +66,7 @@ class BudgetReportController extends Controller
);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $budgets
@@ -90,6 +91,7 @@ class BudgetReportController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $budgets
@@ -114,6 +116,7 @@ class BudgetReportController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $budgets
@@ -197,6 +200,7 @@ class BudgetReportController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Returns the budget limits belonging to the given budget and valid on the given day.
*
@@ -225,6 +229,7 @@ class BudgetReportController extends Controller
return $set;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $budgets

View File

@@ -51,6 +51,7 @@ class CategoryController extends Controller
$this->generator = app(GeneratorInterface::class);
}
/**
* Show an overview for a category for all time, per month/week/year.
*
@@ -116,6 +117,7 @@ class CategoryController extends Controller
return response()->json($data);
}
/**
* @param CategoryRepositoryInterface $repository
* @param AccountRepositoryInterface $accountRepository
@@ -156,16 +158,17 @@ class CategoryController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param CategoryRepositoryInterface $repository
* @param Category $category
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
* @param Category $category
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function reportPeriod(CategoryRepositoryInterface $repository, Category $category, Collection $accounts, Carbon $start, Carbon $end)
public function reportPeriod(Category $category, Collection $accounts, Carbon $start, Carbon $end)
{
$cache = new CacheProperties;
$cache->addProperty($start);
@@ -176,10 +179,11 @@ class CategoryController extends Controller
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
$expenses = $repository->periodExpenses(new Collection([$category]), $accounts, $start, $end);
$income = $repository->periodIncome(new Collection([$category]), $accounts, $start, $end);
$periods = app('navigation')->listOfPeriods($start, $end);
$chartData = [
$repository = app(CategoryRepositoryInterface::class);
$expenses = $repository->periodExpenses(new Collection([$category]), $accounts, $start, $end);
$income = $repository->periodIncome(new Collection([$category]), $accounts, $start, $end);
$periods = app('navigation')->listOfPeriods($start, $end);
$chartData = [
[
'label' => (string)trans('firefly.spent'),
'entries' => [],
@@ -214,15 +218,15 @@ class CategoryController extends Controller
return response()->json($data);
}
/**
* @param CategoryRepositoryInterface $repository
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function reportPeriodNoCategory(CategoryRepositoryInterface $repository, Collection $accounts, Carbon $start, Carbon $end)
public function reportPeriodNoCategory(Collection $accounts, Carbon $start, Carbon $end)
{
$cache = new CacheProperties;
$cache->addProperty($start);
@@ -232,10 +236,11 @@ class CategoryController extends Controller
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
$expenses = $repository->periodExpensesNoCategory($accounts, $start, $end);
$income = $repository->periodIncomeNoCategory($accounts, $start, $end);
$periods = app('navigation')->listOfPeriods($start, $end);
$chartData = [
$repository = app(CategoryRepositoryInterface::class);
$expenses = $repository->periodExpensesNoCategory($accounts, $start, $end);
$income = $repository->periodIncomeNoCategory($accounts, $start, $end);
$periods = app('navigation')->listOfPeriods($start, $end);
$chartData = [
[
'label' => (string)trans('firefly.spent'),
'entries' => [],
@@ -270,31 +275,30 @@ class CategoryController extends Controller
}
/**
* @param CategoryRepositoryInterface $repository
* @param Category $category
* @param $date
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, Carbon $date)
public function specificPeriod(Category $category, Carbon $date)
{
$range = Preferences::get('viewRange', '1M')->data;
$start = app('navigation')->startOfPeriod($date, $range);
$end = app('navigation')->endOfPeriod($date, $range);
$data = $this->makePeriodChart($repository, $category, $start, $end);
$data = $this->makePeriodChart($category, $start, $end);
return response()->json($data);
}
/**
* @param CategoryRepositoryInterface $repository
* @param Category $category
* @param Carbon $start
* @param Carbon $end
* @param Category $category
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makePeriodChart(CategoryRepositoryInterface $repository, Category $category, Carbon $start, Carbon $end)
private function makePeriodChart(Category $category, Carbon $start, Carbon $end)
{
$cache = new CacheProperties;
$cache->addProperty($start);
@@ -302,14 +306,16 @@ class CategoryController extends Controller
$cache->addProperty($category->id);
$cache->addProperty('chart.category.period-chart');
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$repository = app(CategoryRepositoryInterface::class);
// chart data
$chartData = [
[

View File

@@ -62,6 +62,7 @@ class CategoryReportController extends Controller
);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $categories
@@ -83,6 +84,7 @@ class CategoryReportController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $categories
@@ -107,6 +109,7 @@ class CategoryReportController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $categories
@@ -131,6 +134,7 @@ class CategoryReportController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $categories
@@ -155,6 +159,8 @@ class CategoryReportController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $categories
@@ -260,6 +266,7 @@ class CategoryReportController extends Controller
return response()->json($data);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $categories
@@ -282,6 +289,7 @@ class CategoryReportController extends Controller
return $collector->getJournals();
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $accounts
* @param Collection $categories

View File

@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MoreThanThreeArgumentsInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Chart;

View File

@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MoreThanThreeArgumentsInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Chart;