Expand action and clean up code.

This commit is contained in:
James Cole
2023-11-04 14:09:51 +01:00
parent 6eabe5fa8c
commit 5a35960434
23 changed files with 119 additions and 93 deletions

View File

@@ -96,15 +96,17 @@ class AccountController extends Controller
// user's preferences
$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT])->pluck('id')->toArray();
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
/** @var TransactionCurrency $default */
$default = app('amount')->getDefaultCurrency();
$accounts = $this->repository->getAccountsById($frontPage->data);
$chartData = [];
if (!(is_array($frontPage->data) && count($frontPage->data) > 0)) {
$frontPage->data = $defaultSet;
$frontPage->save();
}
/** @var TransactionCurrency $default */
$default = app('amount')->getDefaultCurrency();
$accounts = $this->repository->getAccountsById($frontPage->data);
$chartData = [];
/** @var Account $account */
foreach ($accounts as $account) {
$currency = $this->repository->getAccountCurrency($account);

View File

@@ -38,19 +38,19 @@ use Illuminate\Pagination\LengthAwarePaginator;
*/
class ListController extends Controller
{
// private BudgetLimitRepositoryInterface $repository;
//
// public function __construct()
// {
// parent::__construct();
// $this->middleware(
// function ($request, $next) {
// $this->repository = app(BudgetLimitRepositoryInterface::class);
//
// return $next($request);
// }
// );
// }
// private BudgetLimitRepositoryInterface $repository;
//
// public function __construct()
// {
// parent::__construct();
// $this->middleware(
// function ($request, $next) {
// $this->repository = app(BudgetLimitRepositoryInterface::class);
//
// return $next($request);
// }
// );
// }
/**
* This endpoint is documented at:
@@ -59,18 +59,18 @@ class ListController extends Controller
public function index(DateRequest $request, Budget $budget): JsonResponse
{
return response()->json([]);
// throw new FireflyException('Needs refactoring, move to IndexController.');
// $pageSize = $this->parameters->get('limit');
// $dates = $request->getAll();
// $collection = $this->repository->getBudgetLimits($budget, $dates['start'], $dates['end']);
// $total = $collection->count();
// $collection->slice($pageSize * $this->parameters->get('page'), $pageSize);
//
// $paginator = new LengthAwarePaginator($collection, $total, $pageSize, $this->parameters->get('page'));
// $transformer = new BudgetLimitTransformer();
//
// return response()
// ->api($this->jsonApiList('budget-limits', $paginator, $transformer))
// ->header('Content-Type', self::CONTENT_TYPE);
// throw new FireflyException('Needs refactoring, move to IndexController.');
// $pageSize = $this->parameters->get('limit');
// $dates = $request->getAll();
// $collection = $this->repository->getBudgetLimits($budget, $dates['start'], $dates['end']);
// $total = $collection->count();
// $collection->slice($pageSize * $this->parameters->get('page'), $pageSize);
//
// $paginator = new LengthAwarePaginator($collection, $total, $pageSize, $this->parameters->get('page'));
// $transformer = new BudgetLimitTransformer();
//
// return response()
// ->api($this->jsonApiList('budget-limits', $paginator, $transformer))
// ->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -53,8 +53,8 @@ class ForceDecimalSize extends Command
{
use ShowsFriendlyMessages;
protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';
protected $signature = 'firefly-iii:force-decimal-size';
protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';
protected $signature = 'firefly-iii:force-decimal-size';
private string $cast;
private array $classes
= [

View File

@@ -56,7 +56,7 @@ class MigrateToRules extends Command
*
* @var string
*/
protected $signature = 'firefly-iii:bills-to-rules {--F|force : Force the execution of this command.}';
protected $signature = 'firefly-iii:bills-to-rules {--F|force : Force the execution of this command.}';
private BillRepositoryInterface $billRepository;
private int $count;
private RuleGroupRepositoryInterface $ruleGroupRepository;

View File

@@ -249,11 +249,11 @@ class UpgradeLiabilitiesEight extends Command
// code is kept in place so I can revisit my reasoning.
$delete = false;
// if ($delete) {
// if ($delete) {
$service = app(TransactionGroupDestroyService::class);
$service->destroy($journal->transactionGroup);
$count++;
// }
// }
}
return $count;

View File

@@ -34,11 +34,10 @@ use Throwable;
*/
final class IntervalException extends Exception
{
public array $availableIntervals;
public Periodicity $periodicity;
/** @var string */
protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s';
protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s';
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
{
@@ -60,8 +59,7 @@ final class IntervalException extends Exception
array $intervals,
int $code = 0,
?Throwable $previous = null
): IntervalException
{
): IntervalException {
$message = sprintf(
'The periodicity %s is unknown. Choose one of available periodicity: %s',
$periodicity->name,

View File

@@ -48,8 +48,7 @@ class AttachmentHelper implements AttachmentHelperInterface
protected array $allowedMimes = [];
protected int $maxUploadSize = 0;
/** @var Filesystem The disk where attachments are stored. */
protected $uploadDisk;
protected Filesystem $uploadDisk;
/**
* AttachmentHelper constructor.

View File

@@ -252,7 +252,7 @@ class MassController extends Controller
try {
$carbon = Carbon::parse($value[$journalId]);
} catch (InvalidArgumentException $e) {
Log::warning(sprintf('Could not parse "%s" but dont mind',$value[$journalId]));
Log::warning(sprintf('Could not parse "%s" but dont mind', $value[$journalId]));
Log::warning($e->getMessage());
return null;

View File

@@ -113,7 +113,7 @@ class TagRepository implements TagRepositoryInterface
*/
public function setUser(User | Authenticatable | null $user): void
{
if ($user instanceof User ) {
if ($user instanceof User) {
$this->user = $user;
}
}

View File

@@ -32,7 +32,6 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class IsBoolean implements ValidationRule
{
/**
* @param string $attribute
* @param mixed $value

View File

@@ -35,7 +35,6 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class IsDateOrTime implements ValidationRule
{
/**
* @param string $attribute
* @param mixed $value
@@ -47,7 +46,8 @@ class IsDateOrTime implements ValidationRule
{
$value = (string)$value;
if ('' === $value) {
$fail('validation.date_or_time')->translate();;
$fail('validation.date_or_time')->translate();
;
return;
}
if (10 === strlen($value)) {
@@ -57,12 +57,14 @@ class IsDateOrTime implements ValidationRule
} catch (InvalidDateException $e) { // @phpstan-ignore-line
app('log')->error(sprintf('"%s" is not a valid date: %s', $value, $e->getMessage()));
$fail('validation.date_or_time')->translate();;
$fail('validation.date_or_time')->translate();
;
return;
} catch (InvalidFormatException $e) { // @phpstan-ignore-line
app('log')->error(sprintf('"%s" is of an invalid format: %s', $value, $e->getMessage()));
$fail('validation.date_or_time')->translate();;
$fail('validation.date_or_time')->translate();
;
return;
}
@@ -74,12 +76,14 @@ class IsDateOrTime implements ValidationRule
} catch (InvalidDateException $e) { // @phpstan-ignore-line
app('log')->error(sprintf('"%s" is not a valid date or time: %s', $value, $e->getMessage()));
$fail('validation.date_or_time')->translate();;
$fail('validation.date_or_time')->translate();
;
return;
} catch (InvalidFormatException $e) {
app('log')->error(sprintf('"%s" is of an invalid format: %s', $value, $e->getMessage()));
$fail('validation.date_or_time')->translate();;
$fail('validation.date_or_time')->translate();
;
return;
}
}

View File

@@ -34,7 +34,6 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class IsTransferAccount implements ValidationRule
{
/**
* @param string $attribute
* @param mixed $value

View File

@@ -35,7 +35,6 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class ValidJournals implements ValidationRule
{
/**
* @param string $attribute
* @param mixed $value

View File

@@ -293,7 +293,8 @@ class RecurrenceUpdateService
if (array_key_exists('currency_id', $submitted) || array_key_exists('currency_code', $submitted)) {
$currency = $currencyFactory->find(
array_key_exists('currency_id', $submitted) ? (int)$submitted['currency_id'] : null,
array_key_exists('currency_code', $submitted) ? $submitted['currency_code'] : null);
array_key_exists('currency_code', $submitted) ? $submitted['currency_code'] : null
);
}
if (null === $currency) {
unset($submitted['currency_id'], $submitted['currency_code']);
@@ -304,7 +305,8 @@ class RecurrenceUpdateService
if (array_key_exists('foreign_currency_id', $submitted) || array_key_exists('foreign_currency_code', $submitted)) {
$foreignCurrency = $currencyFactory->find(
array_key_exists('foreign_currency_id', $submitted) ? (int)$submitted['foreign_currency_id'] : null,
array_key_exists('foreign_currency_code', $submitted) ? $submitted['foreign_currency_code'] : null);
array_key_exists('foreign_currency_code', $submitted) ? $submitted['foreign_currency_code'] : null
);
}
if (null === $foreignCurrency) {
unset($submitted['foreign_currency_id'], $currency['foreign_currency_code']);

View File

@@ -89,10 +89,10 @@ class Navigation
if (!array_key_exists($repeatFreq, $functionMap)) {
Log::error(sprintf(
'The periodicity %s is unknown. Choose one of available periodicity: %s',
$repeatFreq,
join(', ', array_keys($functionMap))
));
'The periodicity %s is unknown. Choose one of available periodicity: %s',
$repeatFreq,
join(', ', array_keys($functionMap))
));
return $theDate;
}
@@ -352,12 +352,12 @@ class Navigation
public function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int
{
Log::debug(sprintf(
'diffInPeriods: %s (skip: %d), between %s and %s.',
$period,
$skip,
$beginning->format('Y-m-d'),
$end->format('Y-m-d')
));
'diffInPeriods: %s (skip: %d), between %s and %s.',
$period,
$skip,
$beginning->format('Y-m-d'),
$end->format('Y-m-d')
));
$map = [
'daily' => 'floatDiffInDays',
'weekly' => 'floatDiffInWeeks',
@@ -394,11 +394,11 @@ class Navigation
$parameter = $skip + 1;
$diff = ceil($diff / $parameter) * $parameter;
Log::debug(sprintf(
'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',
$skip,
$parameter,
$diff
));
'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',
$skip,
$parameter,
$diff
));
}
return (int)$diff;

View File

@@ -322,15 +322,15 @@ class Steam
$balances[$format] = $currentBalance;
app('log')->debug(sprintf(
'%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',
$format,
$currency->code,
$rate,
$currency->code,
$transaction['amount'],
$native->code,
$convertedAmount
));
'%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',
$format,
$currency->code,
$rate,
$currency->code,
$transaction['amount'],
$native->code,
$convertedAmount
));
}

View File

@@ -43,7 +43,6 @@ use stdClass;
*/
class TransactionGroupTransformer extends AbstractTransformer
{
private ExchangeRateConverter $converter;
private array $currencies = [];
private TransactionCurrency $default;

View File

@@ -47,7 +47,6 @@ use PragmaRX\Google2FA\Exceptions\InvalidCharactersException;
use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException;
use ValueError;
/**
* Class FireflyValidator.
*/