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,59 +1,45 @@
<?php
/*
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
/**
* Chill is a software for social workers
*
* 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/>.
* 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\Security\RoleProvider;
use Chill\MainBundle\Entity\RoleScope;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Chill\MainBundle\Security\RoleProvider;
use Chill\MainBundle\Validation\Constraint\RoleScopeScopePresenceConstraint;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class RoleScopeScopePresence extends ConstraintValidator
{
/**
*
* @var RoleProvider
*/
private $roleProvider;
/**
*
* @var LoggerInterface
*/
private $logger;
/**
* @var RoleProvider
*/
private $roleProvider;
/**
*
* @var TranslatorInterface
*/
private $translator;
public function __construct(RoleProvider $roleProvider, LoggerInterface $logger,
TranslatorInterface $translator)
public function __construct(
RoleProvider $roleProvider,
LoggerInterface $logger,
TranslatorInterface $translator
)
{
$this->roleProvider = $roleProvider;
$this->logger = $logger;
@@ -62,41 +48,37 @@ 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');
if (!$value instanceof 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');
if (!$constraint instanceof RoleScopeScopePresenceConstraint) {
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 (
!in_array($value->getRole(), $this->roleProvider->getRolesWithoutScopes())
&&
$value->getScope() === NULL
&& $value->getScope() === null
) {
$this->context->buildViolation($constraint->messagePresenceRequired)
->setParameter('%role%', $this->translator->trans($value->getRole()))
->addViolation();
->setParameter('%role%', $this->translator->trans($value->getRole()))
->addViolation();
$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())
&&
! is_null($value->getScope())
)
{
&& !is_null($value->getScope())
) {
$this->context->buildViolation($constraint->messageNullRequired)
->setParameter('%role%', $this->translator->trans($value->getRole()))
->addViolation();
->setParameter('%role%', $this->translator->trans($value->getRole()))
->addViolation();
$this->logger->debug('the role scole should not have a scope, but scope is not null. Violation build.');
} // everything is fine !
else {
$this->logger->debug('role scope is valid. Validation finished.');
}
}
}