mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
Code cleanup and realign.
This commit is contained in:
@@ -243,7 +243,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param string $attribute
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -338,7 +340,7 @@ class FireflyValidator extends Validator
|
||||
$classes = app('config')->get('firefly.rule-triggers');
|
||||
/** @var TriggerInterface $class */
|
||||
$class = $classes[$triggerType] ?? false;
|
||||
if(false === $class) {
|
||||
if (false === $class) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -412,7 +414,7 @@ class FireflyValidator extends Validator
|
||||
public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
$accountId = (int)($this->data['id'] ?? 0.0);
|
||||
if ($accountId === 0) {
|
||||
if (0 === $accountId) {
|
||||
$accountId = (int)($parameters[0] ?? 0.0);
|
||||
}
|
||||
|
||||
@@ -421,7 +423,7 @@ class FireflyValidator extends Validator
|
||||
->where('accounts.user_id', auth()->user()->id)
|
||||
->where('account_meta.name', 'accountNumber');
|
||||
|
||||
if ((int)$accountId > 0) {
|
||||
if ($accountId > 0) {
|
||||
// exclude current account from check.
|
||||
$query->where('account_meta.account_id', '!=', $accountId);
|
||||
}
|
||||
@@ -513,66 +515,6 @@ class FireflyValidator extends Validator
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRuleActionName(int $index): string
|
||||
{
|
||||
$name = $this->data['rule-action'][$index] ?? 'invalid';
|
||||
if (!isset($this->data['rule-action'][$index])) {
|
||||
$name = $this->data['rule-actions'][$index]['name'] ?? 'invalid';
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRuleActionValue(int $index): string
|
||||
{
|
||||
$value = $this->data['rule-action-value'][$index] ?? '';
|
||||
if (!isset($this->data['rule-action-value'][$index])) {
|
||||
$value = $this->data['rule-actions'][$index]['value'] ?? '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRuleTriggerName(int $index): string
|
||||
{
|
||||
$name = $this->data['rule-trigger'][$index] ?? 'invalid';
|
||||
if (!isset($this->data['rule-trigger'][$index])) {
|
||||
$name = $this->data['rule-triggers'][$index]['name'] ?? 'invalid';
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRuleTriggerValue(int $index): string
|
||||
{
|
||||
$value = $this->data['rule-trigger-value'][$index] ?? '';
|
||||
if (!isset($this->data['rule-trigger-value'][$index])) {
|
||||
$value = $this->data['rule-triggers'][$index]['value'] ?? '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
@@ -627,6 +569,7 @@ class FireflyValidator extends Validator
|
||||
$ignore = $existingAccount->id;
|
||||
$value = $this->tryDecrypt($value);
|
||||
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
|
||||
/** @var Account $entry */
|
||||
foreach ($set as $entry) {
|
||||
@@ -650,6 +593,7 @@ class FireflyValidator extends Validator
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
$value = $this->tryDecrypt($value);
|
||||
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
|
||||
/** @var Account $entry */
|
||||
foreach ($set as $entry) {
|
||||
|
@@ -37,6 +37,39 @@ use Log;
|
||||
*/
|
||||
trait RecurrenceValidation
|
||||
{
|
||||
/**
|
||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateOneRepetition(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
// need at least one transaction
|
||||
if (0 === \count($repetitions)) {
|
||||
$validator->errors()->add('description', (string)trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the recurrence has valid repetition information. It either doesn't stop,
|
||||
* or stops after X times or at X date. Not both of them.,
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateRecurrenceRepetition(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['nr_of_repetitions'] ?? null;
|
||||
$repeatUntil = $data['repeat_until'] ?? null;
|
||||
if (null !== $repetitions && null !== $repeatUntil) {
|
||||
// expect a date OR count:
|
||||
$validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*/
|
||||
@@ -73,39 +106,6 @@ trait RecurrenceValidation
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateOneRepetition(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
// need at least one transaction
|
||||
if (\count($repetitions) === 0) {
|
||||
$validator->errors()->add('description', (string)trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the recurrence has valid repetition information. It either doesn't stop,
|
||||
* or stops after X times or at X date. Not both of them.,
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateRecurrenceRepetition(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['nr_of_repetitions'] ?? null;
|
||||
$repeatUntil = $data['repeat_until'] ?? null;
|
||||
if (null !== $repetitions && null !== $repeatUntil) {
|
||||
// expect a date OR count:
|
||||
$validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the repetition type is daily, the moment should be empty.
|
||||
*
|
||||
@@ -145,7 +145,7 @@ trait RecurrenceValidation
|
||||
protected function validateNdom(Validator $validator, int $index, string $moment): void
|
||||
{
|
||||
$parameters = explode(',', $moment);
|
||||
if (\count($parameters) !== 2) {
|
||||
if (2 !== \count($parameters)) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
|
||||
return;
|
||||
|
@@ -338,13 +338,13 @@ trait TransactionValidation
|
||||
if ($accountId < 1 && '' === $accountName) {
|
||||
return null;
|
||||
}
|
||||
if ($accountId !== 0) {
|
||||
if (0 !== $accountId) {
|
||||
// ID belongs to user and is $type account:
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($admin);
|
||||
$set = $repository->getAccountsById([$accountId]);
|
||||
if ($set->count() === 1) {
|
||||
if (1 === $set->count()) {
|
||||
/** @var Account $first */
|
||||
$first = $set->first();
|
||||
if ($first->accountType->type !== $type) {
|
||||
|
Reference in New Issue
Block a user