refactor(run_id): 提炼RunId::short用于warning短展示并加单测

This commit is contained in:
萝卜
2026-03-17 18:43:25 +08:00
parent af806923b1
commit aefecd0cbe
3 changed files with 45 additions and 8 deletions

24
app/Support/RunId.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace App\Support;
class RunId
{
public static function short(string $runId, int $head = 6, int $tail = 4, string $ellipsis = '…'): string
{
$runId = trim((string) $runId);
if ($runId === '') {
return '';
}
$len = strlen($runId);
if ($len <= ($head + $tail + 1)) {
return $runId;
}
$head = max(1, (int) $head);
$tail = max(1, (int) $tail);
return substr($runId, 0, $head) . $ellipsis . substr($runId, -$tail);
}
}