diff --git a/src/Controller/CaptchaController.php b/src/Controller/CaptchaController.php index 75f7c91..3f788ef 100644 --- a/src/Controller/CaptchaController.php +++ b/src/Controller/CaptchaController.php @@ -59,6 +59,7 @@ public function display($id = null) { if ($id === null) { $captcha = new Captcha(); } else { + /** @var \Captcha\Model\Entity\Captcha $captcha */ $captcha = $this->Captchas->find()->where(['uuid' => (string)$id])->firstOrFail(); } $captcha = $this->Preparer->prepare($captcha); diff --git a/src/Engine/Math/SimpleMath.php b/src/Engine/Math/SimpleMath.php index a875ff2..f09550f 100644 --- a/src/Engine/Math/SimpleMath.php +++ b/src/Engine/Math/SimpleMath.php @@ -57,11 +57,7 @@ public function getExpression(): string { public function getValue(): string { $operator = $this->data[1]; - if ($operator === '-') { - $value = $this->data[0] - $this->data[2]; - } else { - $value = $this->data[0] + $this->data[2]; - } + $value = $operator === '-' ? $this->data[0] - $this->data[2] : $this->data[0] + $this->data[2]; return (string)$value; } diff --git a/src/Engine/MathEngine.php b/src/Engine/MathEngine.php index 4d5ed27..b4a5059 100644 --- a/src/Engine/MathEngine.php +++ b/src/Engine/MathEngine.php @@ -83,16 +83,11 @@ protected function render($expression) { $formula = new expression_math(tableau_expression($expression)); $formula->dessine($this->_config['size']); ob_start(); - switch ($this->_config['imageFormat']) { - case static::FORMAT_JPEG: - imagejpeg($formula->image); - - break; - case static::FORMAT_PNG: - imagepng($formula->image); - - break; - } + match ($this->_config['imageFormat']) { + static::FORMAT_JPEG => imagejpeg($formula->image), + static::FORMAT_PNG => imagepng($formula->image), + default => null, + }; return ob_get_clean() ?: ''; } diff --git a/src/Model/Behavior/CaptchaBehavior.php b/src/Model/Behavior/CaptchaBehavior.php index 51d8620..e8e4f85 100644 --- a/src/Model/Behavior/CaptchaBehavior.php +++ b/src/Model/Behavior/CaptchaBehavior.php @@ -197,11 +197,8 @@ public function validateCaptchaMinTime($value, $context) { if (!$captcha) { return false; } - if ($captcha->created >= new DateTime('- ' . $this->getConfig('minTime') . ' seconds')) { - return false; - } - return true; + return $captcha->created < new DateTime('- ' . $this->getConfig('minTime') . ' seconds'); } /** @@ -215,11 +212,8 @@ public function validateCaptchaMaxTime($value, $context) { if (!$captcha) { return false; } - if ($captcha->created <= new DateTime('- ' . $this->getConfig('maxTime') . ' seconds')) { - return false; - } - return true; + return $captcha->created > new DateTime('- ' . $this->getConfig('maxTime') . ' seconds'); } /** @@ -259,7 +253,7 @@ public function validateCaptchaResult($value, $context) { * @return \Captcha\Model\Entity\Captcha|null */ protected function _getCaptcha(array $data) { - $uuid = !empty($data['captcha_uuid']) ? (string)$data['captcha_uuid'] : null; + $uuid = empty($data['captcha_uuid']) ? null : (string)$data['captcha_uuid']; if ($uuid && array_key_exists($uuid, $this->_captchas)) { $captcha = $this->_captchas[$uuid]; diff --git a/src/View/Helper/CaptchaHelper.php b/src/View/Helper/CaptchaHelper.php index 8cf4563..38b45c3 100644 --- a/src/View/Helper/CaptchaHelper.php +++ b/src/View/Helper/CaptchaHelper.php @@ -87,9 +87,8 @@ public function render(array $options = []) { $html = $this->control($options); } $html .= $this->Form->control('captcha_uuid', ['type' => 'hidden', 'value' => $id ?? '']); - $html .= $this->passive(); - return $html; + return $html . $this->passive(); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d7d26b3..bb89dfb 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,7 +14,7 @@ define('DS', DIRECTORY_SEPARATOR); } if (!defined('WINDOWS')) { - if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') { + if (DS === '\\' || str_starts_with(PHP_OS, 'WIN')) { define('WINDOWS', true); } else { define('WINDOWS', false); diff --git a/tests/schema.php b/tests/schema.php index 5ec5ed6..3352fa7 100644 --- a/tests/schema.php +++ b/tests/schema.php @@ -21,7 +21,7 @@ $tableObject = (new ReflectionClass($class))->getProperty('table'); $tableName = $tableObject->getDefaultValue(); - } catch (ReflectionException $e) { + } catch (ReflectionException) { continue; }