@@ -201,15 +201,15 @@ public static function alignmentOptions(array $options): array
201201 public static function runtime ($ startTime , $ startMem , array $ info = []): array
202202 {
203203 $ 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 ();
206206
207207 // 计算运行时间
208- $ info ['runtime ' ] = number_format (($ info ['endTime ' ] - $ startTime ) * 1000 , 3 ) . ' ms ' ;
208+ $ info ['runtime ' ] = \ number_format (($ info ['endTime ' ] - $ startTime ) * 1000 , 3 ) . ' ms ' ;
209209
210210 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 ' ]));
213213
214214 // $info['memory'] = number_format(($endMem - $startMem) / 1024, 3) . 'kb';
215215 $ info ['memory ' ] = self ::memoryUsage ($ endMem - $ startMem );
@@ -231,18 +231,18 @@ public static function runtime($startTime, $startMem, array $info = []): array
231231 public static function memoryUsage ($ memory ): string
232232 {
233233 if ($ memory >= 1024 * 1024 * 1024 ) {
234- return sprintf ('%.2f Gb ' , $ memory / 1024 / 1024 / 1024 );
234+ return \ sprintf ('%.2f Gb ' , $ memory / 1024 / 1024 / 1024 );
235235 }
236236
237237 if ($ memory >= 1024 * 1024 ) {
238- return sprintf ('%.2f Mb ' , $ memory / 1024 / 1024 );
238+ return \ sprintf ('%.2f Mb ' , $ memory / 1024 / 1024 );
239239 }
240240
241241 if ($ memory >= 1024 ) {
242- return sprintf ('%.2f Kb ' , $ memory / 1024 );
242+ return \ sprintf ('%.2f Kb ' , $ memory / 1024 );
243243 }
244244
245- return sprintf ('%d B ' , $ memory );
245+ return \ sprintf ('%d B ' , $ memory );
246246 }
247247
248248 /**
@@ -266,19 +266,19 @@ public static function howLongAgo(int $secs): string
266266
267267 foreach ($ timeFormats as $ index => $ format ) {
268268 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 ) {
272272 if (2 === \count ($ format )) {
273273 return $ format [1 ];
274274 }
275275
276- return floor ($ secs / $ format [2 ]) . ' ' . $ format [1 ];
276+ return \ floor ($ secs / $ format [2 ]) . ' ' . $ format [1 ];
277277 }
278278 }
279279 }
280280
281- return date ('Y-m-d H:i:s ' , $ secs );
281+ return \ date ('Y-m-d H:i:s ' , $ secs );
282282 }
283283
284284 /**
@@ -291,16 +291,16 @@ public static function splitStringByWidth(string $string, int $width): array
291291 // str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
292292 // additionally, array_slice() is not enough as some character has doubled width.
293293 // 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 );
296296 }
297297
298- $ utf8String = mb_convert_encoding ($ string , 'utf8 ' , $ encoding );
299- $ lines = array () ;
298+ $ utf8String = \ mb_convert_encoding ($ string , 'utf8 ' , $ encoding );
299+ $ lines = [] ;
300300 $ line = '' ;
301- foreach (preg_split ('//u ' , $ utf8String ) as $ char ) {
301+ foreach (\ preg_split ('//u ' , $ utf8String ) as $ char ) {
302302 // 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 ) {
304304 $ line .= $ char ;
305305 continue ;
306306 }
@@ -309,10 +309,10 @@ public static function splitStringByWidth(string $string, int $width): array
309309 $ line = $ char ;
310310 }
311311 if ('' !== $ line ) {
312- $ lines [] = \count ($ lines ) ? str_pad ($ line , $ width ) : $ line ;
312+ $ lines [] = \count ($ lines ) ? \ str_pad ($ line , $ width ) : $ line ;
313313 }
314314
315- mb_convert_variables ($ encoding , 'utf8 ' , $ lines );
315+ \ mb_convert_variables ($ encoding , 'utf8 ' , $ lines );
316316
317317 return $ lines ;
318318 }
@@ -330,7 +330,7 @@ public static function splitStringByWidth(string $string, int $width): array
330330 public static function spliceKeyValue (array $ data , array $ opts = []): string
331331 {
332332 $ text = '' ;
333- $ opts = array_merge ([
333+ $ opts = \ array_merge ([
334334 'leftChar ' => '' , // e.g ' ', ' * '
335335 'sepChar ' => ' ' , // e.g ' | ' OUT: key | value
336336 'keyStyle ' => '' , // e.g 'info','comment'
@@ -340,7 +340,7 @@ public static function spliceKeyValue(array $data, array $opts = []): string
340340 'ucFirst ' => true , // upper first char
341341 ], $ opts );
342342
343- if (!is_numeric ($ opts ['keyMaxWidth ' ])) {
343+ if (!\ is_numeric ($ opts ['keyMaxWidth ' ])) {
344344 $ opts ['keyMaxWidth ' ] = Helper::getKeyMaxWidth ($ data );
345345 }
346346
@@ -349,14 +349,14 @@ public static function spliceKeyValue(array $data, array $opts = []): string
349349 $ opts ['keyMaxWidth ' ] = $ opts ['keyMinWidth ' ];
350350 }
351351
352- $ keyStyle = trim ($ opts ['keyStyle ' ]);
352+ $ keyStyle = \ trim ($ opts ['keyStyle ' ]);
353353
354354 foreach ($ data as $ key => $ value ) {
355355 $ hasKey = !\is_int ($ key );
356356 $ text .= $ opts ['leftChar ' ];
357357
358358 if ($ hasKey && $ opts ['keyMaxWidth ' ]) {
359- $ key = str_pad ($ key , $ opts ['keyMaxWidth ' ], ' ' );
359+ $ key = \ str_pad ($ key , $ opts ['keyMaxWidth ' ], ' ' );
360360 $ text .= Helper::wrapTag ($ key , $ keyStyle ) . $ opts ['sepChar ' ];
361361 }
362362
@@ -369,13 +369,13 @@ public static function spliceKeyValue(array $data, array $opts = []): string
369369 if (\is_bool ($ val )) {
370370 $ val = $ val ? '(True) ' : '(False) ' ;
371371 } else {
372- $ val = is_scalar ($ val ) ? (string )$ val : \gettype ($ val );
372+ $ val = \ is_scalar ($ val ) ? (string )$ val : \gettype ($ val );
373373 }
374374
375- $ temp .= (!is_numeric ($ k ) ? "$ k: " : '' ) . "$ val, " ;
375+ $ temp .= (!\ is_numeric ($ k ) ? "$ k: " : '' ) . "$ val, " ;
376376 }
377377
378- $ value = rtrim ($ temp , ' , ' );
378+ $ value = \ rtrim ($ temp , ' , ' );
379379 } else {
380380 if (\is_bool ($ value )) {
381381 $ value = $ value ? '(True) ' : '(False) ' ;
@@ -384,7 +384,7 @@ public static function spliceKeyValue(array $data, array $opts = []): string
384384 }
385385 }
386386
387- $ value = $ hasKey && $ opts ['ucFirst ' ] ? ucfirst ($ value ) : $ value ;
387+ $ value = $ hasKey && $ opts ['ucFirst ' ] ? \ ucfirst ($ value ) : $ value ;
388388 $ text .= Helper::wrapTag ($ value , $ opts ['valStyle ' ]) . "\n" ;
389389 }
390390
0 commit comments