cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,117 +1,105 @@
<?php
/*
* Copyright (C) 2018 Julien Fastré <julien.fastre@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\MainBundle\Validation\Validator;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Constraint;
use Chill\MainBundle\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
/**
*
* Chill is a software for social workers
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Validation\Validator;
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
{
/**
*
* @var EntityManagerInterface
*/
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
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) {
$countUsersByUsername = $this->em->createQuery(
sprintf(
"SELECT COUNT(u) FROM %s u "
. "WHERE u.usernameCanonical = LOWER(UNACCENT(:username)) "
. "AND u != :user",
User::class)
'SELECT COUNT(u) FROM %s u '
. 'WHERE u.usernameCanonical = LOWER(UNACCENT(:username)) '
. 'AND u != :user',
User::class
)
)
->setParameter('username', $value->getUsername())
->setParameter('user', $value)
->getSingleScalarResult();
} else {
$countUsersByUsername = $this->em->createQuery(
sprintf(
"SELECT COUNT(u) FROM %s u "
. "WHERE u.usernameCanonical = LOWER(UNACCENT(:username)) ",
User::class)
'SELECT COUNT(u) FROM %s u '
. 'WHERE u.usernameCanonical = LOWER(UNACCENT(:username)) ',
User::class
)
)
->setParameter('username', $value->getUsername())
->getSingleScalarResult();
}
if ($countUsersByUsername > 0) {
if (0 < $countUsersByUsername) {
$this->context
->buildViolation($constraint->messageDuplicateUsername)
->setParameters([
'%username%' => $value->getUsername()
'%username%' => $value->getUsername(),
])
->atPath('username')
->addViolation()
;
->addViolation();
}
if ($value->getId() !== null) {
$countUsersByEmail = $this->em->createQuery(
sprintf(
"SELECT COUNT(u) FROM %s u "
. "WHERE u.emailCanonical = LOWER(UNACCENT(:email)) "
. "AND u != :user",
User::class)
'SELECT COUNT(u) FROM %s u '
. 'WHERE u.emailCanonical = LOWER(UNACCENT(:email)) '
. 'AND u != :user',
User::class
)
)
->setParameter('email', $value->getEmail())
->setParameter('user', $value)
->getSingleScalarResult();
} else {
$countUsersByEmail = $this->em->createQuery(
sprintf(
"SELECT COUNT(u) FROM %s u "
. "WHERE u.emailCanonical = LOWER(UNACCENT(:email))",
User::class)
'SELECT COUNT(u) FROM %s u '
. 'WHERE u.emailCanonical = LOWER(UNACCENT(:email))',
User::class
)
)
->setParameter('email', $value->getEmail())
->getSingleScalarResult();
}
if ($countUsersByEmail > 0) {
if (0 < $countUsersByEmail) {
$this->context
->buildViolation($constraint->messageDuplicateEmail)
->setParameters([
'%email%' => $value->getEmail()
'%email%' => $value->getEmail(),
])
->atPath('email')
->addViolation()
;
->addViolation();
}
}
}