diff --git a/src/ACL/Login.php b/src/ACL/Login.php index 890119f..205bd49 100644 --- a/src/ACL/Login.php +++ b/src/ACL/Login.php @@ -423,14 +423,9 @@ class Login // LOGOUT TARGET if (!isset($options['logout_target'])) { - if (defined('LOGOUT_TARGET')) { - trigger_error( - 'loginMainCall: LOGOUT_TARGET should not be used', - E_USER_DEPRECATED - ); - $options['logout_target'] = LOGOUT_TARGET; - $this->logout_target = $options['logout_target']; - } + // defaults to '' + $options['logout_target'] = ''; + $this->logout_target = $options['logout_target']; } // *** PASSWORD SETTINGS diff --git a/src/Basic.php b/src/Basic.php index db57672..c259bd7 100644 --- a/src/Basic.php +++ b/src/Basic.php @@ -103,11 +103,7 @@ class Basic 'VIDEOS', 'DOCUMENTS', 'PDFS', 'BINARIES', 'ICONS', 'UPLOADS', 'CSV', 'JS', 'CSS', 'TABLE_ARRAYS', 'SMARTY', 'LANG', 'CACHE', 'TMP', 'LOG', 'TEMPLATES', 'TEMPLATES_C', 'DEFAULT_LANG', 'DEFAULT_ENCODING', 'DEFAULT_HASH', - 'DEFAULT_ACL_LEVEL', 'LOGOUT_TARGET', 'PASSWORD_CHANGE', 'AJAX_REQUEST_TYPE', - 'USE_PROTOTYPE', 'USE_SCRIPTACULOUS', 'USE_JQUERY', 'PAGE_WIDTH', - 'MASTER_TEMPLATE_NAME', 'PUBLIC_SCHEMA', 'TEST_SCHEMA', 'DEV_SCHEMA', - 'LIVE_SCHEMA', 'DB_CONFIG_NAME', 'DB_CONFIG', 'TARGET', 'DEBUG', - 'SHOW_ALL_ERRORS' + 'DB_CONFIG_NAME', 'DB_CONFIG', 'TARGET' ] as $constant ) { if (!defined($constant)) { diff --git a/src/Combined/DateTime.php b/src/Combined/DateTime.php index d123c53..b86bdee 100644 --- a/src/Combined/DateTime.php +++ b/src/Combined/DateTime.php @@ -714,6 +714,66 @@ class DateTime } } + /** + * wrapper for calcDaysInterval with numeric return only + * + * @param string $start_date valid start date (y/m/d) + * @param string $end_date valid end date (y/m/d) + * @param bool $include_end_date [default=true] include end date in calc + * @param bool $exclude_start_date [default=false] include end date in calc + * @return array{0:int,1:int,2:int,3:bool} + */ + public static function calcDaysIntervalNumIndex( + string $start_date, + string $end_date, + bool $include_end_date = true, + bool $exclude_start_date = false + ): array { + $values = self::calcDaysInterval( + $start_date, + $end_date, + false, + $include_end_date, + $exclude_start_date + ); + return [ + $values[0] ?? 0, + $values[1] ?? 0, + $values[2] ?? 0, + $values[3] ?? false, + ]; + } + + /** + * wrapper for calcDaysInterval with named return only + * + * @param string $start_date valid start date (y/m/d) + * @param string $end_date valid end date (y/m/d) + * @param bool $include_end_date [default=true] include end date in calc + * @param bool $exclude_start_date [default=false] include end date in calc + * @return array{overall:int,weekday:int,weekend:int,reverse:bool} + */ + public static function calcDaysIntervalNamedIndex( + string $start_date, + string $end_date, + bool $include_end_date = true, + bool $exclude_start_date = false + ): array { + $values = self::calcDaysInterval( + $start_date, + $end_date, + true, + $include_end_date, + $exclude_start_date + ); + return [ + 'overall' => $values['overall'] ?? 0, + 'weekday' => $values['weekday'] ?? 0, + 'weekend' => $values['weekend'] ?? 0, + 'reverse' => $values['reverse'] ?? false, + ]; + } + /** * check if a weekend day (sat/sun) is in the given date range * Can have time too, but is not needed diff --git a/src/Convert/Html.php b/src/Convert/Html.php index 2094dc5..ae05766 100644 --- a/src/Convert/Html.php +++ b/src/Convert/Html.php @@ -10,9 +10,16 @@ namespace CoreLibs\Convert; class Html { + /** @var int */ public const SELECTED = 0; + /** @var int */ public const CHECKED = 1; + // TODO: check for not valid htmlentites encoding + // as of PHP 8.4: https://www.php.net/manual/en/function.htmlentities.php + /** @#var array */ + // public const VALID_HTMLENT_ENCODINGS = []; + /** * full wrapper for html entities * @@ -22,14 +29,19 @@ class Html * encodes in UTF-8 * does not double encode * - * @param mixed $string string to html encode - * @param int $flags [default: ENT_QUOTES | ENT_HTML5] + * @param mixed $string string to html encode + * @param int $flags [default=ENT_QUOTES | ENT_HTML5] + * @param string $encoding [default=UTF-8] * @return mixed if string, encoded, else as is (eg null) */ - public static function htmlent(mixed $string, int $flags = ENT_QUOTES | ENT_HTML5): mixed - { + public static function htmlent( + mixed $string, + int $flags = ENT_QUOTES | ENT_HTML5, + string $encoding = 'UTF-8' + ): mixed { if (is_string($string)) { - return htmlentities($string, $flags, 'UTF-8', false); + // if not a valid encoding this will throw a warning and use UTF-8 + return htmlentities($string, $flags, $encoding, false); } return $string; } @@ -37,7 +49,7 @@ class Html /** * strips out all line breaks or replaced with given string * @param string $string string - * @param string $replace replace character, default ' ' + * @param string $replace [default=' '] replace character * @return string cleaned string without any line breaks */ public static function removeLB(string $string, string $replace = ' '): string diff --git a/src/Language/GetLocale.php b/src/Language/GetLocale.php index d0e6f9e..2953621 100644 --- a/src/Language/GetLocale.php +++ b/src/Language/GetLocale.php @@ -50,7 +50,6 @@ class GetLocale $locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ? SITE_LOCALE : // else parse from default, if not 'en' - /** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */ (defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE) ? DEFAULT_LOCALE : 'en'); } @@ -97,8 +96,7 @@ class GetLocale $encoding = defined('SITE_ENCODING') && !empty(SITE_ENCODING) ? SITE_ENCODING : // or default encoding, if not 'UTF-8' - /** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */ - (defined('DEFAULT_ENCODING') && !empty(DEFAULT_ENCODING) ? + (defined('DEFAULT_ENCODING') ? DEFAULT_ENCODING : 'UTF-8'); } } diff --git a/src/Output/ProgressBar.php b/src/Output/ProgressBar.php index 5c4f9c7..c64b699 100644 --- a/src/Output/ProgressBar.php +++ b/src/Output/ProgressBar.php @@ -418,9 +418,7 @@ class ProgressBar // if this is percent, we ignore anything, it is auto positioned if ($this->label[$name]['type'] != 'percent') { foreach (['top', 'left', 'width', 'height'] as $pos_name) { - if ($$pos_name !== false) { - $this->label[$name][$pos_name] = intval($$pos_name); - } + $this->label[$name][$pos_name] = intval($$pos_name); } if ($align != '') { diff --git a/test/phpunit/ACL/CoreLibsACLLoginTest.php b/test/phpunit/ACL/CoreLibsACLLoginTest.php index e6abe06..1062bb6 100644 --- a/test/phpunit/ACL/CoreLibsACLLoginTest.php +++ b/test/phpunit/ACL/CoreLibsACLLoginTest.php @@ -152,7 +152,6 @@ final class CoreLibsACLLoginTest extends TestCase // TARGET define('TARGET', 'test'); // LOGIN DB SCHEMA - // define('LOGIN_DB_SCHEMA', ''); // SHOULD SET // DEFAULT_ACL_LEVEL (d80) diff --git a/test/phpunit/Combined/CoreLibsCombinedDateTimeTest.php b/test/phpunit/Combined/CoreLibsCombinedDateTimeTest.php index 58040c4..1833f70 100644 --- a/test/phpunit/Combined/CoreLibsCombinedDateTimeTest.php +++ b/test/phpunit/Combined/CoreLibsCombinedDateTimeTest.php @@ -1068,8 +1068,32 @@ final class CoreLibsCombinedDateTimeTest extends TestCase return_named:$return_named, include_end_date:$include_end_date, exclude_start_date:$exclude_start_date - ) + ), + 'call calcDaysInterval' ); + if ($return_named) { + $this->assertEquals( + $expected, + \CoreLibs\Combined\DateTime::calcDaysIntervalNamedIndex( + $input_a, + $input_b, + include_end_date:$include_end_date, + exclude_start_date:$exclude_start_date + ), + 'call calcDaysIntervalNamedIndex' + ); + } else { + $this->assertEquals( + $expected, + \CoreLibs\Combined\DateTime::calcDaysIntervalNumIndex( + $input_a, + $input_b, + include_end_date:$include_end_date, + exclude_start_date:$exclude_start_date + ), + 'call calcDaysIntervalNamedIndex' + ); + } } /** diff --git a/test/phpunit/Convert/CoreLibsConvertByteTest.php b/test/phpunit/Convert/CoreLibsConvertByteTest.php index 9583888..0cd1682 100644 --- a/test/phpunit/Convert/CoreLibsConvertByteTest.php +++ b/test/phpunit/Convert/CoreLibsConvertByteTest.php @@ -40,7 +40,7 @@ final class CoreLibsConvertByteTest extends TestCase 4 => '1.00 KB', 5 => '1.02KiB', ], - 'invalud string number' => [ + 'invalid string number' => [ 0 => '1024 MB', 1 => '1024 MB', 2 => '1024 MB',