refactor(run_id): 提炼RunId::short用于warning短展示并加单测
This commit is contained in:
24
app/Support/RunId.php
Normal file
24
app/Support/RunId.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user