2
2
3
3
namespace ArtARTs36 \MergeRequestLinter \IO \Console ;
4
4
5
- use ArtARTs36 \MergeRequestLinter \Contracts \DataStructure \ Collection ;
5
+ use ArtARTs36 \MergeRequestLinter \Contracts \HasDebugInfo ;
6
6
use ArtARTs36 \MergeRequestLinter \Contracts \IO \Printer ;
7
7
use Symfony \Component \Console \Helper \Table ;
8
8
use Symfony \Component \Console \Helper \TableSeparator ;
@@ -61,7 +61,7 @@ private function separateProps(array $props): array
61
61
}
62
62
63
63
/**
64
- * @param array<mixed > $props
64
+ * @param array<array<string> > $props
65
65
*/
66
66
private function buildProps (object $ object , array &$ props , string $ prefix ): void
67
67
{
@@ -72,21 +72,53 @@ private function buildProps(object $object, array &$props, string $prefix): void
72
72
$ k = $ prefix . '. ' . $ key ;
73
73
}
74
74
75
- if (is_bool ($ value )) {
76
- $ props [] = [$ k , $ value ? 'true ' : 'false ' ];
77
- } elseif ($ value instanceof Collection) {
78
- $ props [] = [$ k , sprintf ("- Count: %s \n- %s " , $ value ->count (), $ value ->debugView ())];
79
- } elseif (is_string ($ value ) || $ value instanceof \Stringable) {
80
- $ props [] = [$ k , sprintf ('"%s" ' , $ value )];
81
- } elseif (is_scalar ($ value )) {
82
- $ props [] = [$ k , $ value ];
83
- } elseif (is_object ($ value )) {
75
+ if ($ value instanceof HasDebugInfo) {
76
+ $ debugInfo = '' ;
77
+ $ debugBag = $ value ->__debugInfo ();
78
+
79
+ foreach ($ debugBag as $ field => $ debugVal ) {
80
+ $ debugInfo .= sprintf (
81
+ '- %s: %s ' ,
82
+ $ field ,
83
+ $ this ->prepareValue ($ debugVal ),
84
+ );
85
+
86
+ if (next ($ debugBag ) !== false ) {
87
+ $ debugInfo .= "\n" ;
88
+ }
89
+ }
90
+
91
+ $ props [] = [$ k , $ debugInfo ];
92
+ } elseif (is_object ($ value ) && ! $ value instanceof \Stringable) {
84
93
$ prefix = $ k ;
85
94
86
95
$ this ->buildProps ($ value , $ props , $ prefix );
96
+ } else {
97
+ $ props [] = [$ k , $ this ->prepareValue ($ value )];
87
98
}
88
99
89
100
$ prefix = '' ;
90
101
}
91
102
}
103
+
104
+ private function prepareValue (mixed $ value ): string
105
+ {
106
+ if (is_array ($ value )) {
107
+ return ($ json = json_encode ($ value )) ? $ json : '' ;
108
+ }
109
+
110
+ if (is_bool ($ value )) {
111
+ return $ value ? 'true ' : 'false ' ;
112
+ }
113
+
114
+ if (is_string ($ value ) || $ value instanceof \Stringable) {
115
+ return sprintf ('"%s" ' , $ value );
116
+ }
117
+
118
+ if ($ value === null ) {
119
+ return 'null ' ;
120
+ }
121
+
122
+ return '' . $ value ;
123
+ }
92
124
}
0 commit comments