mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 19:01:39 +00:00
Updated code coverage, improved binder code.
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -31,52 +32,41 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
*/
|
||||
class AccountList implements BinderInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public static function routeBinder($value, $route): Collection
|
||||
public static function routeBinder(string $value, Route $route): Collection
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$ids = explode(',', $value);
|
||||
// filter ids:
|
||||
$ids = self::filterIds($ids);
|
||||
$list = [];
|
||||
$incoming = explode(',', $value);
|
||||
foreach ($incoming as $entry) {
|
||||
$list[] = intval($entry);
|
||||
}
|
||||
$list = array_unique($list);
|
||||
if (count($list) === 0) {
|
||||
throw new NotFoundHttpException; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @var \Illuminate\Support\Collection $object */
|
||||
$object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('accounts.id', $ids)
|
||||
->where('user_id', auth()->user()->id)
|
||||
->get(['accounts.*']);
|
||||
if ($object->count() > 0) {
|
||||
$object = $object->sortBy(
|
||||
/** @var \Illuminate\Support\Collection $collection */
|
||||
$collection = auth()->user()->accounts()
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('accounts.id', $list)
|
||||
->get(['accounts.*']);
|
||||
if ($collection->count() > 0) {
|
||||
$collection = $collection->sortBy(
|
||||
function (Account $account) {
|
||||
return $account->name;
|
||||
}
|
||||
);
|
||||
|
||||
return $object;
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function filterIds(array $ids): array
|
||||
{
|
||||
$new = [];
|
||||
foreach ($ids as $id) {
|
||||
if (intval($id) > 0) {
|
||||
$new[] = $id;
|
||||
}
|
||||
}
|
||||
$new = array_unique($new);
|
||||
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
|
@@ -22,16 +22,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use Illuminate\Routing\Route;
|
||||
|
||||
/**
|
||||
* Interface BinderInterface.
|
||||
*/
|
||||
interface BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function routeBinder($value, $route);
|
||||
public static function routeBinder(string $value, Route $route);
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use FireflyIII\Models\Budget;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -32,12 +33,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class BudgetList implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
* @return Collection
|
||||
*/
|
||||
public static function routeBinder($value, $route): Collection
|
||||
public static function routeBinder(string $value, Route $route): Collection
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$ids = explode(',', $value);
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -32,12 +33,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class CategoryList implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
* @return Collection
|
||||
*/
|
||||
public static function routeBinder($value, $route): Collection
|
||||
public static function routeBinder(string $value, Route $route): Collection
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$ids = explode(',', $value);
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use Illuminate\Routing\Route;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
@@ -31,15 +32,15 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class CurrencyCode implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public static function routeBinder($value, $route)
|
||||
public static function routeBinder(string $value, Route $route): TransactionCurrency
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$currency = TransactionCurrency::where('code', $value)->first();
|
||||
$currency = TransactionCurrency::where('code', trim($value))->first();
|
||||
if (null !== $currency) {
|
||||
return $currency;
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ namespace FireflyIII\Support\Binder;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Helpers\FiscalHelper;
|
||||
use Illuminate\Routing\Route;
|
||||
use Log;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -34,12 +35,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class Date implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
* @return Carbon
|
||||
*/
|
||||
public static function routeBinder($value, $route): Carbon
|
||||
public static function routeBinder(string $value, Route $route): Carbon
|
||||
{
|
||||
$fiscalHelper = new FiscalHelper;
|
||||
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -32,12 +33,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class JournalList implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function routeBinder($value, $route): Collection
|
||||
public static function routeBinder(string $value, Route $route): Collection
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$ids = explode(',', $value);
|
||||
|
@@ -24,6 +24,7 @@ namespace FireflyIII\Support\Binder;
|
||||
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -33,12 +34,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class TagList implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
* @return Collection
|
||||
*/
|
||||
public static function routeBinder($value, $route): Collection
|
||||
public static function routeBinder(string $value, Route $route): Collection
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$tags = explode(',', $value);
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Routing\Route;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
@@ -31,20 +32,20 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
class UnfinishedJournal implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return mixed
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public static function routeBinder($value, $route): TransactionJournal
|
||||
public static function routeBinder(string $value, Route $route): TransactionJournal
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$object = TransactionJournal::where('transaction_journals.id', $value)
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->where('completed', 0)
|
||||
->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
|
||||
if ($object) {
|
||||
return $object;
|
||||
$journal = auth()->user()->transactionJournals()->where('transaction_journals.id', $value)
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->where('completed', 0)
|
||||
->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
|
||||
if (!is_null($journal)) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user