@@ -47,6 +47,14 @@ public function encode($value, $depth, array $options, callable $encode)
47
47
return $ this ->getFormattedArray ($ value , $ depth , $ options , $ encode );
48
48
}
49
49
50
+ /**
51
+ * Returns the PHP code for the array as inline or multi line array.
52
+ * @param array $array Array to encode
53
+ * @param integer $depth Current indentation depth of the output
54
+ * @param array $options List of encoder options
55
+ * @param callable $encode Callback used to encode values
56
+ * @return string The PHP code representation for the array
57
+ */
50
58
private function getFormattedArray (array $ array , $ depth , $ options , $ encode )
51
59
{
52
60
$ lines = $ this ->getPairs ($ array , ' ' , $ options ['array.omit ' ], $ encode , $ omitted );
@@ -62,7 +70,13 @@ private function getFormattedArray(array $array, $depth, $options, $encode)
62
70
return $ this ->buildArray ($ lines , $ depth , $ options );
63
71
}
64
72
65
- private function getInlineArray ($ lines , $ options )
73
+ /**
74
+ * Returns the code for the inlined array, if possible.
75
+ * @param string[] $lines Encoded key and value pairs
76
+ * @param array $options List of encoder options
77
+ * @return string|false Array encoded as single line of PHP code or false if not possible
78
+ */
79
+ private function getInlineArray (array $ lines , array $ options )
66
80
{
67
81
$ output = $ this ->wrap (implode (', ' , $ lines ), $ options ['array.short ' ]);
68
82
@@ -75,6 +89,13 @@ private function getInlineArray($lines, $options)
75
89
return $ output ;
76
90
}
77
91
92
+ /**
93
+ * Builds the complete array from the encoded key and value pairs.
94
+ * @param string[] $lines Encoded key and value pairs
95
+ * @param integer $depth Current indentation depth of the output
96
+ * @param array $options List of encoder options
97
+ * @return string Array encoded as PHP code
98
+ */
78
99
private function buildArray (array $ lines , $ depth , array $ options )
79
100
{
80
101
$ indent = $ this ->buildIndent ($ options ['array.base ' ], $ options ['array.indent ' ], $ depth + 1 );
@@ -121,7 +142,7 @@ private function buildIndent($base, $indent, $depth)
121
142
* @param callable $encode Callback used to encode values
122
143
* @return string[] Each of key and value pair encoded as php
123
144
*/
124
- private function getAlignedPairs ($ array , callable $ encode )
145
+ private function getAlignedPairs (array $ array , callable $ encode )
125
146
{
126
147
$ keys = [];
127
148
$ values = [];
@@ -150,7 +171,7 @@ private function getAlignedPairs($array, callable $encode)
150
171
* @param boolean $omitted Set to true, if all the keys were omitted, false otherwise
151
172
* @return string[] Each of key and value pair encoded as php
152
173
*/
153
- private function getPairs ($ array , $ space , $ omit , callable $ encode , & $ omitted = true )
174
+ private function getPairs (array $ array , $ space , $ omit , callable $ encode , & $ omitted = true )
154
175
{
155
176
$ pairs = [];
156
177
$ nextIndex = 0 ;
@@ -169,6 +190,12 @@ private function getPairs($array, $space, $omit, callable $encode, & $omitted =
169
190
return $ pairs ;
170
191
}
171
192
193
+ /**
194
+ * Tells if the key can be omitted from array output based on expected index.
195
+ * @param integer|string $key Current array key
196
+ * @param integer $nextIndex Next expected key that can be omitted
197
+ * @return bool True if the key can be omitted, false if not
198
+ */
172
199
private function canOmit ($ key , & $ nextIndex )
173
200
{
174
201
if (!is_int ($ key ) || $ key < $ nextIndex ) {
0 commit comments