phpstan check fixes

This commit is contained in:
Clemens Schwaighofer
2026-05-11 15:31:59 +09:00
parent 85f7e114b0
commit a8755c8c0f
7 changed files with 63 additions and 21 deletions
@@ -277,6 +277,38 @@ final class CoreLibsConvertJsonTest extends TestCase
); );
} }
/**
* Check if invalid flag throws exception
*
* @covers ::jsonValidate
* @testdox jsonValidate test exception thrown on invalid flag
*
* @return void
*/
public function testJsonValidateInvalidFlag(): void
{
$this->expectException("\InvalidArgumentException");
\CoreLibs\Convert\Json::jsonValidate('{"valid": "json"}', 5);
}
/**
* Check if valid flag throws no exception
*
* @covers ::jsonValidate
* @testdox jsonValidate test no exception on valid flag
*
* @return void
*/
public function testJsonValidateValidflag(): void
{
$this->assertTrue(
\CoreLibs\Convert\Json::jsonValidate('{"valid": "json"}', 0)
);
$this->assertTrue(
\CoreLibs\Convert\Json::jsonValidate('{"valid": "json"}', JSON_INVALID_UTF8_IGNORE)
);
}
/** /**
* Undocumented function * Undocumented function
* *
+2 -2
View File
@@ -133,7 +133,7 @@ class DateTime
} else { } else {
for ($i = 0, $iMax = count($timegroups); $i < $iMax; $i++) { for ($i = 0, $iMax = count($timegroups); $i < $iMax; $i++) {
$output = floor((float)$timestamp / $timegroups[$i]); $output = floor((float)$timestamp / $timegroups[$i]);
$timestamp = (float)$timestamp % $timegroups[$i]; $timestamp = $timestamp % $timegroups[$i];
// output has days|hours|min|sec // output has days|hours|min|sec
if ($output || $time_string) { if ($output || $time_string) {
$time_string .= $output . $labels[$i] . (($i + 1) != count($timegroups) ? ' ' : ''); $time_string .= $output . $labels[$i] . (($i + 1) != count($timegroups) ? ' ' : '');
@@ -453,7 +453,7 @@ class DateTime
} }
if (isset($matches[11]) && is_numeric($matches[11])) { if (isset($matches[11]) && is_numeric($matches[11])) {
// for milliseconds, we need to divide by 1000 and add them // for milliseconds, we need to divide by 1000 and add them
$timestamp += (float)($matches[11] / 1000); $timestamp += ((float)$matches[11] / 1000);
} }
if ($negative) { if ($negative) {
// cast to float so we can do a negative multiplication // cast to float so we can do a negative multiplication
+1 -1
View File
@@ -154,7 +154,7 @@ class Byte
if (!empty($matches[1])) { if (!empty($matches[1])) {
$number_negative = true; $number_negative = true;
} }
if (isset($matches[2]) && isset($matches[3])) { if (isset($matches[2])) {
// remove all non valid characters from the number // remove all non valid characters from the number
$number = preg_replace('/[^0-9\.]/', '', $matches[2]); $number = preg_replace('/[^0-9\.]/', '', $matches[2]);
// final clean up and convert to float // final clean up and convert to float
+6 -6
View File
@@ -957,9 +957,9 @@ class Color
* Undocumented function * Undocumented function
* *
* @param HWB $hwb * @param HWB $hwb
* @return Lch * @return LCH
*/ */
public static function hwbToLch(HWB $hwb): Lch public static function hwbToLch(HWB $hwb): LCH
{ {
return self::rgbToLch( return self::rgbToLch(
self::hwbToRgb($hwb) self::hwbToRgb($hwb)
@@ -1078,10 +1078,10 @@ class Color
/** /**
* OkLab to Lch (CIE) * OkLab to Lch (CIE)
* *
* @param LAB $lab * @param Lab $lab
* @return LCH * @return LCH
*/ */
public static function okLabToLch(LAB $lab): LCH public static function okLabToLch(Lab $lab): LCH
{ {
return self::labToLch( return self::labToLch(
self::okLabToLab($lab) self::okLabToLab($lab)
@@ -1092,9 +1092,9 @@ class Color
* Lch (CIE) to OkLab * Lch (CIE) to OkLab
* *
* @param LCH $lch * @param LCH $lch
* @return LAB * @return Lab
*/ */
public static function lchToOkLab(LCH $lch): LAB public static function lchToOkLab(LCH $lch): Lab
{ {
return self::labToOkLab( return self::labToOkLab(
self::lchToLab($lch) self::lchToLab($lch)
+5 -1
View File
@@ -74,11 +74,15 @@ class Json
* Weill set the internval last error state and info can be read with jsonGetLastError * Weill set the internval last error state and info can be read with jsonGetLastError
* *
* @param string $json * @param string $json
* @param int $flags only JSON_INVALID_UTF8_IGNORE is currently allowed * @param int $flags only JSON_INVALID_UTF8_IGNORE is currently allowed
* @return bool * @return bool
* @throws \InvalidArgumentException if flags is invalid
*/ */
public static function jsonValidate(string $json, int $flags = 0): bool public static function jsonValidate(string $json, int $flags = 0): bool
{ {
if ($flags != 0 && $flags != JSON_INVALID_UTF8_IGNORE) {
throw new \InvalidArgumentException("For flag only 0 or JSON_INVALID_UTF8_IGNORE is allwed: " . $flags);
}
$json_valid = json_validate($json, flags:$flags); $json_valid = json_validate($json, flags:$flags);
self::$json_last_error = json_last_error(); self::$json_last_error = json_last_error();
return $json_valid; return $json_valid;
+12 -6
View File
@@ -2562,21 +2562,27 @@ class IO
// set field names // set field names
$this->cursor_ext[$query_hash]['field_names'] = []; $this->cursor_ext[$query_hash]['field_names'] = [];
for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) { for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) {
$this->cursor_ext[$query_hash]['field_names'][] = if (
$this->db_functions->__dbFieldName( ($field_name = $this->db_functions->__dbFieldName(
$this->cursor_ext[$query_hash]['cursor'], $this->cursor_ext[$query_hash]['cursor'],
$i $i
); )) !== false
) {
$this->cursor_ext[$query_hash]['field_names'][] = $field_name;
}
} }
$this->field_names = $this->cursor_ext[$query_hash]['field_names']; $this->field_names = $this->cursor_ext[$query_hash]['field_names'];
// field types // field types
$this->cursor_ext[$query_hash]['field_types'] = []; $this->cursor_ext[$query_hash]['field_types'] = [];
for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) { for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) {
$this->cursor_ext[$query_hash]['field_types'][] = if (
$this->db_functions->__dbFieldType( ($field_type = $this->db_functions->__dbFieldType(
$this->cursor_ext[$query_hash]['cursor'], $this->cursor_ext[$query_hash]['cursor'],
$i $i
); )) !== false
) {
$this->cursor_ext[$query_hash]['field_types'][] = $field_type;
}
} }
$this->field_types = $this->cursor_ext[$query_hash]['field_types']; $this->field_types = $this->cursor_ext[$query_hash]['field_types'];
// combined name => type // combined name => type
+5 -5
View File
@@ -178,11 +178,11 @@ class Elements
"/(href=\")?(\>)?\b($protRegex)([\w\.\-?&=+%#~,;\/]+)\b([\.\-?&=+%#~,;\/]*)(\|([^\||^#]+)(#([^\|]+))?\|)?/", "/(href=\")?(\>)?\b($protRegex)([\w\.\-?&=+%#~,;\/]+)\b([\.\-?&=+%#~,;\/]*)(\|([^\||^#]+)(#([^\|]+))?\|)?/",
function ($matches) { function ($matches) {
return self::createUrl( return self::createUrl(
$matches[1] ?? '', $matches[1],
$matches[2] ?? '', $matches[2],
$matches[3] ?? '', $matches[3],
$matches[4] ?? '', $matches[4],
$matches[5] ?? '', $matches[5],
$matches[7] ?? '', $matches[7] ?? '',
$matches[9] ?? '' $matches[9] ?? ''
); );