diff --git a/src/Admin/Backend.php b/src/Admin/Backend.php index f06b786..44b771d 100644 --- a/src/Admin/Backend.php +++ b/src/Admin/Backend.php @@ -504,9 +504,9 @@ class Backend string $data, string $key_name, string $key_value, - string $associate = null, - string $file = null, - string $db_schema = null, + ?string $associate = null, + ?string $file = null, + ?string $db_schema = null, ): void { /** @var string $DB_SCHEMA check schema */ $DB_SCHEMA = 'public'; diff --git a/src/Basic.php b/src/Basic.php index d069486..065ec63 100644 --- a/src/Basic.php +++ b/src/Basic.php @@ -90,7 +90,7 @@ class Basic * @deprecated DO NOT USE Class\Basic anymore. Use dedicated logger and sub classes */ public function __construct( - \CoreLibs\Logging\Logging $log = null, + ?\CoreLibs\Logging\Logging $log = null, ?string $session_name = null ) { trigger_error('Class \CoreLibs\Basic is deprected', E_USER_DEPRECATED); diff --git a/src/Convert/Extends/SetVarTypeMain.php b/src/Convert/Extends/SetVarTypeMain.php index d32e416..7d4601c 100644 --- a/src/Convert/Extends/SetVarTypeMain.php +++ b/src/Convert/Extends/SetVarTypeMain.php @@ -52,7 +52,7 @@ class SetVarTypeMain */ protected static function makeStrMain( mixed $val, - string $default = null, + ?string $default = null, bool $to_null = false ): ?string { // int/float/string/bool/null, everything else is ignored @@ -113,7 +113,7 @@ class SetVarTypeMain */ protected static function makeIntMain( mixed $val, - int $default = null, + ?int $default = null, bool $to_null = false ): ?int { // if we can filter it to a valid int, we can convert it @@ -167,7 +167,7 @@ class SetVarTypeMain */ protected static function makeFloatMain( mixed $val, - float $default = null, + ?float $default = null, bool $to_null = false ): ?float { if ( diff --git a/src/Convert/SetVarTypeNull.php b/src/Convert/SetVarTypeNull.php index 6d2c161..12d22e4 100644 --- a/src/Convert/SetVarTypeNull.php +++ b/src/Convert/SetVarTypeNull.php @@ -35,7 +35,7 @@ class SetVarTypeNull extends Extends\SetVarTypeMain * @param string|null $default Default override value * @return string|null Input value as string or default as string/null */ - public static function makeStr(mixed $val, string $default = null): ?string + public static function makeStr(mixed $val, ?string $default = null): ?string { return SetVarTypeMain::makeStrMain($val, $default, true); } @@ -60,7 +60,7 @@ class SetVarTypeNull extends Extends\SetVarTypeMain * @param int|null $default Default override value * @return int|null Input value as int or default as int/null */ - public static function makeInt(mixed $val, int $default = null): ?int + public static function makeInt(mixed $val, ?int $default = null): ?int { return SetVarTypeMain::makeIntMain($val, $default, true); } @@ -84,7 +84,7 @@ class SetVarTypeNull extends Extends\SetVarTypeMain * @param float|null $default Default override value * @return float|null Input value as float or default as float/null */ - public static function makeFloat(mixed $val, float $default = null): ?float + public static function makeFloat(mixed $val, ?float $default = null): ?float { return SetVarTypeMain::makeFloatMain($val, $default, true); } diff --git a/src/DB/IO.php b/src/DB/IO.php index c28471e..a006b1a 100644 --- a/src/DB/IO.php +++ b/src/DB/IO.php @@ -1896,7 +1896,12 @@ class IO $matches = []; // compare has =, >, < prefix, and gets stripped // if the rest is not X.Y format then error - preg_match("/^([<>=]{1,})(\d{1,})\.(\d{1,})/", $compare, $matches); + if (!preg_match("/^([<>=]{1,})(\d{1,})\.(\d{1,})/", $compare, $matches)) { + $this->log->error('Could not regex match compare version string', [ + "compare" => $compare + ]); + return false; + } $compare = $matches[1]; $to_master = $matches[2]; $to_minor = $matches[3]; @@ -1908,11 +1913,18 @@ class IO } // db_version can return X.Y.Z // we only compare the first two - preg_match( - "/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/", - $this->dbVersion(), - $matches - ); + if ( + !preg_match( + "/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/", + $this->dbVersion(), + $matches + ) + ) { + $this->log->error('Could not regex match dbVersion string', [ + "dbVersion" => $this->dbVersion() + ]); + return false; + } $master = $matches[1]; $minor = $matches[2]; $version = $master . ($minor < 10 ? '0' : '') . $minor; diff --git a/src/Language/GetLocale.php b/src/Language/GetLocale.php index 1f7842f..d0e6f9e 100644 --- a/src/Language/GetLocale.php +++ b/src/Language/GetLocale.php @@ -128,7 +128,7 @@ class GetLocale $matches ) ) { - $lang = ($matches['lang'] ?? 'en') + $lang = $matches['lang'] // add country only if set . (!empty($matches['country']) ? '_' . $matches['country'] : ''); } else { @@ -235,7 +235,7 @@ class GetLocale $matches ) ) { - $lang = ($matches['lang'] ?? 'en') + $lang = $matches['lang'] // add country only if set . (!empty($matches['country']) ? '_' . $matches['country'] : ''); } else { diff --git a/src/Logging/Logger/MessageLevel.php b/src/Logging/Logger/MessageLevel.php index 8efc8bc..c03033e 100644 --- a/src/Logging/Logger/MessageLevel.php +++ b/src/Logging/Logger/MessageLevel.php @@ -14,6 +14,7 @@ namespace CoreLibs\Logging\Logger; enum MessageLevel: int { case ok = 100; + case success = 110; // special for file uploads case info = 200; case notice = 250; case warn = 300; @@ -30,6 +31,7 @@ enum MessageLevel: int { return match (strtolower($name)) { 'ok' => self::ok, + 'success' => self::success, 'info' => self::info, 'notice' => self::notice, 'warn', 'warning' => self::warn, diff --git a/src/Output/Form/Elements.php b/src/Output/Form/Elements.php index b6ee9d8..6fbd38e 100644 --- a/src/Output/Form/Elements.php +++ b/src/Output/Form/Elements.php @@ -194,13 +194,13 @@ class Elements "/(mailto:)?(\>)?\b([\w\.-]+)@([\w\.\-]+)\.([a-zA-Z]{2,4})\b(\|([^\||^#]+)(#([^\|]+))?\|)?/", function ($matches) { return self::createEmail( - $matches[1] ?? '', - $matches[2] ?? '', - $matches[3] ?? '', - $matches[4] ?? '', - $matches[5] ?? '', + $matches[1], + $matches[2], + $matches[3], + $matches[4], + $matches[5], $matches[7] ?? '', - $matches[9] ?? '' + $matches[9] ?? '', ); }, $output diff --git a/src/Template/HtmlBuilder/Element.php b/src/Template/HtmlBuilder/Element.php index 85d5874..d9c2cc1 100644 --- a/src/Template/HtmlBuilder/Element.php +++ b/src/Template/HtmlBuilder/Element.php @@ -401,7 +401,7 @@ class Element * @param bool $add_nl [default=false] Optional output string line breaks * @return string HTML as string */ - public function buildHtml(Element $tree = null, bool $add_nl = false): string + public function buildHtml(?Element $tree = null, bool $add_nl = false): string { // print "D01: " . microtime(true) . "
"; if ($tree === null) { @@ -533,7 +533,7 @@ class Element * @return string build html as string * @deprecated Do not use, use Element->buildHtml() instead */ - public static function printHtmlFromObject(Element $tree = null, bool $add_nl = false): string + public static function printHtmlFromObject(?Element $tree = null, bool $add_nl = false): string { // nothing ->bad if ($tree === null) { diff --git a/test/phpunit/Logging/CoreLibsLoggingErrorMessagesTest.php b/test/phpunit/Logging/CoreLibsLoggingErrorMessagesTest.php index 7e1729c..a92b444 100644 --- a/test/phpunit/Logging/CoreLibsLoggingErrorMessagesTest.php +++ b/test/phpunit/Logging/CoreLibsLoggingErrorMessagesTest.php @@ -39,6 +39,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'str' => 'OK', 'expected' => 'ok', ], + 'success' => [ + 'level' => 'success', + 'str' => 'SUCCESS', + 'expected' => 'success', + ], 'info' => [ 'level' => 'info', 'str' => 'INFO',