mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-22 20:16:22 +00:00 
			
		
		
		
	Update validators so they can handle one field at a time.
This commit is contained in:
		| @@ -43,6 +43,16 @@ class AccountValidator | ||||
| { | ||||
|     use AccountValidatorProperties, WithdrawalValidation, DepositValidation, TransferValidation, ReconciliationValidation, OBValidation; | ||||
|  | ||||
|     public bool                        $createMode; | ||||
|     public string                      $destError; | ||||
|     public ?Account                     $destination; | ||||
|     public ?Account                     $source; | ||||
|     public string                      $sourceError; | ||||
|     private AccountRepositoryInterface $accountRepository; | ||||
|     private array                      $combinations; | ||||
|     private string                     $transactionType; | ||||
|     private User                       $user; | ||||
|  | ||||
|     /** | ||||
|      * AccountValidator constructor. | ||||
|      */ | ||||
| @@ -52,6 +62,8 @@ class AccountValidator | ||||
|         $this->destError    = 'No error yet.'; | ||||
|         $this->sourceError  = 'No error yet.'; | ||||
|         $this->combinations = config('firefly.source_dests'); | ||||
|         $this->source       = null; | ||||
|         $this->destination  = null; | ||||
|  | ||||
|         /** @var AccountRepositoryInterface accountRepository */ | ||||
|         $this->accountRepository = app(AccountRepositoryInterface::class); | ||||
| @@ -66,7 +78,7 @@ class AccountValidator | ||||
|      */ | ||||
|     public function setTransactionType(string $transactionType): void | ||||
|     { | ||||
|         Log::debug(sprintf('Transaction type for validator is now %s', ucfirst($transactionType))); | ||||
|         Log::debug(sprintf('Transaction type for validator is now "%s".', ucfirst($transactionType))); | ||||
|         $this->transactionType = ucfirst($transactionType); | ||||
|     } | ||||
|  | ||||
| @@ -135,9 +147,8 @@ class AccountValidator | ||||
|         Log::debug(sprintf('Now in AccountValidator::validateSource(%d, "%s", "%s")', $accountId, $accountName, $accountIban)); | ||||
|         switch ($this->transactionType) { | ||||
|             default: | ||||
|                 $result            = false; | ||||
|                 $this->sourceError = trans('validation.invalid_account_info'); | ||||
|                 Log::error(sprintf('AccountValidator::validateSource cannot handle "%s", so it will always return false.', $this->transactionType)); | ||||
|                 Log::error(sprintf('AccountValidator::validateSource cannot handle "%s", so it will do a generic check.', $this->transactionType)); | ||||
|                 $result = $this->validateGenericSource($accountId, $accountName); | ||||
|                 break; | ||||
|             case TransactionType::WITHDRAWAL: | ||||
|                 $result = $this->validateWithdrawalSource($accountId, $accountName); | ||||
| @@ -197,8 +208,8 @@ class AccountValidator | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array       $validTypes | ||||
|      * @param int $accountId | ||||
|      * @param array  $validTypes | ||||
|      * @param int    $accountId | ||||
|      * @param string $accountName | ||||
|      * | ||||
|      * @return Account|null | ||||
| @@ -221,5 +232,12 @@ class AccountValidator | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return Account|null | ||||
|      */ | ||||
|     public function getSource(): ?Account | ||||
|     { | ||||
|         return $this->source; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user