mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clean up code in validator.
This commit is contained in:
parent
2e61bb7375
commit
138c38fbb5
@ -65,8 +65,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate2faCode(/** @scrutinizer ignore-unused */ $attribute, $value): bool
|
||||
{
|
||||
public function validate2faCode($attribute, $value): bool {
|
||||
if (!is_string($value) || null === $value || 6 != strlen($value)) {
|
||||
return false;
|
||||
}
|
||||
@ -85,8 +84,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateBelongsToUser(/** @scrutinizer ignore-unused */ $attribute, $value, $parameters): bool
|
||||
{
|
||||
public function validateBelongsToUser($attribute, $value, $parameters): bool {
|
||||
$field = $parameters[1] ?? 'id';
|
||||
|
||||
if (0 === intval($value)) {
|
||||
@ -108,8 +106,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateBic(/** @scrutinizer ignore-unused */ $attribute, $value): bool
|
||||
{
|
||||
public function validateBic($attribute, $value): bool {
|
||||
$regex = '/^[a-z]{6}[0-9a-z]{2}([0-9a-z]{3})?\z/i';
|
||||
$result = preg_match($regex, $value);
|
||||
if (false === $result) {
|
||||
@ -130,8 +127,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateIban(/** @scrutinizer ignore-unused */ $attribute, $value): bool
|
||||
{
|
||||
public function validateIban($attribute, $value): bool {
|
||||
if (!is_string($value) || null === $value || strlen($value) < 6) {
|
||||
return false;
|
||||
}
|
||||
@ -210,8 +206,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateMore(/** @scrutinizer ignore-unused */ $attribute, $value, $parameters): bool
|
||||
{
|
||||
public function validateMore($attribute, $value, $parameters): bool {
|
||||
$compare = $parameters[0] ?? '0';
|
||||
|
||||
return bccomp($value, $compare) > 0;
|
||||
@ -226,8 +221,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateMustExist(/** @scrutinizer ignore-unused */ $attribute, $value, $parameters): bool
|
||||
{
|
||||
public function validateMustExist($attribute, $value, $parameters): bool {
|
||||
$field = $parameters[1] ?? 'id';
|
||||
|
||||
if (0 === intval($value)) {
|
||||
@ -335,8 +329,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateSecurePassword(/** @scrutinizer ignore-unused */ $attribute, $value): bool
|
||||
{
|
||||
public function validateSecurePassword($attribute, $value): bool {
|
||||
$verify = false;
|
||||
if (isset($this->data['verify_password'])) {
|
||||
$verify = 1 === intval($this->data['verify_password']);
|
||||
@ -360,8 +353,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueAccountForUser(/** @scrutinizer ignore-unused */ $attribute, $value, $parameters): bool
|
||||
{
|
||||
public function validateUniqueAccountForUser($attribute, $value, $parameters): bool {
|
||||
// because a user does not have to be logged in (tests and what-not).
|
||||
if (!auth()->check()) {
|
||||
return $this->validateAccountAnonymously();
|
||||
@ -390,8 +382,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueAccountNumberForUser(/** @scrutinizer ignore-unused */ $attribute, $value): bool
|
||||
{
|
||||
public function validateUniqueAccountNumberForUser($attribute, $value): bool {
|
||||
$accountId = $this->data['id'] ?? 0;
|
||||
|
||||
$query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
||||
@ -428,7 +419,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueObjectForUser(/** @scrutinizer ignore-unused */ $attribute, $value, $parameters): bool
|
||||
public function validateUniqueObjectForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
$value = $this->tryDecrypt($value);
|
||||
// exclude?
|
||||
@ -436,6 +427,16 @@ class FireflyValidator extends Validator
|
||||
$field = $parameters[1];
|
||||
$exclude = $parameters[2] ?? 0;
|
||||
|
||||
/*
|
||||
* If other data (in $this->getData()) contains
|
||||
* ID field, set that field to be the $exclude.
|
||||
*/
|
||||
$data = $this->getData();
|
||||
if (!isset($parameters[2]) && isset($data['id']) && intval($data['id']) > 0) {
|
||||
$exclude = intval($data['id']);
|
||||
}
|
||||
|
||||
|
||||
// get entries from table
|
||||
$set = DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at')
|
||||
->where('id', '!=', $exclude)->get([$field]);
|
||||
@ -460,8 +461,7 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniquePiggyBankForUser(/** @scrutinizer ignore-unused */ $attribute, $value, $parameters): bool
|
||||
{
|
||||
public function validateUniquePiggyBankForUser($attribute, $value, $parameters): bool {
|
||||
$exclude = $parameters[0] ?? null;
|
||||
$query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id);
|
||||
|
Loading…
Reference in New Issue
Block a user