mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 14:12:15 +00:00
Improve code quality.
This commit is contained in:
@@ -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 NullPointerExceptionInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Chart;
|
||||
@@ -216,6 +217,7 @@ class AccountController extends Controller
|
||||
return $this->expenseCategory($account, $start, $end);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows the balances for all the user's frontpage accounts.
|
||||
*
|
||||
@@ -230,6 +232,8 @@ class AccountController extends Controller
|
||||
$defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
|
||||
Log::debug('Default set is ', $defaultSet);
|
||||
$frontPage = Preferences::get('frontPageAccounts', $defaultSet);
|
||||
|
||||
|
||||
Log::debug('Frontpage preference set is ', $frontPage->data);
|
||||
if (0 === \count($frontPage->data)) {
|
||||
$frontPage->data = $defaultSet;
|
||||
|
||||
@@ -107,6 +107,7 @@ class BudgetController extends Controller
|
||||
$current = app('navigation')->startOfPeriod($current, $step);
|
||||
|
||||
while ($end >= $current) {
|
||||
/** @var Carbon $currentEnd */
|
||||
$currentEnd = app('navigation')->endOfPeriod($current, $step);
|
||||
if ('1Y' === $step) {
|
||||
$currentEnd->subDay(); // @codeCoverageIgnore
|
||||
@@ -182,9 +183,10 @@ class BudgetController extends Controller
|
||||
*/
|
||||
public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id;
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($budget->id);
|
||||
$cache->addProperty($budgetLimit->id ?? 0);
|
||||
$cache->addProperty($budgetLimitId);
|
||||
$cache->addProperty('chart.budget.expense-asset');
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
@@ -193,7 +195,7 @@ class BudgetController extends Controller
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setBudget($budget);
|
||||
if (null !== $budgetLimit->id) {
|
||||
if (null !== $budgetLimit) {
|
||||
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
||||
}
|
||||
|
||||
@@ -227,9 +229,10 @@ class BudgetController extends Controller
|
||||
*/
|
||||
public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
$budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id;
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($budget->id);
|
||||
$cache->addProperty($budgetLimit->id ?? 0);
|
||||
$cache->addProperty($budgetLimitId);
|
||||
$cache->addProperty('chart.budget.expense-category');
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
@@ -238,7 +241,7 @@ class BudgetController extends Controller
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setBudget($budget)->withCategoryInformation();
|
||||
if (null !== $budgetLimit->id) {
|
||||
if (null !== $budgetLimit) {
|
||||
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
||||
}
|
||||
|
||||
@@ -274,9 +277,10 @@ class BudgetController extends Controller
|
||||
*/
|
||||
public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
$budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id;
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($budget->id);
|
||||
$cache->addProperty($budgetLimit->id ?? 0);
|
||||
$cache->addProperty($budgetLimitId);
|
||||
$cache->addProperty('chart.budget.expense-expense');
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
@@ -285,7 +289,7 @@ class BudgetController extends Controller
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withOpposingAccount();
|
||||
if (null !== $budgetLimit->id) {
|
||||
if (null !== $budgetLimit) {
|
||||
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
||||
}
|
||||
|
||||
@@ -481,7 +485,9 @@ class BudgetController extends Controller
|
||||
$current = clone $start;
|
||||
$budgeted = [];
|
||||
while ($current < $end) {
|
||||
/** @var Carbon $currentStart */
|
||||
$currentStart = app('navigation')->startOfPeriod($current, $range);
|
||||
/** @var Carbon $currentEnd */
|
||||
$currentEnd = app('navigation')->endOfPeriod($current, $range);
|
||||
$budgetLimits = $this->repository->getBudgetLimits($budget, $currentStart, $currentEnd);
|
||||
$index = $currentStart->format($key);
|
||||
|
||||
@@ -191,6 +191,7 @@ class BudgetReportController extends Controller
|
||||
$chartData[$budget->id . '-left']['entries'][$label] = $leftOfLimits[$budgetLimitId];
|
||||
}
|
||||
}
|
||||
/** @var Carbon $currentStart */
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay();
|
||||
}
|
||||
|
||||
@@ -248,6 +248,7 @@ class CategoryReportController extends Controller
|
||||
$chartData[$labelSumIn]['entries'][$label] = $sumOfIncome[$category->id];
|
||||
$chartData[$labelSumOut]['entries'][$label] = $sumOfExpense[$category->id];
|
||||
}
|
||||
/** @var Carbon $currentStart */
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay();
|
||||
}
|
||||
|
||||
@@ -165,6 +165,7 @@ class ExpenseReportController extends Controller
|
||||
$chartData[$labelSumIn]['entries'][$label] = $sumOfIncome[$exp->id];
|
||||
$chartData[$labelSumOut]['entries'][$label] = $sumOfExpense[$exp->id];
|
||||
}
|
||||
/** @var Carbon $currentStart */
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay();
|
||||
}
|
||||
|
||||
@@ -237,6 +237,7 @@ class TagReportController extends Controller
|
||||
$chartData[$labelSumIn]['entries'][$label] = $sumOfIncome[$tag->id];
|
||||
$chartData[$labelSumOut]['entries'][$label] = $sumOfExpense[$tag->id];
|
||||
}
|
||||
/** @var Carbon $currentStart */
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user