Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Controller/CaptchaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions src/Engine/Math/SimpleMath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 5 additions & 10 deletions src/Engine/MathEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?: '';
}
Expand Down
12 changes: 3 additions & 9 deletions src/Model/Behavior/CaptchaBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 1 addition & 2 deletions src/View/Helper/CaptchaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$tableObject = (new ReflectionClass($class))->getProperty('table');
$tableName = $tableObject->getDefaultValue();

} catch (ReflectionException $e) {
} catch (ReflectionException) {
continue;
}

Expand Down
Loading