fix (ECS) apply coding standard
This commit is contained in:
parent
2ed4f74954
commit
478c64633e
|
@ -10,7 +10,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Generates a captcha via a URL
|
||||
* Generates a captcha via a URL.
|
||||
*
|
||||
* @author Jeremy Livingston <jeremy.j.livingston@gmail.com>
|
||||
*/
|
||||
|
|
|
@ -11,7 +11,7 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
|||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
/**
|
||||
* Extension used to load the configuration, set parameters, and initialize the captcha view
|
||||
* Extension used to load the configuration, set parameters, and initialize the captcha view.
|
||||
*
|
||||
* @author Gregwar <g.passault@gmail.com>
|
||||
*/
|
||||
|
@ -20,6 +20,7 @@ class GregwarCaptchaExtension extends Extension
|
|||
/**
|
||||
* @param array $configs
|
||||
* @param ContainerBuilder $container
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container): void
|
||||
|
|
|
@ -7,12 +7,11 @@ namespace Gregwar\CaptchaBundle\Generator;
|
|||
use Gregwar\Captcha\CaptchaBuilder;
|
||||
use Gregwar\Captcha\PhraseBuilder;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
use Gregwar\Captcha\CaptchaBuilderInterface;
|
||||
use Gregwar\Captcha\PhraseBuilderInterface;
|
||||
|
||||
/**
|
||||
* Uses configuration parameters to call the services that generate captcha images
|
||||
* Uses configuration parameters to call the services that generate captcha images.
|
||||
*
|
||||
* @author Gregwar <g.passault@gmail.com>
|
||||
* @author Jeremy Livingston <jeremy.j.livingston@gmail.com>
|
||||
|
@ -62,8 +61,10 @@ class CaptchaGenerator
|
|||
|
||||
// Returns the image generation URL
|
||||
if ($options['as_url']) {
|
||||
return $this->router->generate('gregwar_captcha.generate_captcha',
|
||||
array('key' => $options['session_key'], 'n' => md5(microtime(true).mt_rand())));
|
||||
return $this->router->generate(
|
||||
'gregwar_captcha.generate_captcha',
|
||||
array('key' => $options['session_key'], 'n' => md5(microtime(true).mt_rand()))
|
||||
);
|
||||
}
|
||||
|
||||
return 'data:image/jpeg;base64,'.base64_encode($this->generate($options));
|
||||
|
@ -82,7 +83,7 @@ class CaptchaGenerator
|
|||
$this->builder->setMaxBehindLines($options['max_behind_lines']);
|
||||
|
||||
if (isset($options['text_color']) && $options['text_color']) {
|
||||
if (count($options['text_color']) !== 3) {
|
||||
if (3 !== count($options['text_color'])) {
|
||||
throw new \RuntimeException('text_color should be an array of r, g and b');
|
||||
}
|
||||
|
||||
|
@ -91,7 +92,7 @@ class CaptchaGenerator
|
|||
}
|
||||
|
||||
if (isset($options['background_color']) && $options['background_color']) {
|
||||
if (count($options['background_color']) !== 3) {
|
||||
if (3 !== count($options['background_color'])) {
|
||||
throw new \RuntimeException('background_color should be an array of r, g and b');
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Gregwar\CaptchaBundle\Generator;
|
|||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
/**
|
||||
* Handles actions related to captcha image files including saving and garbage collection
|
||||
* Handles actions related to captcha image files including saving and garbage collection.
|
||||
*
|
||||
* @author Gregwar <g.passault@gmail.com>
|
||||
* @author Jeremy Livingston <jeremy@quizzle.com>
|
||||
|
@ -15,25 +15,29 @@ use Symfony\Component\Finder\Finder;
|
|||
class ImageFileHandler
|
||||
{
|
||||
/**
|
||||
* Name of folder for captcha images
|
||||
* Name of folder for captcha images.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $imageFolder;
|
||||
|
||||
/**
|
||||
* Absolute path to public web folder
|
||||
* Absolute path to public web folder.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $webPath;
|
||||
|
||||
/**
|
||||
* Frequency of garbage collection in fractions of 1
|
||||
* Frequency of garbage collection in fractions of 1.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $gcFreq;
|
||||
|
||||
/**
|
||||
* Maximum age of images in minutes
|
||||
* Maximum age of images in minutes.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expiration;
|
||||
|
@ -65,7 +69,7 @@ class ImageFileHandler
|
|||
|
||||
public function collectGarbage(): bool
|
||||
{
|
||||
if (!mt_rand(1, $this->gcFreq) == 1) {
|
||||
if (1 == !mt_rand(1, $this->gcFreq)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ use Gregwar\CaptchaBundle\Validator\CaptchaValidator;
|
|||
use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
|
||||
|
||||
/**
|
||||
* Captcha type
|
||||
* Captcha type.
|
||||
*
|
||||
* @author Gregwar <g.passault@gmail.com>
|
||||
*/
|
||||
|
@ -103,12 +103,12 @@ class CaptchaType extends AbstractType
|
|||
'image_id' => uniqid('captcha_'),
|
||||
'captcha_code' => $this->generator->getCaptchaCode($options),
|
||||
'value' => '',
|
||||
'is_human' => $isHuman
|
||||
'is_human' => $isHuman,
|
||||
));
|
||||
|
||||
$persistOptions = array();
|
||||
foreach (array('phrase', 'width', 'height', 'distortion', 'length',
|
||||
'quality', 'background_color', 'background_images', 'text_color') as $key) {
|
||||
'quality', 'background_color', 'background_images', 'text_color', ) as $key) {
|
||||
$persistOptions[$key] = $options[$key];
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use Symfony\Component\Form\FormEvent;
|
|||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* Captcha validator
|
||||
* Captcha validator.
|
||||
*
|
||||
* @author Gregwar <g.passault@gmail.com>
|
||||
*/
|
||||
|
@ -20,31 +20,36 @@ class CaptchaValidator
|
|||
private $session;
|
||||
|
||||
/**
|
||||
* Session key to store the code
|
||||
* Session key to store the code.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $key;
|
||||
|
||||
/**
|
||||
* Error message text for non-matching submissions
|
||||
* Error message text for non-matching submissions.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $invalidMessage;
|
||||
|
||||
/**
|
||||
* Configuration parameter used to bypass a required code match
|
||||
* Configuration parameter used to bypass a required code match.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $bypassCode;
|
||||
|
||||
/**
|
||||
* Number of form that the user can submit without captcha
|
||||
* Number of form that the user can submit without captcha.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $humanity;
|
||||
|
||||
/**
|
||||
* Translator
|
||||
* Translator.
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
@ -76,11 +81,12 @@ class CaptchaValidator
|
|||
$humanity = $this->getHumanity();
|
||||
if ($humanity > 0) {
|
||||
$this->updateHumanity($humanity - 1);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!($code !== null && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) {
|
||||
if (!(null !== $code && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) {
|
||||
$form->addError(new FormError($this->translator->trans($this->invalidMessage, array(), 'validators')));
|
||||
} else {
|
||||
if ($this->humanity > 0) {
|
||||
|
@ -96,7 +102,7 @@ class CaptchaValidator
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve the expected CAPTCHA code
|
||||
* Retrieve the expected CAPTCHA code.
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
|
@ -112,7 +118,7 @@ class CaptchaValidator
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve the humanity
|
||||
* Retrieve the humanity.
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
|
@ -136,14 +142,15 @@ class CaptchaValidator
|
|||
}
|
||||
|
||||
/**
|
||||
* Run a match comparison on the provided code and the expected code
|
||||
* Run a match comparison on the provided code and the expected code.
|
||||
*
|
||||
* @param string $code
|
||||
* @param string|null $expectedCode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function compare($code, $expectedCode): bool
|
||||
{
|
||||
return ($expectedCode !== null && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode));
|
||||
return null !== $expectedCode && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue