mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 01:42:19 +00:00
Small code quality improvements.
This commit is contained in:
@@ -143,6 +143,7 @@ class NoCategoryController extends Controller
|
|||||||
* @param Carbon $theDate
|
* @param Carbon $theDate
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
private function getNoCategoryPeriodOverview(Carbon $theDate): Collection
|
private function getNoCategoryPeriodOverview(Carbon $theDate): Collection
|
||||||
{
|
{
|
||||||
|
@@ -36,15 +36,22 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use FireflyIII\Support\Http\Controllers\DateCalculation;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/** checked
|
/**
|
||||||
* Class AccountController.
|
* Class AccountController.
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||||
*/
|
*/
|
||||||
class AccountController extends Controller
|
class AccountController extends Controller
|
||||||
{
|
{
|
||||||
|
use DateCalculation;
|
||||||
|
|
||||||
/** @var GeneratorInterface */
|
/** @var GeneratorInterface */
|
||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
@@ -310,6 +317,8 @@ class AccountController extends Controller
|
|||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
public function period(Account $account, Carbon $start, Carbon $end): JsonResponse
|
public function period(Account $account, Carbon $start, Carbon $end): JsonResponse
|
||||||
{
|
{
|
||||||
@@ -321,18 +330,8 @@ class AccountController extends Controller
|
|||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
// depending on diff, do something with range of chart.
|
|
||||||
$step = '1D';
|
$step = $this->calculateStep($start, $end);
|
||||||
$months = $start->diffInMonths($end);
|
|
||||||
if ($months > 3) {
|
|
||||||
$step = '1W'; // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
if ($months > 24) {
|
|
||||||
$step = '1M'; // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
if ($months > 100) {
|
|
||||||
$step = '1Y'; // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
$current = clone $start;
|
$current = clone $start;
|
||||||
switch ($step) {
|
switch ($step) {
|
||||||
@@ -433,6 +432,9 @@ class AccountController extends Controller
|
|||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
*
|
||||||
|
* @SuppressWarnigns(PHPMD.CyclomaticComplexity)
|
||||||
|
* @SuppressWarnigns(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
private function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array
|
private function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
|
@@ -36,6 +36,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use FireflyIII\Support\Http\Controllers\DateCalculation;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
class BudgetController extends Controller
|
class BudgetController extends Controller
|
||||||
{
|
{
|
||||||
|
use DateCalculation;
|
||||||
/** @var GeneratorInterface */
|
/** @var GeneratorInterface */
|
||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
@@ -89,17 +91,7 @@ class BudgetController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// depending on diff, do something with range of chart.
|
// depending on diff, do something with range of chart.
|
||||||
$step = '1D';
|
$step = $this->calculateStep($start, $end);
|
||||||
$months = $start->diffInMonths($end);
|
|
||||||
if ($months > 3) {
|
|
||||||
$step = '1W';
|
|
||||||
}
|
|
||||||
if ($months > 24) {
|
|
||||||
$step = '1M';
|
|
||||||
}
|
|
||||||
if ($months > 60) {
|
|
||||||
$step = '1Y'; // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
$budgetCollection = new Collection([$budget]);
|
$budgetCollection = new Collection([$budget]);
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
$current = clone $start;
|
$current = clone $start;
|
||||||
|
@@ -29,6 +29,7 @@ use FireflyIII\Models\PiggyBank;
|
|||||||
use FireflyIII\Models\PiggyBankEvent;
|
use FireflyIII\Models\PiggyBankEvent;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use FireflyIII\Support\Http\Controllers\DateCalculation;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
class PiggyBankController extends Controller
|
class PiggyBankController extends Controller
|
||||||
{
|
{
|
||||||
|
use DateCalculation;
|
||||||
/** @var GeneratorInterface */
|
/** @var GeneratorInterface */
|
||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
@@ -81,17 +83,7 @@ class PiggyBankController extends Controller
|
|||||||
$oldest = $startDate->lt($firstDate) ? $startDate : $firstDate;
|
$oldest = $startDate->lt($firstDate) ? $startDate : $firstDate;
|
||||||
$today = new Carbon;
|
$today = new Carbon;
|
||||||
// depending on diff, do something with range of chart.
|
// depending on diff, do something with range of chart.
|
||||||
$step = '1D';
|
$step = $this->calculateStep($oldest, $today);
|
||||||
$months = $oldest->diffInMonths($today);
|
|
||||||
if ($months > 3) {
|
|
||||||
$step = '1W'; // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
if ($months > 24) {
|
|
||||||
$step = '1M'; // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
if ($months > 100) {
|
|
||||||
$step = '1Y'; // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
while ($oldest <= $today) {
|
while ($oldest <= $today) {
|
||||||
|
@@ -32,7 +32,7 @@ use Illuminate\Support\Facades\Facade;
|
|||||||
*
|
*
|
||||||
* @method Preference set(string $name, $value)
|
* @method Preference set(string $name, $value)
|
||||||
* @method Preference get(string $name, $value)
|
* @method Preference get(string $name, $value)
|
||||||
* @method Preference|null getForUser(User $user, string $name, $default)
|
* @method Preference|null getForUser(User $user, string $name, $default = null)
|
||||||
* @method void mark()
|
* @method void mark()
|
||||||
*/
|
*/
|
||||||
class Preferences extends Facade
|
class Preferences extends Facade
|
||||||
|
@@ -33,6 +33,30 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
trait DateCalculation
|
trait DateCalculation
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function calculateStep(Carbon $start, Carbon $end): string
|
||||||
|
{
|
||||||
|
|
||||||
|
$step = '1D';
|
||||||
|
$months = $start->diffInMonths($end);
|
||||||
|
if ($months > 3) {
|
||||||
|
$step = '1W'; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
if ($months > 24) {
|
||||||
|
$step = '1M'; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
if ($months > 100) {
|
||||||
|
$step = '1Y'; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
return $step;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of days between the two given dates.
|
* Returns the number of days between the two given dates.
|
||||||
* - If today is within the two dates, give the number of days between today and the end date.
|
* - If today is within the two dates, give the number of days between today and the end date.
|
||||||
@@ -111,7 +135,7 @@ trait DateCalculation
|
|||||||
while ($count < 12) {
|
while ($count < 12) {
|
||||||
$format = $current->format('Y-m-d');
|
$format = $current->format('Y-m-d');
|
||||||
$loop[$format] = app('navigation')->periodShow($current, $range);
|
$loop[$format] = app('navigation')->periodShow($current, $range);
|
||||||
$current = app('navigation')->endOfPeriod($current, $range);
|
$current = app('navigation')->endOfPeriod($current, $range);
|
||||||
++$count;
|
++$count;
|
||||||
$current->addDay();
|
$current->addDay();
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,7 @@ class FireflyValidator extends Validator
|
|||||||
*/
|
*/
|
||||||
public function validate2faCode($attribute, $value): bool
|
public function validate2faCode($attribute, $value): bool
|
||||||
{
|
{
|
||||||
if (!\is_string($value) || null === $value || 6 != \strlen($value)) {
|
if (!\is_string($value) || null === $value || 6 !== \strlen($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user