Refactor ValidatorByNameFactories of Company and Item models.
continuous-integration/drone/push Build is passing Details

main
KKlochko 2 years ago
parent c415a77272
commit 2b37a4c2e7

@ -2,45 +2,28 @@
namespace App\Models\Validation\Messages\Factories; namespace App\Models\Validation\Messages\Factories;
use App\Models\Validation\Messages\Factories\InformativeValidatorFactory; use App\Models\Validation\Messages\Factories\InformativeValidatorByNameFactory;
use App\Models\Validation\Messages\InformativeValidator; use App\Models\Validation\Messages\InformativeValidator;
use App\Models\Validation\Messages\OkInformativeValidator; use App\Models\Validation\Validators\Validator;
use App\Models\Validation\Messages\NextInformativeValidator;
use App\Models\Validation\Validators\EmptyNameValidator;
use App\Models\Validation\Validators\CompanyValidatorByName; use App\Models\Validation\Validators\CompanyValidatorByName;
class CompanyInformativeValidatorByNameFactory extends InformativeValidatorFactory class CompanyInformativeValidatorByNameFactory extends InformativeValidatorByNameFactory
{ {
protected array $messages;
protected string $name;
public function __construct(string $name) public function __construct(string $name)
{ {
$this->messages = [ $this->setMessages([
'found' => 'A company with the name is valid.', 'found' => 'A company with the name is valid.',
'not_found' => 'A company with the name does not exist!!!', 'not_found' => 'A company with the name does not exist!!!',
'invalid_name' => 'The company name is empty, please, write the name!!!', 'invalid_name' => 'The company name is empty, please, write the name!!!',
]; ]);
$this->name = $name; $this->setName($name);
} }
function create(): InformativeValidator public function getValidatorByName(InformativeValidator $okValidator): Validator
{ {
$okValidator = new OkInformativeValidator($this->messages['found']); return new CompanyValidatorByName($this->name, $okValidator);
$nameValidator = new NextInformativeValidator(
$this->messages['not_found'],
new CompanyValidatorByName($this->name, $okValidator),
$okValidator
);
return new NextInformativeValidator(
$this->messages['invalid_name'],
new EmptyNameValidator($this->name, $nameValidator),
$nameValidator
);
} }
} }

@ -2,45 +2,28 @@
namespace App\Models\Validation\Messages\Factories; namespace App\Models\Validation\Messages\Factories;
use App\Models\Validation\Messages\Factories\InformativeValidatorFactory; use App\Models\Validation\Messages\Factories\InformativeValidatorByNameFactory;
use App\Models\Validation\Messages\InformativeValidator; use App\Models\Validation\Messages\InformativeValidator;
use App\Models\Validation\Messages\OkInformativeValidator; use App\Models\Validation\Validators\Validator;
use App\Models\Validation\Messages\NextInformativeValidator;
use App\Models\Validation\Validators\EmptyNameValidator;
use App\Models\Validation\Validators\ItemValidatorByName; use App\Models\Validation\Validators\ItemValidatorByName;
class ItemInformativeValidatorByNameFactory extends InformativeValidatorFactory class ItemInformativeValidatorByNameFactory extends InformativeValidatorByNameFactory
{ {
protected array $messages;
protected string $name;
public function __construct(string $name) public function __construct(string $name)
{ {
$this->messages = [ $this->setMessages([
'found' => 'A item with the name is valid.', 'found' => 'A item with the name is valid.',
'not_found' => 'A item with the name does not exist!!!', 'not_found' => 'A item with the name does not exist!!!',
'invalid_name' => 'The item name is empty, please, write the name!!!', 'invalid_name' => 'The item name is empty, please, write the name!!!',
]; ]);
$this->name = $name; $this->setName($name);
} }
function create(): InformativeValidator public function getValidatorByName(InformativeValidator $okValidator): Validator
{ {
$okValidator = new OkInformativeValidator($this->messages['found']); return new ItemValidatorByName($this->name, $okValidator);
$nameValidator = new NextInformativeValidator(
$this->messages['not_found'],
new ItemValidatorByName($this->name, $okValidator),
$okValidator
);
return new NextInformativeValidator(
$this->messages['invalid_name'],
new EmptyNameValidator($this->name, $nameValidator),
$nameValidator
);
} }
} }

Loading…
Cancel
Save