Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -64,7 +64,7 @@ class AccountController extends Controller
return $next($request);
}
);
$this->balanceTypes = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE,];
$this->balanceTypes = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
}
/**
@@ -76,9 +76,6 @@ class AccountController extends Controller
* 4. Endpoint is documented.
* 5. Collector uses user_group_id
*
* @param AutocompleteRequest $request
*
* @return JsonResponse
* @throws FireflyException
* @throws FireflyException
*/
@@ -92,6 +89,7 @@ class AccountController extends Controller
$defaultCurrency = app('amount')->getDefaultCurrency();
$groupedResult = [];
$allItems = [];
/** @var Account $account */
foreach ($result as $account) {
$nameWithBalance = $account->name;
@@ -131,6 +129,7 @@ class AccountController extends Controller
return $posLeft - $posRight;
}
);
return response()->json($allItems);
}
}

View File

@@ -64,9 +64,6 @@ class TransactionController extends Controller
* 3. Request includes user_group_id
* 4. Endpoint is documented.
* 5. Collector uses user_group_id
*
*
* @return JsonResponse
*/
public function transactionDescriptions(AutocompleteRequest $request): JsonResponse
{
@@ -88,7 +85,5 @@ class TransactionController extends Controller
}
return response()->json($array);
}
}

View File

@@ -49,9 +49,6 @@ class AccountController extends Controller
private AccountRepositoryInterface $repository;
/**
*
*/
public function __construct()
{
parent::__construct();
@@ -79,18 +76,17 @@ class AccountController extends Controller
*
* TODO validate and set user_group_id from request
*
* @param DashboardChartRequest $request
*
* @return JsonResponse
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function dashboard(DashboardChartRequest $request): JsonResponse
{
/** @var Carbon $start */
$start = $this->parameters->get('start');
/** @var Carbon $end */
$end = $this->parameters->get('end');
$end->endOfDay();
@@ -98,6 +94,7 @@ class AccountController extends Controller
/** @var TransactionCurrency $default */
$default = app('amount')->getDefaultCurrency();
$params = $request->getAll();
/** @var Collection $accounts */
$accounts = $params['accounts'];
$chartData = [];
@@ -174,5 +171,4 @@ class AccountController extends Controller
return response()->json($this->clean($chartData));
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* BalanceController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -34,7 +33,6 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use FireflyIII\Support\Http\Api\AccountBalanceGrouped;
use FireflyIII\Support\Http\Api\CleansChartData;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
@@ -57,21 +55,22 @@ class BalanceController extends Controller
* TODO validate and set user_group_id
* TODO collector set group, not user
*
* @param BalanceChartRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function balance(BalanceChartRequest $request): JsonResponse
{
$params = $request->getAll();
/** @var Carbon $start */
$start = $this->parameters->get('start');
/** @var Carbon $end */
$end = $this->parameters->get('end');
$end->endOfDay();
/** @var Collection $accounts */
$accounts = $params['accounts'];
/** @var string $preferredRange */
$preferredRange = $params['period'];
@@ -99,5 +98,4 @@ class BalanceController extends Controller
return response()->json($this->clean($chartData));
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* BudgetController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -81,34 +80,32 @@ class BudgetController extends Controller
*
* TODO see autocomplete/accountcontroller
*
* @return JsonResponse
* @throws FireflyException
*/
public function dashboard(DateRequest $request): JsonResponse
{
$params = $request->getAll();
/** @var Carbon $start */
$start = $params['start'];
/** @var Carbon $end */
$end = $params['end'];
// code from FrontpageChartGenerator, but not in separate class
$budgets = $this->repository->getActiveBudgets();
$data = [];
/** @var Budget $budget */
foreach ($budgets as $budget) {
// could return multiple arrays, so merge.
$data = array_merge($data, $this->processBudget($budget, $start, $end));
}
return response()->json($this->clean($data));
}
/**
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @throws FireflyException
*/
private function processBudget(Budget $budget, Carbon $start, Carbon $end): array
@@ -154,6 +151,7 @@ class BudgetController extends Controller
];
$return[] = $current;
}
return $return;
}
@@ -161,16 +159,12 @@ class BudgetController extends Controller
* When no budget limits are present, the expenses of the whole period are collected and grouped.
* This is grouped per currency. Because there is no limit set, "left to spend" and "overspent" are empty.
*
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @throws FireflyException
*/
private function noBudgetLimits(Budget $budget, Carbon $start, Carbon $end): array
{
$spent = $this->opsRepository->listExpenses($start, $end, null, new Collection([$budget]));
return $this->processExpenses($budget->id, $spent, $start, $end);
}
@@ -179,10 +173,6 @@ class BudgetController extends Controller
*
* Will take a single set of expenses and return its info.
*
* @param int $budgetId
* @param array $array
*
* @return array
* @throws FireflyException
*/
private function processExpenses(int $budgetId, array $array, Carbon $start, Carbon $end): array
@@ -218,13 +208,12 @@ class BudgetController extends Controller
'native_left' => '0',
'overspent' => '0',
'native_overspent' => '0',
];
$currentBudgetArray = $block['budgets'][$budgetId];
//var_dump($return);
// var_dump($return);
/** @var array $journal */
foreach ($currentBudgetArray['transaction_journals'] as $journal) {
// convert the amount to the native currency.
$rate = $converter->getCurrencyRate($this->currencies[$currencyId], $this->currency, $journal['date']);
$convertedAmount = bcmul($journal['amount'], $rate);
@@ -236,6 +225,7 @@ class BudgetController extends Controller
$return[$currencyId]['native_spent'] = bcadd($return[$currencyId]['native_spent'], $convertedAmount);
}
}
return $return;
}
@@ -247,16 +237,13 @@ class BudgetController extends Controller
*
* If you have a budget limit in EUR, and a transaction in GBP, it will not be considered for the EUR budget limit.
*
* @param Budget $budget
* @param Collection $limits
*
* @return array
* @throws FireflyException
*/
private function budgetLimits(Budget $budget, Collection $limits): array
{
app('log')->debug(sprintf('Now in budgetLimits(#%d)', $budget->id));
$data = [];
/** @var BudgetLimit $limit */
foreach ($limits as $limit) {
$data = array_merge($data, $this->processLimit($budget, $limit));
@@ -266,10 +253,6 @@ class BudgetController extends Controller
}
/**
* @param Budget $budget
* @param BudgetLimit $limit
*
* @return array
* @throws FireflyException
*/
private function processLimit(Budget $budget, BudgetLimit $limit): array
@@ -284,7 +267,6 @@ class BudgetController extends Controller
$rate = $converter->getCurrencyRate($limitCurrency, $this->currency, $limit->start_date);
$convertedLimitAmount = bcmul($limit->amount, $rate);
/** @var array $entry */
foreach ($spent as $currencyId => $entry) {
// only spent the entry where the entry's currency matches the budget limit's currency
@@ -306,8 +288,7 @@ class BudgetController extends Controller
$result[$limitCurrencyId]['native_overspent'] = app('steam')->positive(bcadd($convertedLimitAmount, $result[$limitCurrencyId]['native_spent']));
}
}
return $result;
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* CategoryController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -61,6 +60,7 @@ class CategoryController extends Controller
if (null !== $userGroup) {
$this->accountRepos->setUserGroup($userGroup);
}
return $next($request);
}
);
@@ -70,16 +70,15 @@ class CategoryController extends Controller
* TODO may be worth to move to a handler but the data is simple enough.
* TODO see autoComplete/account controller
*
* @param DateRequest $request
*
* @return JsonResponse
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function dashboard(DateRequest $request): JsonResponse
{
/** @var Carbon $start */
$start = $this->parameters->get('start');
/** @var Carbon $end */
$end = $this->parameters->get('end');
$accounts = $this->accountRepos->getAccountsByType([AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::ASSET, AccountType::DEFAULT]);
@@ -128,7 +127,6 @@ class CategoryController extends Controller
'native_amount' => '0',
];
// add monies
$return[$key]['amount'] = bcadd($return[$key]['amount'], $amount);
$return[$key]['native_amount'] = bcadd($return[$key]['native_amount'], $nativeAmount);
@@ -139,7 +137,7 @@ class CategoryController extends Controller
usort($return, static function (array $a, array $b) {
return (float)$a['native_amount'] < (float)$b['native_amount'] ? 1 : -1;
});
return response()->json($this->clean($return));
}
}

View File

@@ -53,9 +53,6 @@ class Controller extends BaseController
protected const string CONTENT_TYPE = 'application/vnd.api+json';
protected ParameterBag $parameters;
/**
*
*/
public function __construct()
{
$this->middleware(
@@ -65,22 +62,57 @@ class Controller extends BaseController
return $next($request);
}
);
}
final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array
{
$manager = new Manager();
$baseUrl = request()->getSchemeAndHttpHost().'/api/v2';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
$objects = $paginator->getCollection();
// the transformer, at this point, needs to collect information that ALL items in the collection
// require, like meta-data and stuff like that, and save it for later.
$transformer->collectMetaData($objects);
$resource = new FractalCollection($objects, $transformer, $key);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $manager->createData($resource)->toArray();
}
/**
* Returns a JSON API object and returns it.
*
* @param Model $object
*/
final protected function jsonApiObject(string $key, array|Model $object, AbstractTransformer $transformer): array
{
// create some objects:
$manager = new Manager();
$baseUrl = request()->getSchemeAndHttpHost().'/api/v2';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
$transformer->collectMetaData(new Collection([$object]));
$resource = new Item($object, $transformer, $key);
return $manager->createData($resource)->toArray();
}
/**
* TODO duplicate from V1 controller
* Method to grab all parameters from the URL.
*
* @return ParameterBag
*/
private function getParameters(): ParameterBag
{
$bag = new ParameterBag();
$bag->set('limit', 50);
try {
$page = (int)request()->get('page');
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) {
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
$page = 1;
}
@@ -99,6 +131,7 @@ class Controller extends BaseController
foreach ($dates as $field) {
$date = null;
$obj = null;
try {
$date = request()->query->get($field);
} catch (BadRequestException $e) {
@@ -109,7 +142,7 @@ class Controller extends BaseController
if (null !== $date) {
try {
$obj = Carbon::parse((string)$date, config('app.timezone'));
} catch (InvalidDateException | InvalidFormatException $e) {
} catch (InvalidDateException|InvalidFormatException $e) {
// don't care
app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', substr((string)$date, 0, 20), $e->getMessage()));
}
@@ -146,52 +179,4 @@ class Controller extends BaseController
return $bag;
}
/**
* @param string $key
* @param LengthAwarePaginator $paginator
* @param AbstractTransformer $transformer
*
* @return array
*/
final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array
{
$manager = new Manager();
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v2';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
$objects = $paginator->getCollection();
// the transformer, at this point, needs to collect information that ALL items in the collection
// require, like meta-data and stuff like that, and save it for later.
$transformer->collectMetaData($objects);
$resource = new FractalCollection($objects, $transformer, $key);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $manager->createData($resource)->toArray();
}
/**
* Returns a JSON API object and returns it.
*
* @param string $key
* @param Model $object
* @param AbstractTransformer $transformer
*
* @return array
*/
final protected function jsonApiObject(string $key, array | Model $object, AbstractTransformer $transformer): array
{
// create some objects:
$manager = new Manager();
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v2';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
$transformer->collectMetaData(new Collection([$object]));
$resource = new Item($object, $transformer, $key);
return $manager->createData($resource)->toArray();
}
}

View File

@@ -29,6 +29,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
/**
* Class AccountController
*/
class AccountController extends Controller
{
}
class AccountController extends Controller {}

View File

@@ -29,6 +29,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
/**
* Class AccountController
*/
class AccountController extends Controller
{
}
class AccountController extends Controller {}

View File

@@ -29,6 +29,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
/**
* Class AccountController
*/
class AccountController extends Controller
{
}
class AccountController extends Controller {}

View File

@@ -46,6 +46,7 @@ class ShowController extends Controller
return response()
->api($this->jsonApiObject('accounts', $account, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* ShowController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -60,10 +59,7 @@ class IndexController extends Controller
}
/**
*
* TODO see autocomplete/accountcontroller for list.
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
@@ -78,6 +74,7 @@ class IndexController extends Controller
return response()
->json($this->jsonApiList('subscriptions', $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* ShowController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -69,6 +68,7 @@ class ShowController extends Controller
return response()
->api($this->jsonApiObject('subscriptions', $bill, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -39,9 +39,6 @@ class SumController extends Controller
private BillRepositoryInterface $repository;
/**
*
*/
public function __construct()
{
parent::__construct();
@@ -54,7 +51,6 @@ class SumController extends Controller
$this->repository->setUserGroup($userGroup);
}
return $next($request);
}
);
@@ -66,9 +62,6 @@ class SumController extends Controller
*
* TODO see autocomplete/accountcontroller for list.
*
* @param DateRequest $request
*
* @return JsonResponse
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function paid(DateRequest $request): JsonResponse
@@ -85,10 +78,7 @@ class SumController extends Controller
*
* TODO see autocomplete/accountcontroller for list.
*
* @param DateRequest $request
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return JsonResponse
*/
public function unpaid(DateRequest $request): JsonResponse
{

View File

@@ -52,9 +52,6 @@ class IndexController extends Controller
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/budgets/listBudgets
*
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
@@ -68,6 +65,7 @@ class IndexController extends Controller
return response()
->api($this->jsonApiList('budgets', $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* ShowController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -39,9 +38,6 @@ class ShowController extends Controller
{
private BudgetRepositoryInterface $repository;
/**
*
*/
public function __construct()
{
parent::__construct();
@@ -60,7 +56,6 @@ class ShowController extends Controller
*
* This endpoint is documented at:
* TODO add URL
*
*/
public function budgeted(DateRequest $request, Budget $budget): JsonResponse
{
@@ -73,7 +68,6 @@ class ShowController extends Controller
/**
* This endpoint is documented at:
* TODO add URL
*
*/
public function spent(DateRequest $request, Budget $budget): JsonResponse
{

View File

@@ -36,9 +36,6 @@ class SumController extends Controller
{
private BudgetRepositoryInterface $repository;
/**
*
*/
public function __construct()
{
parent::__construct();
@@ -54,10 +51,6 @@ class SumController extends Controller
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/budgets/getBudgetedForBudget
*
* @param DateRequest $request
*
* @return JsonResponse
*/
public function budgeted(DateRequest $request): JsonResponse
{
@@ -70,10 +63,6 @@ class SumController extends Controller
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/budgets/getSpentForBudget
*
* @param DateRequest $request
*
* @return JsonResponse
*/
public function spent(DateRequest $request): JsonResponse
{

View File

@@ -53,8 +53,6 @@ class IndexController extends Controller
* TODO This endpoint is not yet documented.
*
* Display a listing of the resource.
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
@@ -68,7 +66,7 @@ class IndexController extends Controller
return response()
->json($this->jsonApiList('currencies', $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* ShowController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -60,8 +59,6 @@ class IndexController extends Controller
/**
* TODO see autocomplete/accountcontroller for list.
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
@@ -75,6 +72,7 @@ class IndexController extends Controller
return response()
->json($this->jsonApiList('piggy-banks', $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* StoreController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -55,6 +54,7 @@ class StoreController extends Controller
$this->middleware(
function ($request, $next) {
$this->groupRepository = app(TransactionGroupRepositoryInterface::class);
return $next($request);
}
);
@@ -63,13 +63,11 @@ class StoreController extends Controller
/**
* TODO this method is practically the same as the V1 method and borrows as much code as possible.
*
* @return JsonResponse
* @throws FireflyException
* @throws ValidationException
*/
public function post(StoreRequest $request): JsonResponse
{
app('log')->debug('Now in API v2 StoreController::store()');
$data = $request->getAll();
$userGroup = $request->getUserGroup();
@@ -88,12 +86,14 @@ class StoreController extends Controller
['transactions' => [['description' => $e->getMessage()]]],
['transactions.0.description' => new IsDuplicateTransaction()]
);
throw new ValidationException($validator); // @phpstan-ignore-line
} catch (FireflyException $e) { // @phpstan-ignore-line
app('log')->warning('Caught an exception. Return error message.');
app('log')->error($e->getMessage());
$message = sprintf('Internal exception: %s', $e->getMessage());
$validator = Validator::make(['transactions' => [['description' => $message]]], ['transactions.0.description' => new IsDuplicateTransaction()]);
throw new ValidationException($validator); // @phpstan-ignore-line
}
app('preferences')->mark();
@@ -103,13 +103,15 @@ class StoreController extends Controller
/** @var User $admin */
$admin = auth()->user();
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on transaction group.
->setTransactionGroup($transactionGroup);
->setTransactionGroup($transactionGroup)
;
$selectedGroup = $collector->getGroups()->first();
if (null === $selectedGroup) {
@@ -121,8 +123,7 @@ class StoreController extends Controller
return response()
->api($this->jsonApiObject('transactions', $selectedGroup, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -29,6 +29,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
/**
* Class AccountController
*/
class AccountController extends Controller
{
}
class AccountController extends Controller {}

View File

@@ -25,7 +25,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V2\Controllers\Summary;
use Carbon\Carbon;
use Exception;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Generic\DateRequest;
use FireflyIII\Exceptions\FireflyException;
@@ -63,8 +62,6 @@ class BasicController extends Controller
/**
* BasicController constructor.
*
*/
public function __construct()
{
@@ -96,10 +93,8 @@ class BasicController extends Controller
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/summary/getBasicSummary
*
* @param DateRequest $request
* @throws \Exception
*
* @return JsonResponse
* @throws Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function basic(DateRequest $request): JsonResponse
@@ -114,14 +109,28 @@ class BasicController extends Controller
$spentData = $this->getLeftToSpendInfo($start, $end);
$netWorthData = $this->getNetWorthInfo($start, $end);
$total = array_merge($balanceData, $billData, $spentData, $netWorthData);
return response()->json($total);
}
/**
* @param Carbon $start
* @param Carbon $end
*
* @return array
* Check if date is outside session range.
*/
protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
{
$result = false;
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
$result = true;
}
// start and end in the past? use $end
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
$result = true;
}
return $result;
}
/**
* @throws FireflyException
*/
private function getBalanceInformation(Carbon $start, Carbon $end): array
@@ -130,6 +139,7 @@ class BasicController extends Controller
$default = app('amount')->getDefaultCurrency();
$object->setDefault($default);
/** @var User $user */
$user = auth()->user();
@@ -143,12 +153,12 @@ class BasicController extends Controller
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes([TransactionType::DEPOSIT])
->setRange($start, $end);
->setRange($start, $end)
;
$set = $collector->getExtractedJournals();
$object->groupTransactions('income', $set);
// collect expenses of user using the new group collector.
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@@ -159,19 +169,14 @@ class BasicController extends Controller
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes([TransactionType::WITHDRAWAL])
->setRange($start, $end);
->setRange($start, $end)
;
$set = $collector->getExtractedJournals();
$object->groupTransactions('expense', $set);
return $object->groupData();
}
/**
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function getBillInformation(Carbon $start, Carbon $end): array
{
/*
@@ -182,6 +187,7 @@ class BasicController extends Controller
$unpaidAmount = $this->billRepository->sumUnpaidInRange($start, $end);
$return = [];
/**
* @var array $info
*/
@@ -234,11 +240,7 @@ class BasicController extends Controller
}
/**
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @throws Exception
* @throws \Exception
*/
private function getLeftToSpendInfo(Carbon $start, Carbon $end): array
{
@@ -279,10 +281,12 @@ class BasicController extends Controller
$currencyId = $currencyId;
$spent = '0';
$spentNative = '0';
// get the sum from the array of transactions (double loop but who cares)
/** @var array $budget */
foreach ($row['budgets'] as $budget) {
app('log')->debug(sprintf('Processing expenses in budget "%s".', $budget['name']));
/** @var array $journal */
foreach ($budget['transaction_journals'] as $journal) {
$journalCurrencyId = $journal['currency_id'];
@@ -351,12 +355,6 @@ class BasicController extends Controller
return $return;
}
/**
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function getNetWorthInfo(Carbon $start, Carbon $end): array
{
/** @var UserGroup $userGroup */
@@ -411,28 +409,4 @@ class BasicController extends Controller
return $return;
}
/**
* Check if date is outside session range.
*
* @param Carbon $date
*
* @param Carbon $start
* @param Carbon $end
*
* @return bool
*/
protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
{
$result = false;
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
$result = true;
}
// start and end in the past? use $end
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
$result = true;
}
return $result;
}
}

View File

@@ -43,9 +43,6 @@ class NetWorthController extends Controller
private NetWorthInterface $netWorth;
private AccountRepositoryInterface $repository;
/**
*
*/
public function __construct()
{
parent::__construct();
@@ -68,10 +65,6 @@ class NetWorthController extends Controller
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/net-worth/getNetWorth
*
* @param SingleDateRequest $request
*
* @return JsonResponse
*/
public function get(SingleDateRequest $request): JsonResponse
{

View File

@@ -27,6 +27,4 @@ namespace FireflyIII\Api\V2\Controllers\System;
/**
* Class ConfigurationController
*/
class ConfigurationController
{
}
class ConfigurationController {}

View File

@@ -29,6 +29,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
/**
* Class DebugController
*/
class DebugController extends Controller
{
}
class DebugController extends Controller {}

View File

@@ -37,15 +37,12 @@ class PreferencesController extends Controller
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/preferences/getPreference
*
* @param Preference $preference
*
* @return JsonResponse
*/
public function get(Preference $preference): JsonResponse
{
return response()
->json($this->jsonApiObject('preferences', $preference, new PreferenceTransformer()))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -29,6 +29,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
/**
* Class VersionUpdateController
*/
class VersionUpdateController extends Controller
{
}
class VersionUpdateController extends Controller {}

View File

@@ -43,11 +43,6 @@ class AccountController extends Controller
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/accounts/listTransactionByAccount
*
* @param ListRequest $request
* @param Account $account
*
* @return JsonResponse
*/
public function list(ListRequest $request, Account $account): JsonResponse
{
@@ -56,14 +51,14 @@ class AccountController extends Controller
$page = max($page, 1);
$pageSize = $this->parameters->get('limit');
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))
->withAPIInformation()
->setLimit($pageSize)
->setPage($page)
->setTypes($request->getTransactionTypes());
->withAPIInformation()
->setLimit($pageSize)
->setPage($page)
->setTypes($request->getTransactionTypes())
;
$start = $request->getStartDate();
$end = $request->getEndDate();
@@ -87,6 +82,7 @@ class AccountController extends Controller
return response()
->json($this->jsonApiList('transactions', $paginator, new TransactionGroupTransformer()))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -34,11 +34,6 @@ use Illuminate\Http\JsonResponse;
*/
class TransactionController extends Controller
{
/**
* @param ListRequest $request
*
* @return JsonResponse
*/
public function list(ListRequest $request): JsonResponse
{
// collect transactions:
@@ -46,14 +41,14 @@ class TransactionController extends Controller
$page = $request->getPage();
$page = max($page, 1);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUserGroup(auth()->user()->userGroup)
->withAPIInformation()
->setLimit($pageSize)
->setPage($page)
->setTypes($request->getTransactionTypes());
->withAPIInformation()
->setLimit($pageSize)
->setPage($page)
->setTypes($request->getTransactionTypes())
;
$start = $this->parameters->get('start');
$end = $this->parameters->get('end');
@@ -79,8 +74,7 @@ class TransactionController extends Controller
return response()
->json($this->jsonApiList('transactions', $paginator, new TransactionGroupTransformer()))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -29,6 +29,4 @@ use FireflyIII\Api\V2\Controllers\Controller;
/**
* Class BillController
*/
class BillController extends Controller
{
}
class BillController extends Controller {}

View File

@@ -1,6 +1,5 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -40,9 +39,6 @@ class DestroyController extends Controller
{
private UserGroupRepositoryInterface $repository;
/**
*
*/
public function __construct()
{
parent::__construct();
@@ -55,11 +51,6 @@ class DestroyController extends Controller
);
}
/**
* @param UserGroup $userGroup
*
* @return JsonResponse
*/
public function destroy(UserGroup $userGroup): JsonResponse
{
/** @var User $user */
@@ -71,6 +62,7 @@ class DestroyController extends Controller
throw new NotFoundHttpException();
}
$this->repository->destroy($userGroup);
return response()->json([], 204);
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* ShowController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -40,9 +39,6 @@ class ShowController extends Controller
{
private UserGroupRepositoryInterface $repository;
/**
*
*/
public function __construct()
{
parent::__construct();
@@ -55,9 +51,6 @@ class ShowController extends Controller
);
}
/**
* @return JsonResponse
*/
public function index(): JsonResponse
{
$collection = new Collection();
@@ -78,14 +71,10 @@ class ShowController extends Controller
return response()
->json($this->jsonApiList('user-groups', $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
/**
* @param UserGroup $userGroup
*
* @return JsonResponse
*/
public function show(UserGroup $userGroup): JsonResponse
{
$transformer = new UserGroupTransformer();
@@ -93,6 +82,7 @@ class ShowController extends Controller
return response()
->api($this->jsonApiObject('user-groups', $userGroup, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* StoreController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -38,9 +37,6 @@ class StoreController extends Controller
{
private UserGroupRepositoryInterface $repository;
/**
*
*/
public function __construct()
{
parent::__construct();
@@ -53,11 +49,6 @@ class StoreController extends Controller
);
}
/**
* @param StoreRequest $request
*
* @return JsonResponse
*/
public function store(StoreRequest $request): JsonResponse
{
$all = $request->getAll();
@@ -67,7 +58,7 @@ class StoreController extends Controller
return response()
->api($this->jsonApiObject('user-groups', $userGroup, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -43,9 +42,6 @@ class UpdateController extends Controller
private UserGroupRepositoryInterface $repository;
/**
*
*/
public function __construct()
{
parent::__construct();
@@ -58,12 +54,6 @@ class UpdateController extends Controller
);
}
/**
* @param UpdateRequest $request
* @param UserGroup $userGroup
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, UserGroup $userGroup): JsonResponse
{
$all = $request->getAll();
@@ -73,15 +63,10 @@ class UpdateController extends Controller
return response()
->api($this->jsonApiObject('user-groups', $userGroup, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
/**
* @param UpdateMembershipRequest $request
* @param UserGroup $userGroup
*
* @return JsonResponse
*/
public function updateMembership(UpdateMembershipRequest $request, UserGroup $userGroup): JsonResponse
{
$all = $request->getAll();
@@ -91,6 +76,7 @@ class UpdateController extends Controller
return response()
->api($this->jsonApiObject('user-groups', $userGroup, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -39,9 +39,6 @@ class AutocompleteRequest extends FormRequest
protected array $acceptedRoles = [UserRoleEnum::MANAGE_TRANSACTIONS];
/**
* @return array
*/
public function getData(): array
{
$types = $this->convertString('types');
@@ -63,9 +60,6 @@ class AutocompleteRequest extends FormRequest
];
}
/**
* @return array
*/
public function rules(): array
{
return [

View File

@@ -1,6 +1,5 @@
<?php
/*
* BalanceChartRequest.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -42,8 +41,6 @@ class BalanceChartRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -55,8 +52,6 @@ class BalanceChartRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -68,11 +63,6 @@ class BalanceChartRequest extends FormRequest
];
}
/**
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
@@ -81,6 +71,7 @@ class BalanceChartRequest extends FormRequest
$data = $validator->getData();
if (!array_key_exists('accounts', $data)) {
$validator->errors()->add('accounts', trans('validation.filled', ['attribute' => 'accounts']));
return;
}
if (!is_array($data['accounts'])) {

View File

@@ -40,8 +40,6 @@ class DashboardChartRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -53,8 +51,6 @@ class DashboardChartRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -66,11 +62,6 @@ class DashboardChartRequest extends FormRequest
];
}
/**
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
@@ -78,7 +69,7 @@ class DashboardChartRequest extends FormRequest
// validate transaction query data.
$data = $validator->getData();
if (!array_key_exists('accounts', $data)) {
//$validator->errors()->add('accounts', trans('validation.filled', ['attribute' => 'accounts']));
// $validator->errors()->add('accounts', trans('validation.filled', ['attribute' => 'accounts']));
return;
}
if (!is_array($data['accounts'])) {

View File

@@ -40,8 +40,6 @@ class DateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -53,8 +51,6 @@ class DateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -41,8 +41,6 @@ class SingleDateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return Carbon
*/
public function getDate(): Carbon
{
@@ -51,8 +49,6 @@ class SingleDateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -40,9 +40,6 @@ class ListRequest extends FormRequest
use ConvertsDataTypes;
use TransactionFilter;
/**
* @return string
*/
public function buildParams(int $pageSize): string
{
$array = [
@@ -56,46 +53,34 @@ class ListRequest extends FormRequest
$array['start'] = $start->format('Y-m-d');
$array['end'] = $end->format('Y-m-d');
}
return http_build_query($array);
}
/**
* @return int
*/
public function getPage(): int
{
$page = $this->convertInteger('page');
return 0 === $page || $page > 65536 ? 1 : $page;
}
/**
* @return Carbon|null
*/
public function getStartDate(): ?Carbon
{
return $this->getCarbonDate('start');
}
/**
* @return Carbon|null
*/
public function getEndDate(): ?Carbon
{
return $this->getCarbonDate('end');
}
/**
* @return array
*/
public function getTransactionTypes(): array
{
$type = (string)$this->get('type', 'default');
return $this->mapTransactionTypes($type);
}
/**
* @return array
*/
public function rules(): array
{
return [

View File

@@ -62,8 +62,6 @@ class StoreRequest extends FormRequest
/**
* Get all data.
*
* @return array
*/
public function getAll(): array
{
@@ -79,107 +77,8 @@ class StoreRequest extends FormRequest
// TODO include location and ability to process it.
}
/**
* Get transaction data.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
/**
* @var array $transaction
*/
foreach ($this->get('transactions') as $transaction) {
$object = new NullArrayObject($transaction);
$return[] = [
'type' => $this->clearString($object['type']),
'date' => $this->dateFromValue($object['date']),
'order' => $this->integerFromValue((string)$object['order']),
'currency_id' => $this->integerFromValue((string)$object['currency_id']),
'currency_code' => $this->clearString((string)$object['currency_code']),
// foreign currency info:
'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
'foreign_currency_code' => $this->clearString((string)$object['foreign_currency_code']),
// amount and foreign amount. Cannot be 0.
'amount' => $this->clearString((string)$object['amount']),
'foreign_amount' => $this->clearString((string)$object['foreign_amount']),
// description.
'description' => $this->clearString($object['description']),
// source of transaction. If everything is null, assume cash account.
'source_id' => $this->integerFromValue((string)$object['source_id']),
'source_name' => $this->clearString((string)$object['source_name']),
'source_iban' => $this->clearString((string)$object['source_iban']),
'source_number' => $this->clearString((string)$object['source_number']),
'source_bic' => $this->clearString((string)$object['source_bic']),
// destination of transaction. If everything is null, assume cash account.
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
'destination_name' => $this->clearString((string)$object['destination_name']),
'destination_iban' => $this->clearString((string)$object['destination_iban']),
'destination_number' => $this->clearString((string)$object['destination_number']),
'destination_bic' => $this->clearString((string)$object['destination_bic']),
// budget info
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
'budget_name' => $this->clearString((string)$object['budget_name']),
// category info
'category_id' => $this->integerFromValue((string)$object['category_id']),
'category_name' => $this->clearString((string)$object['category_name']),
// journal bill reference. Optional. Will only work for withdrawals
'bill_id' => $this->integerFromValue((string)$object['bill_id']),
'bill_name' => $this->clearString((string)$object['bill_name']),
// piggy bank reference. Optional. Will only work for transfers
'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
'piggy_bank_name' => $this->clearString((string)$object['piggy_bank_name']),
// some other interesting properties
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
'notes' => $this->clearStringKeepNewlines((string)$object['notes']),
'tags' => $this->arrayFromValue($object['tags']),
// all custom fields:
'internal_reference' => $this->clearString((string)$object['internal_reference']),
'external_id' => $this->clearString((string)$object['external_id']),
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
'bunq_payment_id' => $this->clearString((string)$object['bunq_payment_id']),
'external_url' => $this->clearString((string)$object['external_url']),
'sepa_cc' => $this->clearString((string)$object['sepa_cc']),
'sepa_ct_op' => $this->clearString((string)$object['sepa_ct_op']),
'sepa_ct_id' => $this->clearString((string)$object['sepa_ct_id']),
'sepa_db' => $this->clearString((string)$object['sepa_db']),
'sepa_country' => $this->clearString((string)$object['sepa_country']),
'sepa_ep' => $this->clearString((string)$object['sepa_ep']),
'sepa_ci' => $this->clearString((string)$object['sepa_ci']),
'sepa_batch_id' => $this->clearString((string)$object['sepa_batch_id']),
// custom date fields. Must be Carbon objects. Presence is optional.
'interest_date' => $this->dateFromValue($object['interest_date']),
'book_date' => $this->dateFromValue($object['book_date']),
'process_date' => $this->dateFromValue($object['process_date']),
'due_date' => $this->dateFromValue($object['due_date']),
'payment_date' => $this->dateFromValue($object['payment_date']),
'invoice_date' => $this->dateFromValue($object['invoice_date']),
];
}
return $return;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -272,15 +171,12 @@ class StoreRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
/** @var User $user */
$user = auth()->user();
/** @var UserGroup $userGroup */
$userGroup = $this->getUserGroup();
$validator->after(
@@ -314,5 +210,98 @@ class StoreRequest extends FormRequest
);
}
/**
* Get transaction data.
*/
private function getTransactionData(): array
{
$return = [];
/**
* @var array $transaction
*/
foreach ($this->get('transactions') as $transaction) {
$object = new NullArrayObject($transaction);
$return[] = [
'type' => $this->clearString($object['type']),
'date' => $this->dateFromValue($object['date']),
'order' => $this->integerFromValue((string)$object['order']),
'currency_id' => $this->integerFromValue((string)$object['currency_id']),
'currency_code' => $this->clearString((string)$object['currency_code']),
// foreign currency info:
'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
'foreign_currency_code' => $this->clearString((string)$object['foreign_currency_code']),
// amount and foreign amount. Cannot be 0.
'amount' => $this->clearString((string)$object['amount']),
'foreign_amount' => $this->clearString((string)$object['foreign_amount']),
// description.
'description' => $this->clearString($object['description']),
// source of transaction. If everything is null, assume cash account.
'source_id' => $this->integerFromValue((string)$object['source_id']),
'source_name' => $this->clearString((string)$object['source_name']),
'source_iban' => $this->clearString((string)$object['source_iban']),
'source_number' => $this->clearString((string)$object['source_number']),
'source_bic' => $this->clearString((string)$object['source_bic']),
// destination of transaction. If everything is null, assume cash account.
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
'destination_name' => $this->clearString((string)$object['destination_name']),
'destination_iban' => $this->clearString((string)$object['destination_iban']),
'destination_number' => $this->clearString((string)$object['destination_number']),
'destination_bic' => $this->clearString((string)$object['destination_bic']),
// budget info
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
'budget_name' => $this->clearString((string)$object['budget_name']),
// category info
'category_id' => $this->integerFromValue((string)$object['category_id']),
'category_name' => $this->clearString((string)$object['category_name']),
// journal bill reference. Optional. Will only work for withdrawals
'bill_id' => $this->integerFromValue((string)$object['bill_id']),
'bill_name' => $this->clearString((string)$object['bill_name']),
// piggy bank reference. Optional. Will only work for transfers
'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
'piggy_bank_name' => $this->clearString((string)$object['piggy_bank_name']),
// some other interesting properties
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
'notes' => $this->clearStringKeepNewlines((string)$object['notes']),
'tags' => $this->arrayFromValue($object['tags']),
// all custom fields:
'internal_reference' => $this->clearString((string)$object['internal_reference']),
'external_id' => $this->clearString((string)$object['external_id']),
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
'bunq_payment_id' => $this->clearString((string)$object['bunq_payment_id']),
'external_url' => $this->clearString((string)$object['external_url']),
'sepa_cc' => $this->clearString((string)$object['sepa_cc']),
'sepa_ct_op' => $this->clearString((string)$object['sepa_ct_op']),
'sepa_ct_id' => $this->clearString((string)$object['sepa_ct_id']),
'sepa_db' => $this->clearString((string)$object['sepa_db']),
'sepa_country' => $this->clearString((string)$object['sepa_country']),
'sepa_ep' => $this->clearString((string)$object['sepa_ep']),
'sepa_ci' => $this->clearString((string)$object['sepa_ci']),
'sepa_batch_id' => $this->clearString((string)$object['sepa_batch_id']),
// custom date fields. Must be Carbon objects. Presence is optional.
'interest_date' => $this->dateFromValue($object['interest_date']),
'book_date' => $this->dateFromValue($object['book_date']),
'process_date' => $this->dateFromValue($object['process_date']),
'due_date' => $this->dateFromValue($object['due_date']),
'payment_date' => $this->dateFromValue($object['payment_date']),
'invoice_date' => $this->dateFromValue($object['invoice_date']),
];
}
return $return;
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* StoreRequest.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -40,9 +39,6 @@ class StoreRequest extends FormRequest
protected array $acceptedRoles = [UserRoleEnum::OWNER, UserRoleEnum::FULL];
/**
* @return array
*/
public function getAll(): array
{
return [
@@ -50,9 +46,6 @@ class StoreRequest extends FormRequest
];
}
/**
* @return array
*/
public function rules(): array
{
return [

View File

@@ -1,6 +1,5 @@
<?php
/*
* StoreRequest.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -40,9 +39,6 @@ class UpdateMembershipRequest extends FormRequest
protected array $acceptedRoles = [UserRoleEnum::OWNER, UserRoleEnum::FULL];
/**
* @return array
*/
public function getAll(): array
{
return [
@@ -52,19 +48,17 @@ class UpdateMembershipRequest extends FormRequest
];
}
/**
* @return array
*/
public function rules(): array
{
$validRoles = [];
foreach (UserRoleEnum::cases() as $role) {
$validRoles[] = $role->value;
}
return [
'id' => 'exists:users,id|required_without:email',
'email' => 'exists:users,email|required_without:id',
'roles.*' => 'required|in:' . implode(',', $validRoles),
'roles.*' => 'required|in:'.implode(',', $validRoles),
];
}
}

View File

@@ -1,6 +1,5 @@
<?php
/*
* StoreRequest.php
* Copyright (c) 2023 james@firefly-iii.org
@@ -41,9 +40,6 @@ class UpdateRequest extends FormRequest
protected array $acceptedRoles = [UserRoleEnum::OWNER, UserRoleEnum::FULL];
/**
* @return array
*/
public function getAll(): array
{
return [
@@ -51,13 +47,11 @@ class UpdateRequest extends FormRequest
];
}
/**
* @return array
*/
public function rules(): array
{
/** @var UserGroup $userGroup */
$userGroup = $this->route()->parameter('userGroup');
return [
'title' => sprintf('required|min:2|max:255|unique:user_groups,title,%d', $userGroup->id),
];

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V2\Response\Sum;
use Closure;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency;
use Illuminate\Database\Eloquent\Model;
@@ -38,20 +37,17 @@ use Illuminate\Support\Collection;
class AutoSum
{
/**
* @param Collection $objects
* @param Closure $getCurrency
* @param Closure $getSum
*
* @return array
* @throws FireflyException
*/
public function autoSum(Collection $objects, Closure $getCurrency, Closure $getSum): array
public function autoSum(Collection $objects, \Closure $getCurrency, \Closure $getSum): array
{
$return = [];
/** @var Model $object */
foreach ($objects as $object) {
/** @var TransactionCurrency $currency */
$currency = $getCurrency($object);
/** @var string $amount */
$amount = $getSum($object);
@@ -68,6 +64,7 @@ class AutoSum
}
var_dump(array_values($return));
throw new FireflyException('Not implemented');
}
}