11<?php
2-
2+ /**
3+ * Created by PhpStorm.
4+ * User: Inhere
5+ * Date: 16-4-1
6+ * Time: 上午10:08
7+ * Used:
8+ * file: Color.php
9+ */
310
411namespace inhere \librarys \console ;
512
@@ -45,20 +52,21 @@ public static function isInteractive($fileDescriptor)
4552 /**
4653 * get key Max Width
4754 *
48- * @param array $data
55+ * @param array $data
4956 * [
5057 * 'key1' => 'value1',
5158 * 'key2-test' => 'value2',
5259 * ]
60+ * @param bool $expectInt
5361 * @return int
5462 */
55- public static function getKeyMaxWidth (array $ data , $ expactInt = true )
63+ public static function getKeyMaxWidth (array $ data , $ expectInt = true )
5664 {
5765 $ keyMaxWidth = 0 ;
5866
5967 foreach ($ data as $ key => $ value ) {
6068 // key is not a integer
61- if ( !$ expactInt || !is_numeric ($ key ) ) {
69+ if ( !$ expectInt || !is_numeric ($ key ) ) {
6270 $ width = mb_strlen ($ key , 'UTF-8 ' );
6371 $ keyMaxWidth = $ width > $ keyMaxWidth ? $ width : $ keyMaxWidth ;
6472 }
@@ -74,7 +82,6 @@ public static function getKeyMaxWidth(array $data, $expactInt = true)
7482 * 'system' => 'Linux',
7583 * 'version' => '4.4.5',
7684 * ]
77- * @param int $keyMaxWidth
7885 * @param array $opts
7986 * @return string
8087 */
@@ -84,7 +91,7 @@ public static function spliceKeyValue(array $data, array $opts = [])
8491 $ opts = array_merge ([
8592 'leftChar ' => '' , // e.g ' ', ' * '
8693 'sepChar ' => ' ' , // e.g ' | ' => OUT: key | value
87- 'keyStyle ' => '' , // e.g 'info','commont '
94+ 'keyStyle ' => '' , // e.g 'info','comment '
8895 'keyMaxWidth ' => null , // if not set, will automatic calculation
8996 ], $ opts );
9097
@@ -106,14 +113,14 @@ public static function spliceKeyValue(array $data, array $opts = [])
106113 if ( is_array ($ value ) ) {
107114 $ temp = '' ;
108115
109- foreach ($ value as $ key => $ val ) {
116+ foreach ($ value as $ k => $ val ) {
110117 if (is_bool ($ val )) {
111118 $ val = $ val ? 'True ' : 'False ' ;
112119 } else {
113120 $ val = (string )$ val ;
114121 }
115122
116- $ temp .= (!is_numeric ($ key ) ? "$ key : " : '' ) . "<info> $ val</info>, " ;
123+ $ temp .= (!is_numeric ($ k ) ? "$ k : " : '' ) . "<info> $ val</info>, " ;
117124 }
118125
119126 $ value = rtrim ($ temp , ' , ' );
0 commit comments