Skip to content

Commit 0b81c29

Browse files
committed
Fixed psalm issues
1 parent 780cd53 commit 0b81c29

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/Dates.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,18 @@ public static function isYesterday($time): bool
203203
}
204204

205205
/**
206-
* Convert seconds to human readable format "H:i:s"
206+
* Convert seconds to human-readable format "H:i:s"
207207
*
208208
* @param float $seconds
209+
* @param int $minValuableSeconds
209210
* @return string
210211
*/
211-
public static function formatTime(float $seconds): string
212+
public static function formatTime(float $seconds, int $minValuableSeconds = 2): string
212213
{
213-
$minValuableSeconds = 2;
214-
215214
if ($seconds < $minValuableSeconds) {
216215
return number_format($seconds, 3) . ' sec';
217216
}
218217

219-
return (string)gmdate('H:i:s', (int)round($seconds, 0));
218+
return gmdate('H:i:s', (int)round($seconds, 0)) ?: '';
220219
}
221220
}

src/Str.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public static function isMBString(): bool
382382
public static function len(string $string): int
383383
{
384384
if (self::isMBString()) {
385-
return (int)mb_strlen($string, self::$encoding);
385+
return mb_strlen($string, self::$encoding) ?: 0;
386386
}
387387

388388
return strlen($string);
@@ -508,7 +508,7 @@ public static function sub(string $string, int $start, int $length = 0): string
508508
$length = self::len($string);
509509
}
510510

511-
return (string)mb_substr($string, $start, $length, self::$encoding);
511+
return mb_substr($string, $start, $length, self::$encoding) ?: '';
512512
}
513513

514514
return (string)substr($string, $start, $length);
@@ -523,7 +523,7 @@ public static function sub(string $string, int $start, int $length = 0): string
523523
public static function low($string): string
524524
{
525525
if (self::isMBString()) {
526-
return (string)mb_strtolower((string)$string, self::$encoding);
526+
return mb_strtolower((string)$string, self::$encoding) ?: '';
527527
}
528528

529529
return strtolower((string)$string);
@@ -540,7 +540,7 @@ public static function low($string): string
540540
public static function up($string): string
541541
{
542542
if (self::isMBString()) {
543-
return (string)mb_strtoupper((string)$string, self::$encoding);
543+
return mb_strtoupper((string)$string, self::$encoding) ?: '';
544544
}
545545

546546
return strtoupper((string)$string);
@@ -556,7 +556,7 @@ public static function up($string): string
556556
public static function subCount(string $haystack, string $needle): int
557557
{
558558
if (self::isMBString()) {
559-
return (int)mb_substr_count($haystack, $needle, self::$encoding);
559+
return mb_substr_count($haystack, $needle, self::$encoding) ?: 0;
560560
}
561561

562562
return substr_count($haystack, $needle);

tests/DatesTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,9 @@ public function testTimeFormat(): void
163163
isSame('00:00:03', Dates::formatTime(2.56789));
164164
isSame('00:00:02', Dates::formatTime(2));
165165
isSame('00:00:50', Dates::formatTime(50));
166+
isSame('00:00:00', Dates::formatTime(0, 0));
167+
isSame('00:00:01', Dates::formatTime(1, 0));
168+
isSame('00:00:02', Dates::formatTime(2, 0));
169+
isSame('00:00:02', Dates::formatTime(1.9999, 0));
166170
}
167171
}

0 commit comments

Comments
 (0)