Refactor InformativeValidators to move the modules into Validators.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages\Factories;
|
||||
|
||||
use App\Models\Validation\Messages\Factories\InformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Messages\Factories\MessageByNameFactory;
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\CompanyValidatorByName;
|
||||
|
||||
class CompanyInformativeValidatorByNameFactory extends InformativeValidatorByNameFactory
|
||||
{
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->setMessages((new MessageByNameFactory('company'))->create());
|
||||
|
||||
$this->setName($name);
|
||||
}
|
||||
|
||||
public function getValidatorByName(InformativeValidator $okValidator): Validator
|
||||
{
|
||||
return new CompanyValidatorByName($this->name, $okValidator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages\Factories;
|
||||
|
||||
use App\Models\Validation\Messages\Factories\InformativeValidatorFactory;
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
|
||||
use App\Models\Validation\Messages\OkInformativeValidator;
|
||||
use App\Models\Validation\Messages\NextInformativeValidator;
|
||||
use App\Models\Validation\Validators\EmptyNameValidator;
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
|
||||
abstract class InformativeValidatorByNameFactory extends InformativeValidatorFactory
|
||||
{
|
||||
protected array $messages;
|
||||
protected string $name;
|
||||
|
||||
public function setMessages(array $messages): void
|
||||
{
|
||||
$this->messages = $messages;
|
||||
}
|
||||
|
||||
public function getMessages(): array
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
abstract public function getValidatorByName(InformativeValidator $okValidator): Validator;
|
||||
|
||||
public function create(): InformativeValidator
|
||||
{
|
||||
$okValidator = new OkInformativeValidator($this->messages['found']);
|
||||
|
||||
$nameValidator = new NextInformativeValidator(
|
||||
$this->messages['not_found'],
|
||||
$this->getValidatorByName($okValidator),
|
||||
$okValidator
|
||||
);
|
||||
|
||||
return new NextInformativeValidator(
|
||||
$this->messages['invalid_name'],
|
||||
new EmptyNameValidator($this->name, $nameValidator),
|
||||
$nameValidator
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages\Factories;
|
||||
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
|
||||
abstract class InformativeValidatorFactory
|
||||
{
|
||||
abstract function create(): InformativeValidator;
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages\Factories;
|
||||
|
||||
use App\Models\Validation\Messages\Factories\InformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Messages\Factories\MessageByNameFactory;
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\ItemValidatorByName;
|
||||
|
||||
class ItemInformativeValidatorByNameFactory extends InformativeValidatorByNameFactory
|
||||
{
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->setMessages((new MessageByNameFactory('item'))->create());
|
||||
|
||||
$this->setName($name);
|
||||
}
|
||||
|
||||
public function getValidatorByName(InformativeValidator $okValidator): Validator
|
||||
{
|
||||
return new ItemValidatorByName($this->name, $okValidator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
|
||||
abstract class InformativeValidator extends Validator {
|
||||
protected Validator $validator;
|
||||
protected string $message;
|
||||
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
return $this->validator->isCurrentValid();
|
||||
}
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->validator->isValid();
|
||||
}
|
||||
|
||||
public function setValidator($validator): void
|
||||
{
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function setMessage($message): void
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
if(!$this->isCurrentValid())
|
||||
return $this->message;
|
||||
|
||||
return $this->nextValidator->getMessage();
|
||||
}
|
||||
|
||||
public function getOkStatus(): array
|
||||
{
|
||||
if(!$this->isCurrentValid())
|
||||
return ['error' => $this->message];
|
||||
|
||||
return $this->nextValidator->getOkStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
|
||||
class NextInformativeValidator extends InformativeValidator {
|
||||
protected InformativeValidator $nextValidator;
|
||||
|
||||
public function __construct(string $message, Validator $validator, InformativeValidator $nextValidator)
|
||||
{
|
||||
$this->setMessage($message);
|
||||
$this->setValidator($validator);
|
||||
$this->nextValidator = $nextValidator;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
use App\Models\Validation\Validators\OkValidator;
|
||||
|
||||
class OkInformativeValidator extends InformativeValidator {
|
||||
public function __construct($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->validator = new OkValidator();
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function getOkStatus(): array
|
||||
{
|
||||
return ['ok' => $this->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user