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

@@ -36,9 +36,6 @@ class AutocompleteRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getData(): array
{
$types = $this->convertString('types');
@@ -57,9 +54,6 @@ class AutocompleteRequest extends FormRequest
];
}
/**
* @return array
*/
public function rules(): array
{
return [

View File

@@ -38,9 +38,6 @@ class MoveTransactionsRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getAll(): array
{
return [
@@ -63,10 +60,8 @@ class MoveTransactionsRequest extends FormRequest
/**
* Configure the validator instance with special rules for after the basic validation rules.
*
* @param Validator $validator
* TODO this is duplicate.
*
* @return void
* @param validator $validator
* TODO this is duplicate
*/
public function withValidator(Validator $validator): void
{
@@ -81,11 +76,6 @@ class MoveTransactionsRequest extends FormRequest
);
}
/**
* @param Validator $validator
*
* @return void
*/
private function validateMove(Validator $validator): void
{
$data = $validator->getData();

View File

@@ -31,7 +31,6 @@ use FireflyIII\Support\Request\ConvertsDataTypes;
use FireflyIII\Validation\Api\Data\Bulk\ValidatesBulkTransactionQuery;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;
use JsonException;
/**
* Class TransactionRequest
@@ -42,17 +41,15 @@ class TransactionRequest extends FormRequest
use ConvertsDataTypes;
use ValidatesBulkTransactionQuery;
/**
* @return array
*/
public function getAll(): array
{
$data = [];
try {
$data = [
'query' => json_decode($this->get('query'), true, 8, JSON_THROW_ON_ERROR),
];
} catch (JsonException $e) {
} catch (\JsonException $e) {
// dont really care. the validation should catch invalid json.
app('log')->error($e->getMessage());
}
@@ -60,9 +57,6 @@ class TransactionRequest extends FormRequest
return $data;
}
/**
* @return array
*/
public function rules(): array
{
return [
@@ -70,11 +64,6 @@ class TransactionRequest extends FormRequest
];
}
/**
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(

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

@@ -37,8 +37,6 @@ class DestroyRequest extends FormRequest
/**
* Get all data from the request.
*
* @return string
*/
public function getObjects(): string
{
@@ -47,13 +45,11 @@ class DestroyRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$valid = 'budgets,bills,piggy_banks,rules,recurring,categories,tags,object_groups' .
',accounts,asset_accounts,expense_accounts,revenue_accounts,liabilities,transactions,withdrawals,deposits,transfers' .
$valid = 'budgets,bills,piggy_banks,rules,recurring,categories,tags,object_groups'.
',accounts,asset_accounts,expense_accounts,revenue_accounts,liabilities,transactions,withdrawals,deposits,transfers'.
',not_assets_liabilities';
return [

View File

@@ -38,9 +38,6 @@ class ExportRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getAll(): array
{
$result = [
@@ -69,8 +66,6 @@ class ExportRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

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

View File

@@ -53,8 +53,6 @@ class GenericRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -64,13 +62,11 @@ class GenericRequest extends FormRequest
];
}
/**
* @return Collection
*/
public function getAssetAccounts(): Collection
{
$this->parseAccounts();
$return = new Collection();
/** @var Account $account */
foreach ($this->accounts as $account) {
$type = $account->accountType->type;
@@ -82,9 +78,100 @@ class GenericRequest extends FormRequest
return $return;
}
public function getBills(): Collection
{
$this->parseBills();
return $this->bills;
}
public function getBudgets(): Collection
{
$this->parseBudgets();
return $this->budgets;
}
public function getCategories(): Collection
{
$this->parseCategories();
return $this->categories;
}
public function getEnd(): Carbon
{
$date = $this->getCarbonDate('end');
$date->endOfDay();
return $date;
}
public function getExpenseAccounts(): Collection
{
$this->parseAccounts();
$return = new Collection();
/** @var Account $account */
foreach ($this->accounts as $account) {
$type = $account->accountType->type;
if (AccountType::EXPENSE === $type) {
$return->push($account);
}
}
return $return;
}
public function getRevenueAccounts(): Collection
{
$this->parseAccounts();
$return = new Collection();
/** @var Account $account */
foreach ($this->accounts as $account) {
$type = $account->accountType->type;
if (AccountType::REVENUE === $type) {
$return->push($account);
}
}
return $return;
}
public function getStart(): Carbon
{
$date = $this->getCarbonDate('start');
$date->startOfDay();
return $date;
}
public function getTags(): Collection
{
$this->parseTags();
return $this->tags;
}
/**
*
* The rules that the incoming request must be matched against.
*/
public function rules(): array
{
// this is cheating, but it works to initialize the collections.
$this->accounts = new Collection();
$this->budgets = new Collection();
$this->categories = new Collection();
$this->bills = new Collection();
$this->tags = new Collection();
return [
'start' => 'required|date',
'end' => 'required|date|after_or_equal:start',
];
}
private function parseAccounts(): void
{
if (0 !== $this->accounts->count()) {
@@ -104,19 +191,6 @@ class GenericRequest extends FormRequest
}
}
/**
* @return Collection
*/
public function getBills(): Collection
{
$this->parseBills();
return $this->bills;
}
/**
*
*/
private function parseBills(): void
{
if (0 !== $this->bills->count()) {
@@ -136,19 +210,6 @@ class GenericRequest extends FormRequest
}
}
/**
* @return Collection
*/
public function getBudgets(): Collection
{
$this->parseBudgets();
return $this->budgets;
}
/**
*
*/
private function parseBudgets(): void
{
if (0 !== $this->budgets->count()) {
@@ -168,19 +229,6 @@ class GenericRequest extends FormRequest
}
}
/**
* @return Collection
*/
public function getCategories(): Collection
{
$this->parseCategories();
return $this->categories;
}
/**
*
*/
private function parseCategories(): void
{
if (0 !== $this->categories->count()) {
@@ -200,77 +248,6 @@ class GenericRequest extends FormRequest
}
}
/**
* @return Carbon
*/
public function getEnd(): Carbon
{
$date = $this->getCarbonDate('end');
$date->endOfDay();
return $date;
}
/**
* @return Collection
*/
public function getExpenseAccounts(): Collection
{
$this->parseAccounts();
$return = new Collection();
/** @var Account $account */
foreach ($this->accounts as $account) {
$type = $account->accountType->type;
if ($type === AccountType::EXPENSE) {
$return->push($account);
}
}
return $return;
}
/**
* @return Collection
*/
public function getRevenueAccounts(): Collection
{
$this->parseAccounts();
$return = new Collection();
/** @var Account $account */
foreach ($this->accounts as $account) {
$type = $account->accountType->type;
if ($type === AccountType::REVENUE) {
$return->push($account);
}
}
return $return;
}
/**
* @return Carbon
*/
public function getStart(): Carbon
{
$date = $this->getCarbonDate('start');
$date->startOfDay();
return $date;
}
/**
* @return Collection
*/
public function getTags(): Collection
{
$this->parseTags();
return $this->tags;
}
/**
*
*/
private function parseTags(): void
{
if (0 !== $this->tags->count()) {
@@ -289,24 +266,4 @@ class GenericRequest extends FormRequest
}
}
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
// this is cheating, but it works to initialize the collections.
$this->accounts = new Collection();
$this->budgets = new Collection();
$this->categories = new Collection();
$this->bills = new Collection();
$this->tags = new Collection();
return [
'start' => 'required|date',
'end' => 'required|date|after_or_equal:start',
];
}
}

View File

@@ -35,8 +35,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -44,9 +42,6 @@ class StoreRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getAllAccountData(): array
{
$active = true;
@@ -93,8 +88,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -104,7 +97,7 @@ class StoreRequest extends FormRequest
$type = $this->convertString('type');
$rules = [
'name' => 'required|max:1024|min:1|uniqueAccountForUser',
'type' => 'required|max:1024|min:1|' . sprintf('in:%s', $types),
'type' => 'required|max:1024|min:1|'.sprintf('in:%s', $types),
'iban' => ['iban', 'nullable', new UniqueIban(null, $type)],
'bic' => 'bic|nullable',
'account_number' => ['between:1,255', 'nullable', new UniqueAccountNumber(null, $type)],

View File

@@ -36,8 +36,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -45,9 +43,6 @@ class UpdateRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getUpdateData(): array
{
$fields = [
@@ -82,8 +77,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -109,7 +102,7 @@ class UpdateRequest extends FormRequest
'include_net_worth' => [new IsBoolean()],
'account_role' => sprintf('in:%s|nullable|required_if:type,asset', $accountRoles),
'credit_card_type' => sprintf('in:%s|nullable|required_if:account_role,ccAsset', $ccPaymentTypes),
'monthly_payment_date' => 'date' . '|nullable|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',
'monthly_payment_date' => 'date|nullable|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',
'liability_type' => 'required_if:type,liability|in:loan,debt,mortgage',
'liability_direction' => 'required_if:type,liability|in:credit,debit',
'interest' => 'required_if:type,liability|between:0,100|numeric',

View File

@@ -30,8 +30,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -40,8 +38,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -56,8 +52,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -30,8 +30,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -40,8 +38,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -58,8 +54,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -31,8 +31,6 @@ use Illuminate\Validation\Validator;
/**
* Class Request
*
*/
class Request extends FormRequest
{
@@ -41,8 +39,6 @@ class Request extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -60,8 +56,6 @@ class Request extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -76,10 +70,6 @@ class Request extends FormRequest
/**
* Configure the validator instance with special rules for after the basic validation rules.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{

View File

@@ -32,8 +32,6 @@ use Illuminate\Validation\Validator;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -42,8 +40,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -71,8 +67,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -94,10 +88,6 @@ class StoreRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{

View File

@@ -33,8 +33,6 @@ use Illuminate\Validation\Validator;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -43,8 +41,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -71,8 +67,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -97,10 +91,6 @@ class UpdateRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{

View File

@@ -32,8 +32,6 @@ use Illuminate\Validation\Validator;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -43,8 +41,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -67,8 +63,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -87,10 +81,6 @@ class StoreRequest extends FormRequest
/**
* Configure the validator instance with special rules for after the basic validation rules.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{

View File

@@ -33,8 +33,6 @@ use Illuminate\Validation\Validator;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -44,8 +42,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -77,8 +73,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -99,10 +93,6 @@ class UpdateRequest extends FormRequest
/**
* Configure the validator instance with special rules for after the basic validation rules.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{

View File

@@ -29,8 +29,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -39,8 +37,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -55,8 +51,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -31,8 +31,6 @@ use Illuminate\Validation\Validator;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -41,8 +39,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -59,8 +55,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -77,9 +71,7 @@ class UpdateRequest extends FormRequest
* Configure the validator instance with special rules for after the basic validation rules.
*
* @param Validator $validator
* TODO duplicate code
*
* @return void
* TODO duplicate code
*/
public function withValidator(Validator $validator): void
{

View File

@@ -23,15 +23,12 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\Category;
use FireflyIII\Rules\ZeroOrMore;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -40,8 +37,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -53,8 +48,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -30,8 +30,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -40,8 +38,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -55,8 +51,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -31,17 +31,12 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getUpdateData(): array
{
$fields = [
@@ -54,8 +49,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -29,8 +29,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -39,8 +37,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -63,8 +59,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -32,8 +32,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -42,8 +40,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -65,8 +61,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -74,7 +68,7 @@ class UpdateRequest extends FormRequest
$piggyBank = $this->route()->parameter('piggyBank');
return [
'name' => 'between:1,255|uniquePiggyBankForUser:' . $piggyBank->id,
'name' => 'between:1,255|uniquePiggyBankForUser:'.$piggyBank->id,
'current_amount' => ['numeric', 'gte:0', new LessThanPiggyTarget()],
'target_amount' => 'numeric|gte:0',
'start_date' => 'date|nullable',

View File

@@ -48,8 +48,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -73,69 +71,8 @@ class StoreRequest extends FormRequest
];
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
// transaction data:
/** @var array|null $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return [];
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleTransactionData($transaction);
}
return $return;
}
/**
* Returns the repetition data as it is found in the submitted data.
*
* @return array
*/
private function getRepetitionData(): array
{
$return = [];
// repetition data:
/** @var array|null $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return [];
}
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$current = [];
if (array_key_exists('type', $repetition)) {
$current['type'] = $repetition['type'];
}
if (array_key_exists('moment', $repetition)) {
$current['moment'] = $repetition['moment'];
}
if (array_key_exists('skip', $repetition)) {
$current['skip'] = (int)$repetition['skip'];
}
if (array_key_exists('weekend', $repetition)) {
$current['weekend'] = (int)$repetition['weekend'];
}
$return[] = $current;
}
return $return;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -179,10 +116,6 @@ class StoreRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
@@ -198,4 +131,63 @@ class StoreRequest extends FormRequest
}
);
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*/
private function getTransactionData(): array
{
$return = [];
// transaction data:
/** @var null|array $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return [];
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleTransactionData($transaction);
}
return $return;
}
/**
* Returns the repetition data as it is found in the submitted data.
*/
private function getRepetitionData(): array
{
$return = [];
// repetition data:
/** @var null|array $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return [];
}
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$current = [];
if (array_key_exists('type', $repetition)) {
$current['type'] = $repetition['type'];
}
if (array_key_exists('moment', $repetition)) {
$current['moment'] = $repetition['moment'];
}
if (array_key_exists('skip', $repetition)) {
$current['skip'] = (int)$repetition['skip'];
}
if (array_key_exists('weekend', $repetition)) {
$current['weekend'] = (int)$repetition['weekend'];
}
$return[] = $current;
}
return $return;
}
}

View File

@@ -49,8 +49,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -78,74 +76,8 @@ class UpdateRequest extends FormRequest
return $return;
}
/**
* Returns the repetition data as it is found in the submitted data.
*
* @return array|null
*/
private function getRepetitionData(): ?array
{
$return = [];
// repetition data:
/** @var array|null $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return null;
}
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$current = [];
if (array_key_exists('type', $repetition)) {
$current['type'] = $repetition['type'];
}
if (array_key_exists('moment', $repetition)) {
$current['moment'] = (string)$repetition['moment'];
}
if (array_key_exists('skip', $repetition)) {
$current['skip'] = (int)$repetition['skip'];
}
if (array_key_exists('weekend', $repetition)) {
$current['weekend'] = (int)$repetition['weekend'];
}
$return[] = $current;
}
if (0 === count($return)) {
return null;
}
return $return;
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
// transaction data:
/** @var array|null $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return [];
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleTransactionData($transaction);
}
return $return;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -186,24 +118,18 @@ class UpdateRequest extends FormRequest
'transactions.*.piggy_bank_id' => ['nullable', 'numeric', 'mustExist:piggy_banks,id', new BelongsUser()],
'transactions.*.piggy_bank_name' => ['between:1,255', 'nullable', new BelongsUser()],
'transactions.*.tags' => 'nullable|between:1,64000',
];
}
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator) {
//$this->validateOneRecurrenceTransaction($validator);
//$this->validateOneRepetitionUpdate($validator);
// $this->validateOneRecurrenceTransaction($validator);
// $this->validateOneRepetitionUpdate($validator);
/** @var Recurrence $recurrence */
$recurrence = $this->route()->parameter('recurrence');
@@ -216,4 +142,67 @@ class UpdateRequest extends FormRequest
);
}
/**
* Returns the repetition data as it is found in the submitted data.
*/
private function getRepetitionData(): ?array
{
$return = [];
// repetition data:
/** @var null|array $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return null;
}
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$current = [];
if (array_key_exists('type', $repetition)) {
$current['type'] = $repetition['type'];
}
if (array_key_exists('moment', $repetition)) {
$current['moment'] = (string)$repetition['moment'];
}
if (array_key_exists('skip', $repetition)) {
$current['skip'] = (int)$repetition['skip'];
}
if (array_key_exists('weekend', $repetition)) {
$current['weekend'] = (int)$repetition['weekend'];
}
$return[] = $current;
}
if (0 === count($return)) {
return null;
}
return $return;
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*/
private function getTransactionData(): array
{
$return = [];
// transaction data:
/** @var null|array $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return [];
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleTransactionData($transaction);
}
return $return;
}
}

View File

@@ -41,8 +41,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -65,52 +63,8 @@ class StoreRequest extends FormRequest
return $data;
}
/**
* @return array
*/
private function getRuleTriggers(): array
{
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $this->convertBoolean((string)($trigger['active'] ?? 'true')),
'stop_processing' => $this->convertBoolean((string)($trigger['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
/**
* @return array
*/
private function getRuleActions(): array
{
$actions = $this->get('actions');
$return = [];
if (is_array($actions)) {
foreach ($actions as $action) {
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string)($action['active'] ?? 'true')),
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -127,12 +81,12 @@ class StoreRequest extends FormRequest
'rule_group_id' => 'belongsToUser:rule_groups|required_without:rule_group_title',
'rule_group_title' => 'nullable|between:1,255|required_without:rule_group_id|belongsToUser:rule_groups,title',
'trigger' => 'required|in:store-journal,update-journal',
'triggers.*.type' => 'required|in:' . implode(',', $validTriggers),
'triggers.*.value' => 'required_if:actions.*.type,' . $contextTriggers . '|min:1|ruleTriggerValue|max:1024',
'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),
'triggers.*.value' => 'required_if:actions.*.type,'.$contextTriggers.'|min:1|ruleTriggerValue|max:1024',
'triggers.*.stop_processing' => [new IsBoolean()],
'triggers.*.active' => [new IsBoolean()],
'actions.*.type' => 'required|in:' . implode(',', $validActions),
'actions.*.value' => 'required_if:actions.*.type,' . $contextActions . '|ruleActionValue',
'actions.*.type' => 'required|in:'.implode(',', $validActions),
'actions.*.value' => 'required_if:actions.*.type,'.$contextActions.'|ruleActionValue',
'actions.*.stop_processing' => [new IsBoolean()],
'actions.*.active' => [new IsBoolean()],
'strict' => [new IsBoolean()],
@@ -143,10 +97,6 @@ class StoreRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
@@ -162,8 +112,6 @@ class StoreRequest extends FormRequest
/**
* Adds an error to the validator when there are no triggers in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneTrigger(Validator $validator): void
{
@@ -177,8 +125,6 @@ class StoreRequest extends FormRequest
/**
* Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneAction(Validator $validator): void
{
@@ -192,13 +138,12 @@ class StoreRequest extends FormRequest
/**
* Adds an error to the validator when there are no ACTIVE triggers in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneActiveTrigger(Validator $validator): void
{
$data = $validator->getData();
/** @var string|int|array|null $triggers */
/** @var null|array|int|string $triggers */
$triggers = $data['triggers'] ?? [];
// need at least one trigger
if (!is_countable($triggers) || 0 === count($triggers)) {
@@ -222,13 +167,12 @@ class StoreRequest extends FormRequest
/**
* Adds an error to the validator when there are no ACTIVE actions in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneActiveAction(Validator $validator): void
{
$data = $validator->getData();
/** @var string|int|array|null $actions */
/** @var null|array|int|string $actions */
$actions = $data['actions'] ?? [];
// need at least one trigger
if (!is_countable($actions) || 0 === count($actions)) {
@@ -249,4 +193,40 @@ class StoreRequest extends FormRequest
$validator->errors()->add(sprintf('actions.%d.active', $inactiveIndex), (string)trans('validation.at_least_one_active_action'));
}
}
private function getRuleTriggers(): array
{
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $this->convertBoolean((string)($trigger['active'] ?? 'true')),
'stop_processing' => $this->convertBoolean((string)($trigger['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
private function getRuleActions(): array
{
$actions = $this->get('actions');
$return = [];
if (is_array($actions)) {
foreach ($actions as $action) {
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string)($action['active'] ?? 'true')),
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
}

View File

@@ -37,9 +37,6 @@ class TestRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getTestParameters(): array
{
return [
@@ -47,23 +44,24 @@ class TestRequest extends FormRequest
'start' => $this->getDate('start'),
'end' => $this->getDate('end'),
'accounts' => $this->getAccounts(),
];
}
/**
* @return int
*/
public function rules(): array
{
return [
'start' => 'date',
'end' => 'date|after_or_equal:start',
'accounts' => '',
'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts',
];
}
private function getPage(): int
{
return 0 === (int)$this->query('page') ? 1 : (int)$this->query('page');
}
/**
* @param string $field
*
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
$value = $this->query($field);
@@ -75,27 +73,12 @@ class TestRequest extends FormRequest
if (false === $result) {
return null;
}
return $result;
}
/**
* @return array
*/
private function getAccounts(): array
{
return $this->get('accounts');
}
/**
* @return array
*/
public function rules(): array
{
return [
'start' => 'date',
'end' => 'date|after_or_equal:start',
'accounts' => '',
'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts',
];
}
}

View File

@@ -37,9 +37,6 @@ class TriggerRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getTriggerParameters(): array
{
return [
@@ -49,11 +46,16 @@ class TriggerRequest extends FormRequest
];
}
/**
* @param string $field
*
* @return Carbon|null
*/
public function rules(): array
{
return [
'start' => 'date',
'end' => 'date|after_or_equal:start',
'accounts' => '',
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
];
}
private function getDate(string $field): ?Carbon
{
$value = $this->query($field);
@@ -65,27 +67,12 @@ class TriggerRequest extends FormRequest
if (false === $result) {
return null;
}
return $result;
}
/**
* @return array
*/
private function getAccounts(): array
{
return $this->get('accounts') ?? [];
}
/**
* @return array
*/
public function rules(): array
{
return [
'start' => 'date',
'end' => 'date|after_or_equal:start',
'accounts' => '',
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
];
}
}

View File

@@ -42,8 +42,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -71,60 +69,8 @@ class UpdateRequest extends FormRequest
return $return;
}
/**
* @return array|null
*/
private function getRuleTriggers(): ?array
{
if (!$this->has('triggers')) {
return null;
}
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$active = array_key_exists('active', $trigger) ? $trigger['active'] : true;
$stopProcessing = array_key_exists('stop_processing', $trigger) ? $trigger['stop_processing'] : false;
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $active,
'stop_processing' => $stopProcessing,
];
}
}
return $return;
}
/**
* @return array|null
*/
private function getRuleActions(): ?array
{
if (!$this->has('actions')) {
return null;
}
$actions = $this->get('actions');
$return = [];
if (is_array($actions)) {
foreach ($actions as $action) {
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string)($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -144,12 +90,12 @@ class UpdateRequest extends FormRequest
'rule_group_id' => 'belongsToUser:rule_groups',
'rule_group_title' => 'nullable|between:1,255|belongsToUser:rule_groups,title',
'trigger' => 'in:store-journal,update-journal',
'triggers.*.type' => 'required|in:' . implode(',', $validTriggers),
'triggers.*.value' => 'required_if:actions.*.type,' . $contextTriggers . '|min:1|ruleTriggerValue|max:1024',
'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),
'triggers.*.value' => 'required_if:actions.*.type,'.$contextTriggers.'|min:1|ruleTriggerValue|max:1024',
'triggers.*.stop_processing' => [new IsBoolean()],
'triggers.*.active' => [new IsBoolean()],
'actions.*.type' => 'required|in:' . implode(',', $validActions),
'actions.*.value' => 'required_if:actions.*.type,' . $contextActions . '|ruleActionValue',
'actions.*.type' => 'required|in:'.implode(',', $validActions),
'actions.*.value' => 'required_if:actions.*.type,'.$contextActions.'|ruleActionValue',
'actions.*.stop_processing' => [new IsBoolean()],
'actions.*.active' => [new IsBoolean()],
'strict' => [new IsBoolean()],
@@ -161,10 +107,6 @@ class UpdateRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
@@ -180,8 +122,6 @@ class UpdateRequest extends FormRequest
/**
* Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneTrigger(Validator $validator): void
{
@@ -195,8 +135,6 @@ class UpdateRequest extends FormRequest
/**
* Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneValidTrigger(Validator $validator): void
{
@@ -224,8 +162,6 @@ class UpdateRequest extends FormRequest
/**
* Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneAction(Validator $validator): void
{
@@ -239,8 +175,6 @@ class UpdateRequest extends FormRequest
/**
* Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneValidAction(Validator $validator): void
{
@@ -266,4 +200,48 @@ class UpdateRequest extends FormRequest
$validator->errors()->add(sprintf('actions.%d.active', $inactiveIndex), (string)trans('validation.at_least_one_active_action'));
}
}
private function getRuleTriggers(): ?array
{
if (!$this->has('triggers')) {
return null;
}
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$active = array_key_exists('active', $trigger) ? $trigger['active'] : true;
$stopProcessing = array_key_exists('stop_processing', $trigger) ? $trigger['stop_processing'] : false;
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $active,
'stop_processing' => $stopProcessing,
];
}
}
return $return;
}
private function getRuleActions(): ?array
{
if (!$this->has('actions')) {
return null;
}
$actions = $this->get('actions');
$return = [];
if (is_array($actions)) {
foreach ($actions as $action) {
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string)($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
}

View File

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

View File

@@ -37,9 +37,6 @@ class TestRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getTestParameters(): array
{
return [
@@ -49,11 +46,16 @@ class TestRequest extends FormRequest
];
}
/**
* @param string $field
*
* @return Carbon|null
*/
public function rules(): array
{
return [
'start' => 'date',
'end' => 'date|after_or_equal:start',
'accounts' => '',
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
];
}
private function getDate(string $field): ?Carbon
{
$value = $this->query($field);
@@ -65,27 +67,12 @@ class TestRequest extends FormRequest
if (false === $result) {
return null;
}
return $result;
}
/**
* @return array
*/
private function getAccounts(): array
{
return $this->get('accounts');
}
/**
* @return array
*/
public function rules(): array
{
return [
'start' => 'date',
'end' => 'date|after_or_equal:start',
'accounts' => '',
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
];
}
}

View File

@@ -37,9 +37,6 @@ class TriggerRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getTriggerParameters(): array
{
return [
@@ -49,11 +46,14 @@ class TriggerRequest extends FormRequest
];
}
/**
* @param string $field
*
* @return Carbon|null
*/
public function rules(): array
{
return [
'start' => 'date',
'end' => 'date|after_or_equal:start',
];
}
private function getDate(string $field): ?Carbon
{
$value = $this->query($field);
@@ -65,25 +65,12 @@ class TriggerRequest extends FormRequest
if (false === $result) {
return null;
}
return $result;
}
/**
* @return array
*/
private function getAccounts(): array
{
return $this->get('accounts');
}
/**
* @return array
*/
public function rules(): array
{
return [
'start' => 'date',
'end' => 'date|after_or_equal:start',
];
}
}

View File

@@ -39,8 +39,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -57,8 +55,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -66,7 +62,7 @@ class UpdateRequest extends FormRequest
$ruleGroup = $this->route()->parameter('ruleGroup');
return [
'title' => 'between:1,100|uniqueObjectForUser:rule_groups,title,' . $ruleGroup->id,
'title' => 'between:1,100|uniqueObjectForUser:rule_groups,title,'.$ruleGroup->id,
'description' => 'between:1,5000|nullable',
'active' => [new IsBoolean()],
];

View File

@@ -31,8 +31,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -42,8 +40,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -59,8 +55,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -33,8 +33,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -44,8 +42,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -62,8 +58,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -71,7 +65,7 @@ class UpdateRequest extends FormRequest
$tag = $this->route()->parameter('tagOrId');
// TODO check if uniqueObjectForUser is obsolete
$rules = [
'tag' => 'min:1|max:1024|uniqueObjectForUser:tags,tag,' . $tag->id,
'tag' => 'min:1|max:1024|uniqueObjectForUser:tags,tag,'.$tag->id,
'description' => 'min:1|nullable|max:65536',
'date' => 'date|nullable',
];

View File

@@ -51,8 +51,6 @@ class StoreRequest extends FormRequest
/**
* Get all data. Is pretty complex because of all the ??-statements.
*
* @return array
*/
public function getAll(): array
{
@@ -68,112 +66,14 @@ 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
{
app('log')->debug('Collect rules of TransactionStoreRequest');
$validProtocols = config('firefly.valid_url_protocols');
return [
// basic fields for group:
'group_title' => 'between:1,1000|nullable',
@@ -256,10 +156,6 @@ class StoreRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
@@ -293,4 +189,99 @@ 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

@@ -57,7 +57,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data. Is pretty complex because of all the ??-statements.
*
* @return array
* @throws FireflyException
*/
public function getAll(): array
@@ -91,8 +90,8 @@ class UpdateRequest extends FormRequest
];
$this->floatFields = [ // not really floats, for validation.
'amount',
'foreign_amount',
'amount',
'foreign_amount',
];
$this->stringFields = [
@@ -148,182 +147,14 @@ class UpdateRequest extends FormRequest
return $data;
}
/**
* Get transaction data.
*
* @return array
* @throws FireflyException
*/
private function getTransactionData(): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
$return = [];
/** @var array|null $transactions */
$transactions = $this->get('transactions');
if (!is_countable($transactions)) {
return $return;
}
/** @var array|null $transaction */
foreach ($transactions as $transaction) {
if (!is_array($transaction)) {
throw new FireflyException('Invalid data submitted: transaction is not array.');
}
// default response is to update nothing in the transaction:
$current = [];
$current = $this->getIntegerData($current, $transaction);
$current = $this->getStringData($current, $transaction);
$current = $this->getNlStringData($current, $transaction);
$current = $this->getDateData($current, $transaction);
$current = $this->getBooleanData($current, $transaction);
$current = $this->getArrayData($current, $transaction);
$current = $this->getFloatData($current, $transaction);
$return[] = $current;
}
return $return;
}
/**
* For each field, add it to the array if a reference is present in the request:
*
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getIntegerData(array $current, array $transaction): array
{
foreach ($this->integerFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->integerFromValue((string)$transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getStringData(array $current, array $transaction): array
{
foreach ($this->stringFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->clearString((string)$transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getNlStringData(array $current, array $transaction): array
{
foreach ($this->textareaFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->clearStringKeepNewlines((string)$transaction[$fieldName]); // keep newlines
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getDateData(array $current, array $transaction): array
{
foreach ($this->dateFields as $fieldName) {
app('log')->debug(sprintf('Now at date field %s', $fieldName));
if (array_key_exists($fieldName, $transaction)) {
app('log')->debug(sprintf('New value: "%s"', (string)$transaction[$fieldName]));
$current[$fieldName] = $this->dateFromValue((string)$transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getBooleanData(array $current, array $transaction): array
{
foreach ($this->booleanFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->convertBoolean((string)$transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getArrayData(array $current, array $transaction): array
{
foreach ($this->arrayFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getFloatData(array $current, array $transaction): array
{
foreach ($this->floatFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$value = $transaction[$fieldName];
if (is_float($value)) {
$current[$fieldName] = sprintf('%.12f', $value);
}
if (!is_float($value)) {
$current[$fieldName] = (string)$value;
}
}
}
return $current;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
$validProtocols = config('firefly.valid_url_protocols');
return [
// basic fields for group:
'group_title' => 'between:1,1000|nullable',
@@ -337,7 +168,6 @@ class UpdateRequest extends FormRequest
// group id:
'transactions.*.transaction_journal_id' => ['nullable', 'numeric', new BelongsUser()],
// currency info
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id|nullable',
'transactions.*.currency_code' => 'min:3|max:51|exists:transaction_currencies,code|nullable',
@@ -401,14 +231,11 @@ class UpdateRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
app('log')->debug('Now in withValidator');
/** @var TransactionGroup $transactionGroup */
$transactionGroup = $this->route()->parameter('transactionGroup');
$validator->after(
@@ -419,7 +246,6 @@ class UpdateRequest extends FormRequest
// all transaction types must be equal:
$this->validateTransactionTypesForUpdate($validator);
// user wants to update a reconciled transaction.
// source, destination, amount + foreign_amount cannot be changed
// and must be omitted from the request.
@@ -429,13 +255,137 @@ class UpdateRequest extends FormRequest
$this->validateEqualAccountsForUpdate($validator, $transactionGroup);
// see method:
//$this->preventNoAccountInfo($validator, );
// $this->preventNoAccountInfo($validator, );
// validate that the currency fits the source and/or destination account.
// validate all account info
$this->validateAccountInformationUpdate($validator, $transactionGroup);
}
);
}
/**
* Get transaction data.
*
* @throws FireflyException
*/
private function getTransactionData(): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
$return = [];
/** @var null|array $transactions */
$transactions = $this->get('transactions');
if (!is_countable($transactions)) {
return $return;
}
/** @var null|array $transaction */
foreach ($transactions as $transaction) {
if (!is_array($transaction)) {
throw new FireflyException('Invalid data submitted: transaction is not array.');
}
// default response is to update nothing in the transaction:
$current = [];
$current = $this->getIntegerData($current, $transaction);
$current = $this->getStringData($current, $transaction);
$current = $this->getNlStringData($current, $transaction);
$current = $this->getDateData($current, $transaction);
$current = $this->getBooleanData($current, $transaction);
$current = $this->getArrayData($current, $transaction);
$current = $this->getFloatData($current, $transaction);
$return[] = $current;
}
return $return;
}
/**
* For each field, add it to the array if a reference is present in the request:
*/
private function getIntegerData(array $current, array $transaction): array
{
foreach ($this->integerFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->integerFromValue((string)$transaction[$fieldName]);
}
}
return $current;
}
private function getStringData(array $current, array $transaction): array
{
foreach ($this->stringFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->clearString((string)$transaction[$fieldName]);
}
}
return $current;
}
private function getNlStringData(array $current, array $transaction): array
{
foreach ($this->textareaFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->clearStringKeepNewlines((string)$transaction[$fieldName]); // keep newlines
}
}
return $current;
}
private function getDateData(array $current, array $transaction): array
{
foreach ($this->dateFields as $fieldName) {
app('log')->debug(sprintf('Now at date field %s', $fieldName));
if (array_key_exists($fieldName, $transaction)) {
app('log')->debug(sprintf('New value: "%s"', (string)$transaction[$fieldName]));
$current[$fieldName] = $this->dateFromValue((string)$transaction[$fieldName]);
}
}
return $current;
}
private function getBooleanData(array $current, array $transaction): array
{
foreach ($this->booleanFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->convertBoolean((string)$transaction[$fieldName]);
}
}
return $current;
}
private function getArrayData(array $current, array $transaction): array
{
foreach ($this->arrayFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);
}
}
return $current;
}
private function getFloatData(array $current, array $transaction): array
{
foreach ($this->floatFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$value = $transaction[$fieldName];
if (is_float($value)) {
$current[$fieldName] = sprintf('%.12f', $value);
}
if (!is_float($value)) {
$current[$fieldName] = (string)$value;
}
}
}
return $current;
}
}

View File

@@ -30,8 +30,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -40,8 +38,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -66,8 +62,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -78,7 +72,6 @@ class StoreRequest extends FormRequest
'decimal_places' => 'between:0,20|numeric|min:0|max:12',
'enabled' => [new IsBoolean()],
'default' => [new IsBoolean()],
];
}
}

View File

@@ -31,8 +31,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -41,8 +39,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -61,8 +57,6 @@ class UpdateRequest 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 StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -57,8 +55,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -73,10 +69,6 @@ class StoreRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
@@ -87,13 +79,11 @@ class StoreRequest extends FormRequest
);
}
/**
* @param Validator $validator
*/
private function validateExistingLink(Validator $validator): void
{
/** @var User $user */
$user = auth()->user();
/** @var LinkTypeRepositoryInterface $repository */
$repository = app(LinkTypeRepositoryInterface::class);
$repository->setUser($user);

View File

@@ -41,8 +41,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -57,8 +55,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -73,10 +69,6 @@ class UpdateRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
@@ -87,14 +79,12 @@ class UpdateRequest extends FormRequest
);
}
/**
* @param Validator $validator
*/
private function validateUpdate(Validator $validator): void
{
/** @var TransactionJournalLink $existing */
$existing = $this->route()->parameter('journalLink');
$data = $validator->getData();
/** @var LinkTypeRepositoryInterface $repository */
$repository = app(LinkTypeRepositoryInterface::class);
$repository->setUser(auth()->user());

View File

@@ -29,8 +29,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class StoreRequest
*
*/
class StoreRequest extends FormRequest
{
@@ -39,8 +37,6 @@ class StoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -53,8 +49,6 @@ class StoreRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -31,8 +31,6 @@ use Illuminate\Validation\Rule;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -41,8 +39,6 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -55,8 +51,6 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -37,9 +37,6 @@ class CreateRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getData(): array
{
$triggers = Webhook::getTriggersForValidation();
@@ -57,17 +54,15 @@ class CreateRequest extends FormRequest
// this is the way.
$return = $this->getAllData($fields);
$return['trigger'] = $triggers[$return['trigger']] ?? (int)($return['trigger']);
$return['response'] = $responses[$return['response']] ?? (int)($return['response']);
$return['delivery'] = $deliveries[$return['delivery']] ?? (int)($return['delivery']);
$return['trigger'] = $triggers[$return['trigger']] ?? (int)$return['trigger'];
$return['response'] = $responses[$return['response']] ?? (int)$return['response'];
$return['delivery'] = $deliveries[$return['delivery']] ?? (int)$return['delivery'];
return $return;
}
/**
* Rules for this request.
*
* @return array
*/
public function rules(): array
{
@@ -75,6 +70,7 @@ class CreateRequest extends FormRequest
$responses = implode(',', array_keys(Webhook::getResponsesForValidation()));
$deliveries = implode(',', array_keys(Webhook::getDeliveriesForValidation()));
$validProtocols = config('firefly.valid_url_protocols');
return [
'title' => 'required|between:1,512|uniqueObjectForUser:webhooks,title',
'active' => [new IsBoolean()],

View File

@@ -37,9 +37,6 @@ class UpdateRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getData(): array
{
$triggers = Webhook::getTriggersForValidation();
@@ -76,8 +73,6 @@ class UpdateRequest extends FormRequest
/**
* Rules for this request.
*
* @return array
*/
public function rules(): array
{
@@ -85,6 +80,7 @@ class UpdateRequest extends FormRequest
$responses = implode(',', array_keys(Webhook::getResponsesForValidation()));
$deliveries = implode(',', array_keys(Webhook::getDeliveriesForValidation()));
$validProtocols = config('firefly.valid_url_protocols');
/** @var Webhook $webhook */
$webhook = $this->route()->parameter('webhook');

View File

@@ -29,8 +29,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class CronRequest
*
*/
class CronRequest extends FormRequest
{
@@ -38,8 +36,6 @@ class CronRequest extends FormRequest
/**
* Verify the request.
*
* @return bool
*/
public function authorize(): bool
{
@@ -48,8 +44,6 @@ class CronRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -69,8 +63,6 @@ class CronRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{

View File

@@ -31,8 +31,6 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* Class UpdateRequest
*
*/
class UpdateRequest extends FormRequest
{
@@ -41,17 +39,15 @@ class UpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
$name = $this->route()->parameter('dynamicConfigKey');
if ($name === 'configuration.is_demo_site' || $name === 'configuration.single_user_mode') {
if ('configuration.is_demo_site' === $name || 'configuration.single_user_mode' === $name) {
return ['value' => $this->boolean('value')];
}
if ($name === 'configuration.permission_update_check' || $name === 'configuration.last_update_check') {
if ('configuration.permission_update_check' === $name || 'configuration.last_update_check' === $name) {
return ['value' => $this->convertInteger('value')];
}
@@ -60,20 +56,18 @@ class UpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$name = $this->route()->parameter('configName');
if ($name === 'configuration.is_demo_site' || $name === 'configuration.single_user_mode') {
if ('configuration.is_demo_site' === $name || 'configuration.single_user_mode' === $name) {
return ['value' => ['required', new IsBoolean()]];
}
if ($name === 'configuration.permission_update_check') {
if ('configuration.permission_update_check' === $name) {
return ['value' => 'required|numeric|between:-1,1'];
}
if ($name === 'configuration.last_update_check') {
if ('configuration.last_update_check' === $name) {
return ['value' => 'required|numeric|min:464272080'];
}

View File

@@ -39,8 +39,6 @@ class UserStoreRequest extends FormRequest
/**
* Logged in + owner
*
* @return bool
*/
public function authorize(): bool
{
@@ -49,8 +47,6 @@ class UserStoreRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -69,8 +65,6 @@ class UserStoreRequest 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 UserUpdateRequest extends FormRequest
/**
* Logged in + owner
*
* @return bool
*/
public function authorize(): bool
{
@@ -51,8 +49,6 @@ class UserUpdateRequest extends FormRequest
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
@@ -71,8 +67,6 @@ class UserUpdateRequest extends FormRequest
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
@@ -89,14 +83,10 @@ class UserUpdateRequest extends FormRequest
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
/** @var User|null $current */
/** @var null|User $current */
$current = $this->route()->parameter('user');
$validator->after(
static function (Validator $validator) use ($current) {

View File

@@ -35,9 +35,6 @@ class PreferenceStoreRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getAll(): array
{
$array = [

View File

@@ -36,9 +36,6 @@ class PreferenceUpdateRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
/**
* @return array
*/
public function getAll(): array
{
$array = [