Skip to content
Commits auf Quelle (8)
tools/
phpstan.neon
.phpunit.result.cache
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="^1.10.67" installed="1.10.67" location="./tools/phpstan" copy="false"/>
</phive>
......@@ -15,6 +15,5 @@ QUI::$Ajax->registerFunction(
'package_quiqqer_captcha_ajax_getCurrentCaptchaControl',
function () {
return Handler::getDefaultCaptchaModuleControl()->create();
},
[]
}
);
{
"name": "quiqqer\/captcha",
"name": "quiqqer/captcha",
"type": "quiqqer-plugin",
"description": "QUIQQER Captcha controls",
"license": [
......@@ -10,20 +10,20 @@
{
"name": "Patrick M\u00fcller",
"email": "p.mueller@pcsg.de",
"homepage": "http:\/\/www.pcsg.de",
"homepage": "https://www.pcsg.de",
"role": "Developer"
}
],
"support": {
"email": "support@pcsg.de",
"url": "http:\/\/www.pcsg.de"
"url": "https://www.pcsg.de"
},
"require": {
"quiqqer\/quiqqer": ">=1.1|dev-master|dev-dev"
"quiqqer/core": "^2"
},
"autoload": {
"psr-4": {
"QUI\\Captcha\\": "src\/QUI\/Captcha"
"QUI\\Captcha\\": "src/QUI/Captcha"
}
}
}
\ No newline at end of file
<?xml version="1.0"?>
<ruleset>
<!-- Use PSR-12 ruleset -->
<rule ref="PSR12"/>
<!-- Only scan *.php files -->
<arg name="extensions" value="php"/>
<!-- Ignore warnings -->
<arg name="warning-severity" value="0"/>
<!-- Process 64 (or number of CPU cores) files in parallel -->
<arg name="parallel" value="64"/>
<!-- Output relative file paths, by setting the current folder as the basepath -->
<arg name="basepath" value="."/>
<!-- Show colored output -->
<arg name="colors"/>
<!-- Scan everything in the current folder -->
<file>.</file>
</ruleset>
includes:
- phpstan-baseline.neon
parameters:
level: 1
paths:
- src
- ajax
bootstrapFiles:
- tests/phpstan-bootstrap.php
......@@ -10,10 +10,10 @@ abstract class AbstractCaptcha implements CaptchaInterface
/**
* Get Captcha module title
*
* @param Locale $Locale (optional) - if omitted use \QUI::getLocale()
* @param Locale|null $Locale (optional) - if omitted use \QUI::getLocale()
* @return string
*/
public static function getTitle($Locale = null)
public static function getTitle(Locale $Locale = null): string
{
if (is_null($Locale)) {
$Locale = QUI::getLocale();
......@@ -25,10 +25,10 @@ abstract class AbstractCaptcha implements CaptchaInterface
/**
* Get Captcha module description
*
* @param Locale $Locale (optional) - if omitted use \QUI::getLocale()
* @param Locale|null $Locale (optional) - if omitted use \QUI::getLocale()
* @return string
*/
public static function getDescription($Locale = null)
public static function getDescription(Locale $Locale = null): string
{
if (is_null($Locale)) {
$Locale = QUI::getLocale();
......@@ -42,7 +42,7 @@ abstract class AbstractCaptcha implements CaptchaInterface
*
* @return string
*/
public static function getModuleName()
public static function getModuleName(): string
{
$parts = explode('\\', get_called_class());
return array_pop($parts);
......@@ -53,7 +53,7 @@ abstract class AbstractCaptcha implements CaptchaInterface
*
* @return bool
*/
public static function isInvisible()
public static function isInvisible(): bool
{
return false;
}
......
......@@ -2,7 +2,7 @@
namespace QUI\Captcha;
use QUI\Controls\Control;
use QUI\Control;
use QUI\Locale;
interface CaptchaInterface
......@@ -12,7 +12,7 @@ interface CaptchaInterface
*
* @return Control
*/
public static function getControl();
public static function getControl(): Control;
/**
* Validate captcha data
......@@ -20,42 +20,42 @@ interface CaptchaInterface
* @param string $data
* @return bool
*/
public static function isValid($data);
public static function isValid(string $data): bool;
/**
* Get Captcha module title
*
* @param Locale $Locale (optional) - if omitted use \QUI::getLocale()
* @param Locale|null $Locale (optional) - if omitted use \QUI::getLocale()
* @return string
*/
public static function getTitle($Locale = null);
public static function getTitle(Locale $Locale = null): string;
/**
* Get Captcha module description
*
* @param Locale $Locale (optional) - if omitted use \QUI::getLocale()
* @param Locale|null $Locale (optional) - if omitted use \QUI::getLocale()
* @return string
*/
public static function getDescription($Locale = null);
public static function getDescription(Locale $Locale = null): string;
/**
* Get Captcha module name
*
* @return string
*/
public static function getModuleName();
public static function getModuleName(): string;
/**
* Does this Captcha module require JavaScript?
*
* @return bool
*/
public static function requiresJavaScript();
public static function requiresJavaScript(): bool;
/**
* Check if this CAPTCHA has a visible representation or not
*
* @return bool
*/
public static function isInvisible();
public static function isInvisible(): bool;
}
......@@ -19,7 +19,7 @@ class CaptchaControl extends QUI\Control
* ControlWrapper constructor.
* @param array $attributes
*/
public function __construct(array $attributes = array())
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->addCSSClass('quiqqer-captcha-control');
......
......@@ -8,6 +8,7 @@ namespace QUI\Captcha\Controls;
use QUI;
use QUI\Captcha\Handler;
use QUI\Exception;
/**
* Class CaptchaDisplay
......@@ -20,7 +21,7 @@ class CaptchaDisplay extends QUI\Control
* ControlWrapper constructor.
* @param array $attributes
*/
public function __construct(array $attributes = array())
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
......@@ -31,14 +32,15 @@ class CaptchaDisplay extends QUI\Control
/**
* @return string
* @throws Exception
*/
public function getBody()
public function getBody(): string
{
$Engine = QUI::getTemplateManager()->getEngine();
$Engine->assign(array(
$Engine->assign([
'ModuleControl' => Handler::getDefaultCaptchaModuleControl()
));
]);
return $Engine->fetch(dirname(__FILE__) . '/CaptchaDisplay.html');
}
......@@ -48,7 +50,7 @@ class CaptchaDisplay extends QUI\Control
*
* @return bool
*/
public function isInvisible()
public function isInvisible(): bool
{
return Handler::isInvisible();
}
......
......@@ -9,6 +9,8 @@ namespace QUI\Captcha\Cookies;
use QUI;
use QUI\GDPR\CookieInterface;
use function sprintf;
/**
* Class QuiqqerSessionCookie
*
......@@ -45,7 +47,7 @@ class GoogleRecaptchaCookie implements CookieInterface
*/
public function getLifetime(): string
{
return \sprintf(
return sprintf(
'%d %s',
180,
QUI::getLocale()->get('quiqqer/quiqqer', 'days')
......
......@@ -3,7 +3,8 @@
namespace QUI\Captcha;
use QUI;
use QUI\Controls\Control;
use QUI\Control;
use QUI\Exception;
use QUI\Utils\System\File;
/**
......@@ -17,8 +18,9 @@ class Handler
* Get Control of the currently configures captcha module (if none set use default)
*
* @return Control|false
* @throws Exception
*/
public static function getDefaultCaptchaModuleControl()
public static function getDefaultCaptchaModuleControl(): Control|bool
{
$defaultModule = QUI::getPackage('quiqqer/captcha')->getConfig()->get('modules', 'defaultCaptcha');
$defaultModuleClass = self::getCaptchaModule($defaultModule);
......@@ -34,10 +36,11 @@ class Handler
* Validates a Captcha response with a Captcha module
*
* @param string $response
* @param string $module (optional) - Captcha module name [default: Default Captcha module]
* @param string|null $module (optional) - Captcha module name [default: Default Captcha module]
* @return bool
* @throws Exception
*/
public static function isResponseValid($response, $module = null)
public static function isResponseValid(string $response, string $module = null): bool
{
if (is_null($module)) {
$module = QUI::getPackage('quiqqer/captcha')->getConfig()->get('modules', 'defaultCaptcha');
......@@ -55,10 +58,11 @@ class Handler
/**
* Check if a Captcha module required JavaScript
*
* @param string $module (optional) - Captcha module name [default: Default Captcha module]
* @param string|null $module (optional) - Captcha module name [default: Default Captcha module]
* @return bool
* @throws Exception
*/
public static function requiresJavaScript($module = null)
public static function requiresJavaScript(string $module = null): bool
{
if (is_null($module)) {
$module = QUI::getPackage('quiqqer/captcha')->getConfig()->get('modules', 'defaultCaptcha');
......@@ -77,9 +81,9 @@ class Handler
* Get Captcha module by name
*
* @param string $name
* @return string - class path of Captcha module
* @return bool|string - class path of Captcha module
*/
public static function getCaptchaModule($name)
public static function getCaptchaModule(string $name): bool|string
{
$class = 'QUI\\Captcha\\Modules\\' . $name;
......@@ -93,11 +97,11 @@ class Handler
/**
* Check if the given CAPTCHA module is invisible
*
* @param string $response
* @param string $module (optional) - Captcha module name [default: Default Captcha module]
* @param string|null $module (optional) - Captcha module name [default: Default Captcha module]
* @return bool
* @throws Exception
*/
public static function isInvisible($module = null)
public static function isInvisible(string $module = null): bool
{
if (is_null($module)) {
$module = QUI::getPackage('quiqqer/captcha')->getConfig()->get('modules', 'defaultCaptcha');
......@@ -117,7 +121,7 @@ class Handler
*
* @return array
*/
public static function getList()
public static function getList(): array
{
$modules = [];
......
......@@ -12,7 +12,7 @@ class Google extends QUI\Captcha\AbstractCaptcha
*
* @return Control
*/
public static function getControl()
public static function getControl(): QUI\Control
{
return new Control();
}
......@@ -24,7 +24,7 @@ class Google extends QUI\Captcha\AbstractCaptcha
* @return bool
* @throws QUI\Exception
*/
public static function isValid($data)
public static function isValid(string $data): bool
{
$url = 'https://www.google.com/recaptcha/api/siteverify?';
$params = [
......@@ -71,7 +71,7 @@ class Google extends QUI\Captcha\AbstractCaptcha
* @return string|false
* @throws QUI\Exception
*/
public static function getSiteKey()
public static function getSiteKey(): bool|string
{
return QUI::getPackage('quiqqer/captcha')->getConfig()->getValue('google', 'siteKey');
}
......@@ -82,7 +82,7 @@ class Google extends QUI\Captcha\AbstractCaptcha
* @return string|false
* @throws QUI\Exception
*/
protected static function getSecretKey()
protected static function getSecretKey(): bool|string
{
return QUI::getPackage('quiqqer/captcha')->getConfig()->getValue('google', 'secretKey');
}
......@@ -92,7 +92,7 @@ class Google extends QUI\Captcha\AbstractCaptcha
*
* @return bool
*/
public static function requiresJavaScript()
public static function requiresJavaScript(): bool
{
return true;
}
......
......@@ -8,6 +8,7 @@ namespace QUI\Captcha\Modules\Google;
use QUI;
use QUI\Captcha\Modules\Google;
use QUI\Exception;
/**
* Class Controls
......@@ -19,8 +20,9 @@ class Control extends QUI\Captcha\Controls\CaptchaControl
/**
* ControlWrapper constructor.
* @param array $attributes
* @throws Exception
*/
public function __construct(array $attributes = array())
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
......@@ -35,7 +37,7 @@ class Control extends QUI\Captcha\Controls\CaptchaControl
/**
* @return string
*/
public function getBody()
public function getBody(): string
{
$Engine = QUI::getTemplateManager()->getEngine();
return $Engine->fetch(dirname(__FILE__) . '/Control.html');
......
......@@ -11,7 +11,7 @@ class GoogleInvisible extends Google
*
* @return Control
*/
public static function getControl()
public static function getControl(): Control
{
return new Control();
}
......@@ -21,7 +21,7 @@ class GoogleInvisible extends Google
*
* @return bool
*/
public static function isInvisible()
public static function isInvisible(): bool
{
return true;
}
......
......@@ -6,8 +6,8 @@
namespace QUI\Captcha\Modules\GoogleInvisible;
use QUI;
use QUI\Captcha\Modules\Google\Control as GoogleControl;
use QUI\Exception;
/**
* Class Controls
......@@ -19,6 +19,7 @@ class Control extends GoogleControl
/**
* ControlWrapper constructor.
* @param array $attributes
* @throws Exception
*/
public function __construct(array $attributes = [])
{
......
......@@ -17,7 +17,7 @@ class GoogleV3 extends Google
*
* @return Control
*/
public static function getControl()
public static function getControl(): QUI\Control
{
return new Control();
}
......@@ -27,7 +27,7 @@ class GoogleV3 extends Google
*
* @return bool
*/
public static function isInvisible()
public static function isInvisible(): bool
{
return true;
}
......@@ -39,7 +39,7 @@ class GoogleV3 extends Google
* @return bool
* @throws QUI\Exception
*/
public static function isValid($data)
public static function isValid(string $data): bool
{
$url = 'https://www.google.com/recaptcha/api/siteverify?';
$params = [
......
......@@ -2,8 +2,8 @@
namespace QUI\Captcha\Modules\GoogleV3;
use QUI;
use QUI\Captcha\Modules\Google\Control as GoogleControl;
use QUI\Exception;
/**
* Class Controls
......@@ -15,6 +15,7 @@ class Control extends GoogleControl
/**
* ControlWrapper constructor.
* @param array $attributes
* @throws Exception
*/
public function __construct(array $attributes = [])
{
......
......@@ -2,6 +2,7 @@
namespace QUI\Captcha\Modules;
use Exception;
use QUI;
use QUI\Captcha\Modules\SimpleMath\Control;
......@@ -20,7 +21,7 @@ class SimpleMath extends QUI\Captcha\AbstractCaptcha
*
* @return Control
*/
public static function getControl()
public static function getControl(): QUI\Control
{
return new Control();
}
......@@ -30,9 +31,8 @@ class SimpleMath extends QUI\Captcha\AbstractCaptcha
*
* @param string $data
* @return bool
* @throws QUI\Exception
*/
public static function isValid($data)
public static function isValid(string $data): bool
{
$problem = QUI::getSession()->get(self::SESSION_KEY_SIMPLE_MATH_PROBLEM);
......@@ -52,14 +52,14 @@ class SimpleMath extends QUI\Captcha\AbstractCaptcha
{
try {
$a = random_int(1, 9);
} catch (\Exception $Exception) {
} catch (Exception $Exception) {
QUI\System\Log::writeException($Exception);
$a = mt_rand(1, 9);
}
try {
$b = random_int(1, 9);
} catch (\Exception $Exception) {
} catch (Exception $Exception) {
QUI\System\Log::writeException($Exception);
$b = mt_rand(1, 9);
}
......@@ -76,7 +76,7 @@ class SimpleMath extends QUI\Captcha\AbstractCaptcha
*
* @return bool
*/
public static function requiresJavaScript()
public static function requiresJavaScript(): bool
{
return false;
}
......