. */ 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; /** * Class BudgetList. */ class BudgetList implements BinderInterface { /** * @param string $value * @param Route $route * * @return Collection * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public static function routeBinder(string $value, Route $route): Collection { if (auth()->check()) { $list = array_unique(array_map('\intval', explode(',', $value))); if (0 === \count($list)) { throw new NotFoundHttpException; // @codeCoverageIgnore } /** @var \Illuminate\Support\Collection $collection */ $collection = auth()->user()->budgets() ->where('active', 1) ->whereIn('id', $list) ->get(); // add empty budget if applicable. if (\in_array(0, $list, true)) { $collection->push(new Budget); } if ($collection->count() > 0) { return $collection; } } throw new NotFoundHttpException; } }