Refactor to use UserInformativeValidatorByMatrixUserNameFactory.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
+1
-15
@@ -9,9 +9,7 @@ use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use App\Models\Validation\ValidationByNameInterface;
|
||||
|
||||
class User extends Authenticatable implements ValidationByNameInterface
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
@@ -29,18 +27,6 @@ class User extends Authenticatable implements ValidationByNameInterface
|
||||
|
||||
|
||||
|
||||
public static function isExistByName(string $name): bool
|
||||
{
|
||||
$count = User::where('matrix_username', $name)->count();
|
||||
|
||||
return $count != 0;
|
||||
}
|
||||
|
||||
public static function isNameValid(string $name): bool
|
||||
{
|
||||
return $name != '';
|
||||
}
|
||||
|
||||
public function userAddresses(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserAddress::class);
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Messages\BaseMessages;
|
||||
|
||||
class UserMessagesFactory
|
||||
{
|
||||
protected array $messages = [
|
||||
'found' => 'A user with the username is valid.',
|
||||
'not_found' => 'A user with the username does not exist!!!',
|
||||
'invalid_name' => 'The username is empty, please, write username!!!',
|
||||
];
|
||||
|
||||
public function create()
|
||||
{
|
||||
return new BaseMessages($this->messages);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation;
|
||||
|
||||
use App\Models\Validation\ModelValidationByName;
|
||||
use App\Models\Validation\Messages\UserMessagesFactory;
|
||||
|
||||
class UserValidationByMatrixUsername extends ModelValidationByName
|
||||
{
|
||||
public function __construct(string $name)
|
||||
{
|
||||
parent::__construct(
|
||||
$name,
|
||||
'App\Models\User',
|
||||
(new UserMessagesFactory())->create(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user