mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
Code cleanup.
This commit is contained in:
@@ -34,12 +34,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class AccountList implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Collection
|
||||
* @throws NotFoundHttpException
|
||||
*
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): Collection
|
||||
{
|
||||
@@ -48,20 +43,23 @@ class AccountList implements BinderInterface
|
||||
if ('allAssetAccounts' === $value) {
|
||||
/** @var Collection $collection */
|
||||
$collection = auth()->user()->accounts()
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('account_types.type', [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE])
|
||||
->orderBy('accounts.name', 'ASC')
|
||||
->get(['accounts.*']);
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('account_types.type', [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE])
|
||||
->orderBy('accounts.name', 'ASC')
|
||||
->get(['accounts.*'])
|
||||
;
|
||||
}
|
||||
if ('allAssetAccounts' !== $value) {
|
||||
$incoming = array_map('\intval', explode(',', $value));
|
||||
$list = array_merge(array_unique($incoming), [0]);
|
||||
|
||||
/** @var Collection $collection */
|
||||
$collection = auth()->user()->accounts()
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('accounts.id', $list)
|
||||
->orderBy('accounts.name', 'ASC')
|
||||
->get(['accounts.*']);
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('accounts.id', $list)
|
||||
->orderBy('accounts.name', 'ASC')
|
||||
->get(['accounts.*'])
|
||||
;
|
||||
}
|
||||
|
||||
if ($collection->count() > 0) {
|
||||
@@ -69,6 +67,7 @@ class AccountList implements BinderInterface
|
||||
}
|
||||
}
|
||||
app('log')->error(sprintf('Trying to show account list (%s), but user is not logged in or list is empty.', $route->uri));
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,6 @@ use Illuminate\Routing\Route;
|
||||
interface BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route);
|
||||
|
||||
@@ -34,37 +34,33 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class BudgetList implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Collection
|
||||
* @throws NotFoundHttpException
|
||||
*
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): Collection
|
||||
{
|
||||
if (auth()->check()) {
|
||||
if ('allBudgets' === $value) {
|
||||
return auth()->user()->budgets()->where('active', true)
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')
|
||||
->get();
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')
|
||||
->get()
|
||||
;
|
||||
}
|
||||
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
|
||||
|
||||
if (0 === count($list)) { // @phpstan-ignore-line
|
||||
app('log')->warning('Budget list count is zero, return 404.');
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
|
||||
/** @var Collection $collection */
|
||||
$collection = auth()->user()->budgets()
|
||||
->where('active', true)
|
||||
->whereIn('id', $list)
|
||||
->get();
|
||||
->where('active', true)
|
||||
->whereIn('id', $list)
|
||||
->get()
|
||||
;
|
||||
|
||||
// add empty budget if applicable.
|
||||
if (in_array(0, $list, true)) {
|
||||
@@ -76,6 +72,7 @@ class BudgetList implements BinderInterface
|
||||
}
|
||||
}
|
||||
app('log')->warning('BudgetList fallback to 404.');
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class CLIToken implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route)
|
||||
@@ -60,6 +58,7 @@ class CLIToken implements BinderInterface
|
||||
}
|
||||
}
|
||||
app('log')->error(sprintf('Recognized no users by access token "%s"', $value));
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,20 +34,16 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class CategoryList implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Collection
|
||||
* @throws NotFoundHttpException
|
||||
*
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): Collection
|
||||
{
|
||||
if (auth()->check()) {
|
||||
if ('allCategories' === $value) {
|
||||
return auth()->user()->categories()
|
||||
->orderBy('name', 'ASC')
|
||||
->get();
|
||||
->orderBy('name', 'ASC')
|
||||
->get()
|
||||
;
|
||||
}
|
||||
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
@@ -57,8 +53,9 @@ class CategoryList implements BinderInterface
|
||||
|
||||
/** @var Collection $collection */
|
||||
$collection = auth()->user()->categories()
|
||||
->whereIn('id', $list)
|
||||
->get();
|
||||
->whereIn('id', $list)
|
||||
->get()
|
||||
;
|
||||
|
||||
// add empty category if applicable.
|
||||
if (in_array(0, $list, true)) {
|
||||
@@ -69,6 +66,7 @@ class CategoryList implements BinderInterface
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class CurrencyCode implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): TransactionCurrency
|
||||
@@ -47,6 +43,7 @@ class CurrencyCode implements BinderInterface
|
||||
return $currency;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class Date implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Carbon
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): Carbon
|
||||
@@ -75,6 +71,7 @@ class Date implements BinderInterface
|
||||
} catch (InvalidDateException|InvalidFormatException $e) { // @phpstan-ignore-line
|
||||
$message = sprintf('Could not parse date "%s" for user #%d: %s', $value, auth()->user()->id, $e->getMessage());
|
||||
app('log')->error($message);
|
||||
|
||||
throw new NotFoundHttpException('Could not parse value', $e);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,8 @@ class DynamicConfigKey
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return string
|
||||
* @throws NotFoundHttpException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): string
|
||||
@@ -52,6 +49,7 @@ class DynamicConfigKey
|
||||
if (in_array($value, self::$accepted, true)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,10 +57,6 @@ class EitherConfigKey
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return string
|
||||
* @throws NotFoundHttpException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
@@ -70,6 +66,7 @@ class EitherConfigKey
|
||||
if (in_array($value, self::$static, true) || in_array($value, DynamicConfigKey::$accepted, true)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,11 +34,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class JournalList implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): array
|
||||
@@ -59,14 +54,10 @@ class JournalList implements BinderInterface
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function parseList(string $value): array
|
||||
{
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
|
||||
@@ -35,10 +35,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class TagList implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Collection
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): Collection
|
||||
@@ -46,18 +42,19 @@ class TagList implements BinderInterface
|
||||
if (auth()->check()) {
|
||||
if ('allTags' === $value) {
|
||||
return auth()->user()->tags()
|
||||
->orderBy('tag', 'ASC')
|
||||
->get();
|
||||
->orderBy('tag', 'ASC')
|
||||
->get()
|
||||
;
|
||||
}
|
||||
$list = array_unique(array_map('\strtolower', explode(',', $value)));
|
||||
app('log')->debug('List of tags is', $list);
|
||||
|
||||
if (0 === count($list)) { // @phpstan-ignore-line
|
||||
app('log')->error('Tag list is empty.');
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
|
||||
/** @var TagRepositoryInterface $repository */
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$repository->setUser(auth()->user());
|
||||
@@ -81,6 +78,7 @@ class TagList implements BinderInterface
|
||||
}
|
||||
}
|
||||
app('log')->error('TagList: user is not logged in.');
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +33,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
*/
|
||||
class TagOrId implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): Tag
|
||||
{
|
||||
if (auth()->check()) {
|
||||
@@ -54,9 +48,11 @@ class TagOrId implements BinderInterface
|
||||
return $result;
|
||||
}
|
||||
app('log')->error('TagOrId: tag not found.');
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
app('log')->error('TagOrId: user is not logged in.');
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class UserGroupAccount implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Account
|
||||
* @throws NotFoundHttpException
|
||||
*
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): Account
|
||||
{
|
||||
@@ -47,12 +42,14 @@ class UserGroupAccount implements BinderInterface
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$currency = Account::where('id', (int)$value)
|
||||
->where('user_group_id', $user->user_group_id)
|
||||
->first();
|
||||
->where('user_group_id', $user->user_group_id)
|
||||
->first()
|
||||
;
|
||||
if (null !== $currency) {
|
||||
return $currency;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class UserGroupBill implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Bill
|
||||
* @throws NotFoundHttpException
|
||||
*
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): Bill
|
||||
{
|
||||
@@ -47,12 +42,14 @@ class UserGroupBill implements BinderInterface
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$currency = Bill::where('id', (int)$value)
|
||||
->where('user_group_id', $user->user_group_id)
|
||||
->first();
|
||||
->where('user_group_id', $user->user_group_id)
|
||||
->first()
|
||||
;
|
||||
if (null !== $currency) {
|
||||
return $currency;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user