@@ -201,15 +201,15 @@ public static function alignmentOptions(array $options): array
201
201
public static function runtime ($ startTime , $ startMem , array $ info = []): array
202
202
{
203
203
$ info ['startTime ' ] = $ startTime ;
204
- $ info ['endTime ' ] = microtime (true );
205
- $ info ['endMemory ' ] = memory_get_usage ();
204
+ $ info ['endTime ' ] = \ microtime (true );
205
+ $ info ['endMemory ' ] = \ memory_get_usage ();
206
206
207
207
// 计算运行时间
208
- $ info ['runtime ' ] = number_format (($ info ['endTime ' ] - $ startTime ) * 1000 , 3 ) . ' ms ' ;
208
+ $ info ['runtime ' ] = \ number_format (($ info ['endTime ' ] - $ startTime ) * 1000 , 3 ) . ' ms ' ;
209
209
210
210
if ($ startMem ) {
211
- $ startMem = array_sum (explode (' ' , $ startMem ));
212
- $ endMem = array_sum (explode (' ' , $ info ['endMemory ' ]));
211
+ $ startMem = \ array_sum (explode (' ' , $ startMem ));
212
+ $ endMem = \ array_sum (explode (' ' , $ info ['endMemory ' ]));
213
213
214
214
// $info['memory'] = number_format(($endMem - $startMem) / 1024, 3) . 'kb';
215
215
$ info ['memory ' ] = self ::memoryUsage ($ endMem - $ startMem );
@@ -231,18 +231,18 @@ public static function runtime($startTime, $startMem, array $info = []): array
231
231
public static function memoryUsage ($ memory ): string
232
232
{
233
233
if ($ memory >= 1024 * 1024 * 1024 ) {
234
- return sprintf ('%.2f Gb ' , $ memory / 1024 / 1024 / 1024 );
234
+ return \ sprintf ('%.2f Gb ' , $ memory / 1024 / 1024 / 1024 );
235
235
}
236
236
237
237
if ($ memory >= 1024 * 1024 ) {
238
- return sprintf ('%.2f Mb ' , $ memory / 1024 / 1024 );
238
+ return \ sprintf ('%.2f Mb ' , $ memory / 1024 / 1024 );
239
239
}
240
240
241
241
if ($ memory >= 1024 ) {
242
- return sprintf ('%.2f Kb ' , $ memory / 1024 );
242
+ return \ sprintf ('%.2f Kb ' , $ memory / 1024 );
243
243
}
244
244
245
- return sprintf ('%d B ' , $ memory );
245
+ return \ sprintf ('%d B ' , $ memory );
246
246
}
247
247
248
248
/**
@@ -266,19 +266,19 @@ public static function howLongAgo(int $secs): string
266
266
267
267
foreach ($ timeFormats as $ index => $ format ) {
268
268
if ($ secs >= $ format [0 ]) {
269
- if (( isset ( $ timeFormats [ $ index + 1 ]) && $ secs < $ timeFormats [$ index + 1 ][ 0 ])
270
- || $ index === \count ( $ timeFormats ) - 1
271
- ) {
269
+ $ next = $ timeFormats [$ index + 1 ] ?? false ;
270
+
271
+ if (( $ next && $ secs < $ next [ 0 ]) || $ index === \count ( $ timeFormats ) - 1 ) {
272
272
if (2 === \count ($ format )) {
273
273
return $ format [1 ];
274
274
}
275
275
276
- return floor ($ secs / $ format [2 ]) . ' ' . $ format [1 ];
276
+ return \ floor ($ secs / $ format [2 ]) . ' ' . $ format [1 ];
277
277
}
278
278
}
279
279
}
280
280
281
- return date ('Y-m-d H:i:s ' , $ secs );
281
+ return \ date ('Y-m-d H:i:s ' , $ secs );
282
282
}
283
283
284
284
/**
@@ -291,16 +291,16 @@ public static function splitStringByWidth(string $string, int $width): array
291
291
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
292
292
// additionally, array_slice() is not enough as some character has doubled width.
293
293
// we need a function to split string not by character count but by string width
294
- if (false === $ encoding = mb_detect_encoding ($ string , null , true )) {
295
- return str_split ($ string , $ width );
294
+ if (false === $ encoding = \ mb_detect_encoding ($ string , null , true )) {
295
+ return \ str_split ($ string , $ width );
296
296
}
297
297
298
- $ utf8String = mb_convert_encoding ($ string , 'utf8 ' , $ encoding );
299
- $ lines = array () ;
298
+ $ utf8String = \ mb_convert_encoding ($ string , 'utf8 ' , $ encoding );
299
+ $ lines = [] ;
300
300
$ line = '' ;
301
- foreach (preg_split ('//u ' , $ utf8String ) as $ char ) {
301
+ foreach (\ preg_split ('//u ' , $ utf8String ) as $ char ) {
302
302
// test if $char could be appended to current line
303
- if (mb_strwidth ($ line . $ char , 'utf8 ' ) <= $ width ) {
303
+ if (\ mb_strwidth ($ line . $ char , 'utf8 ' ) <= $ width ) {
304
304
$ line .= $ char ;
305
305
continue ;
306
306
}
@@ -309,10 +309,10 @@ public static function splitStringByWidth(string $string, int $width): array
309
309
$ line = $ char ;
310
310
}
311
311
if ('' !== $ line ) {
312
- $ lines [] = \count ($ lines ) ? str_pad ($ line , $ width ) : $ line ;
312
+ $ lines [] = \count ($ lines ) ? \ str_pad ($ line , $ width ) : $ line ;
313
313
}
314
314
315
- mb_convert_variables ($ encoding , 'utf8 ' , $ lines );
315
+ \ mb_convert_variables ($ encoding , 'utf8 ' , $ lines );
316
316
317
317
return $ lines ;
318
318
}
@@ -330,7 +330,7 @@ public static function splitStringByWidth(string $string, int $width): array
330
330
public static function spliceKeyValue (array $ data , array $ opts = []): string
331
331
{
332
332
$ text = '' ;
333
- $ opts = array_merge ([
333
+ $ opts = \ array_merge ([
334
334
'leftChar ' => '' , // e.g ' ', ' * '
335
335
'sepChar ' => ' ' , // e.g ' | ' OUT: key | value
336
336
'keyStyle ' => '' , // e.g 'info','comment'
@@ -340,7 +340,7 @@ public static function spliceKeyValue(array $data, array $opts = []): string
340
340
'ucFirst ' => true , // upper first char
341
341
], $ opts );
342
342
343
- if (!is_numeric ($ opts ['keyMaxWidth ' ])) {
343
+ if (!\ is_numeric ($ opts ['keyMaxWidth ' ])) {
344
344
$ opts ['keyMaxWidth ' ] = Helper::getKeyMaxWidth ($ data );
345
345
}
346
346
@@ -349,14 +349,14 @@ public static function spliceKeyValue(array $data, array $opts = []): string
349
349
$ opts ['keyMaxWidth ' ] = $ opts ['keyMinWidth ' ];
350
350
}
351
351
352
- $ keyStyle = trim ($ opts ['keyStyle ' ]);
352
+ $ keyStyle = \ trim ($ opts ['keyStyle ' ]);
353
353
354
354
foreach ($ data as $ key => $ value ) {
355
355
$ hasKey = !\is_int ($ key );
356
356
$ text .= $ opts ['leftChar ' ];
357
357
358
358
if ($ hasKey && $ opts ['keyMaxWidth ' ]) {
359
- $ key = str_pad ($ key , $ opts ['keyMaxWidth ' ], ' ' );
359
+ $ key = \ str_pad ($ key , $ opts ['keyMaxWidth ' ], ' ' );
360
360
$ text .= Helper::wrapTag ($ key , $ keyStyle ) . $ opts ['sepChar ' ];
361
361
}
362
362
@@ -369,13 +369,13 @@ public static function spliceKeyValue(array $data, array $opts = []): string
369
369
if (\is_bool ($ val )) {
370
370
$ val = $ val ? '(True) ' : '(False) ' ;
371
371
} else {
372
- $ val = is_scalar ($ val ) ? (string )$ val : \gettype ($ val );
372
+ $ val = \ is_scalar ($ val ) ? (string )$ val : \gettype ($ val );
373
373
}
374
374
375
- $ temp .= (!is_numeric ($ k ) ? "$ k: " : '' ) . "$ val, " ;
375
+ $ temp .= (!\ is_numeric ($ k ) ? "$ k: " : '' ) . "$ val, " ;
376
376
}
377
377
378
- $ value = rtrim ($ temp , ' , ' );
378
+ $ value = \ rtrim ($ temp , ' , ' );
379
379
} else {
380
380
if (\is_bool ($ value )) {
381
381
$ value = $ value ? '(True) ' : '(False) ' ;
@@ -384,7 +384,7 @@ public static function spliceKeyValue(array $data, array $opts = []): string
384
384
}
385
385
}
386
386
387
- $ value = $ hasKey && $ opts ['ucFirst ' ] ? ucfirst ($ value ) : $ value ;
387
+ $ value = $ hasKey && $ opts ['ucFirst ' ] ? \ ucfirst ($ value ) : $ value ;
388
388
$ text .= Helper::wrapTag ($ value , $ opts ['valStyle ' ]) . "\n" ;
389
389
}
390
390
0 commit comments