mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -21,7 +21,7 @@ class RoleScopeScopePresenceConstraint extends Constraint
|
||||
public $messageNullRequired = 'The role "%role%" should not be associated with a scope.';
|
||||
|
||||
public $messagePresenceRequired = 'The role "%role%" require to be associated with '
|
||||
. 'a scope.';
|
||||
.'a scope.';
|
||||
|
||||
public function getTargets()
|
||||
{
|
||||
|
@@ -15,13 +15,10 @@ use Chill\MainBundle\Entity\RoleScope;
|
||||
use Chill\MainBundle\Security\RoleProvider;
|
||||
use Chill\MainBundle\Validation\Constraint\RoleScopeScopePresenceConstraint;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function in_array;
|
||||
|
||||
class RoleScopeScopePresence extends ConstraintValidator
|
||||
{
|
||||
public function __construct(private readonly RoleProvider $roleProvider, private readonly LoggerInterface $logger, private readonly TranslatorInterface $translator) {}
|
||||
@@ -29,19 +26,19 @@ class RoleScopeScopePresence extends ConstraintValidator
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!$value instanceof RoleScope) {
|
||||
throw new RuntimeException('The validated object is not an instance of roleScope');
|
||||
throw new \RuntimeException('The validated object is not an instance of roleScope');
|
||||
}
|
||||
|
||||
if (!$constraint instanceof RoleScopeScopePresenceConstraint) {
|
||||
throw new RuntimeException('This validator should be used with RoleScopScopePresenceConstraint');
|
||||
throw new \RuntimeException('This validator should be used with RoleScopScopePresenceConstraint');
|
||||
}
|
||||
|
||||
$this->logger->debug('begin validation of a role scope instance');
|
||||
|
||||
//if the role scope should have a scope
|
||||
// if the role scope should have a scope
|
||||
if (
|
||||
!in_array($value->getRole(), $this->roleProvider->getRolesWithoutScopes(), true)
|
||||
&& $value->getScope() === null
|
||||
!\in_array($value->getRole(), $this->roleProvider->getRolesWithoutScopes(), true)
|
||||
&& null === $value->getScope()
|
||||
) {
|
||||
$this->context->buildViolation($constraint->messagePresenceRequired)
|
||||
->setParameter('%role%', $this->translator->trans($value->getRole()))
|
||||
@@ -49,7 +46,7 @@ class RoleScopeScopePresence extends ConstraintValidator
|
||||
$this->logger->debug('the role scope should have a scope, but scope is null. Violation build.');
|
||||
} elseif // if the scope should be null
|
||||
(
|
||||
in_array($value->getRole(), $this->roleProvider->getRolesWithoutScopes(), true)
|
||||
\in_array($value->getRole(), $this->roleProvider->getRolesWithoutScopes(), true)
|
||||
&& null !== $value->getScope()
|
||||
) {
|
||||
$this->context->buildViolation($constraint->messageNullRequired)
|
||||
|
@@ -15,7 +15,6 @@ use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class UserUniqueEmailAndUsername extends ConstraintValidator
|
||||
{
|
||||
@@ -32,16 +31,15 @@ class UserUniqueEmailAndUsername extends ConstraintValidator
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!$value instanceof User) {
|
||||
throw new UnexpectedValueException('This validation should happens '
|
||||
. 'only on class ' . User::class);
|
||||
throw new \UnexpectedValueException('This validation should happens only on class '.User::class);
|
||||
}
|
||||
|
||||
if ($value->getId() !== null) {
|
||||
if (null !== $value->getId()) {
|
||||
$countUsersByUsername = $this->em->createQuery(
|
||||
sprintf(
|
||||
'SELECT COUNT(u) FROM %s u '
|
||||
. 'WHERE u.usernameCanonical = LOWER(UNACCENT(:username)) '
|
||||
. 'AND u != :user',
|
||||
.'WHERE u.usernameCanonical = LOWER(UNACCENT(:username)) '
|
||||
.'AND u != :user',
|
||||
User::class
|
||||
)
|
||||
)
|
||||
@@ -52,7 +50,7 @@ class UserUniqueEmailAndUsername extends ConstraintValidator
|
||||
$countUsersByUsername = $this->em->createQuery(
|
||||
sprintf(
|
||||
'SELECT COUNT(u) FROM %s u '
|
||||
. 'WHERE u.usernameCanonical = LOWER(UNACCENT(:username)) ',
|
||||
.'WHERE u.usernameCanonical = LOWER(UNACCENT(:username)) ',
|
||||
User::class
|
||||
)
|
||||
)
|
||||
@@ -70,12 +68,12 @@ class UserUniqueEmailAndUsername extends ConstraintValidator
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
if ($value->getId() !== null) {
|
||||
if (null !== $value->getId()) {
|
||||
$countUsersByEmail = $this->em->createQuery(
|
||||
sprintf(
|
||||
'SELECT COUNT(u) FROM %s u '
|
||||
. 'WHERE u.emailCanonical = LOWER(UNACCENT(:email)) '
|
||||
. 'AND u != :user',
|
||||
.'WHERE u.emailCanonical = LOWER(UNACCENT(:email)) '
|
||||
.'AND u != :user',
|
||||
User::class
|
||||
)
|
||||
)
|
||||
@@ -86,7 +84,7 @@ class UserUniqueEmailAndUsername extends ConstraintValidator
|
||||
$countUsersByEmail = $this->em->createQuery(
|
||||
sprintf(
|
||||
'SELECT COUNT(u) FROM %s u '
|
||||
. 'WHERE u.emailCanonical = LOWER(UNACCENT(:email))',
|
||||
.'WHERE u.emailCanonical = LOWER(UNACCENT(:email))',
|
||||
User::class
|
||||
)
|
||||
)
|
||||
|
@@ -12,7 +12,6 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Validation\Validator;
|
||||
|
||||
use Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface;
|
||||
use LogicException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
@@ -22,7 +21,7 @@ final class ValidPhonenumber extends ConstraintValidator
|
||||
public function __construct(private readonly LoggerInterface $logger, private readonly PhoneNumberHelperInterface $phonenumberHelper) {}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @param string $value
|
||||
* @param \Chill\MainBundle\Validation\Constraint\PhonenumberConstraint $constraint
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
@@ -57,8 +56,7 @@ final class ValidPhonenumber extends ConstraintValidator
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new LogicException(sprintf("This type '%s' is not implemented. "
|
||||
. "Possible values are 'mobile', 'landline' or 'any'", $constraint->type));
|
||||
throw new \LogicException(sprintf("This type '%s' is not implemented. Possible values are 'mobile', 'landline' or 'any'", $constraint->type));
|
||||
}
|
||||
|
||||
if (false === $isValid) {
|
||||
|
Reference in New Issue
Block a user