mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-23 08:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,41 +1,29 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Champs-Libres <info@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\Phonenumber\PhonenumberHelper;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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\Phonenumber\PhonenumberHelper;
|
||||
use LogicException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
class ValidPhonenumber extends ConstraintValidator
|
||||
{
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var PhonenumberHelper
|
||||
*/
|
||||
protected $phonenumberHelper;
|
||||
|
||||
protected $logger;
|
||||
|
||||
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
PhonenumberHelper $phonenumberHelper
|
||||
@@ -43,45 +31,49 @@ class ValidPhonenumber extends ConstraintValidator
|
||||
$this->phonenumberHelper = $phonenumberHelper;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $value
|
||||
* @param \Chill\MainBundle\Validation\Constraint\PhonenumberConstraint $constraint
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (FALSE === $this->phonenumberHelper->isPhonenumberValidationConfigured()) {
|
||||
if (false === $this->phonenumberHelper->isPhonenumberValidationConfigured()) {
|
||||
$this->logger->debug('[phonenumber] skipping validation due to not configured helper');
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch($constraint->type) {
|
||||
|
||||
switch ($constraint->type) {
|
||||
case 'landline':
|
||||
$isValid = $this->phonenumberHelper->isValidPhonenumberLandOrVoip($value);
|
||||
$message = $constraint->notLandlineMessage;
|
||||
|
||||
break;
|
||||
|
||||
case 'mobile':
|
||||
$isValid = $this->phonenumberHelper->isValidPhonenumberMobile($value);
|
||||
$message = $constraint->notMobileMessage;
|
||||
|
||||
break;
|
||||
|
||||
case 'any':
|
||||
$isValid = $this->phonenumberHelper->isValidPhonenumberAny($value);
|
||||
$message = $constraint->notValidMessage;
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
throw new \LogicException(sprintf("This type '%s' is not implemented. "
|
||||
throw new LogicException(sprintf("This type '%s' is not implemented. "
|
||||
. "Possible values are 'mobile', 'landline' or 'any'", $constraint->type));
|
||||
}
|
||||
|
||||
if (FALSE === $isValid) {
|
||||
$this->context->addViolation($message, [ '%phonenumber%' => $value ]);
|
||||
|
||||
if (false === $isValid) {
|
||||
$this->context->addViolation($message, ['%phonenumber%' => $value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user