protected function dumpArray(array $input, string $indent, int $outerLineLength): string
    {
        if (!$input) {
            return '[]';
        }

        if ($outerLineLength < $this->lineLength) {
            $dump = $this->tryDumpList($input, $outerLineLength, 1);
            if (null !== $dump) {
                return $dump;
            }
        }

        $next_indent = $indent . $this->indent;
        $next_indent_length = $outerLineLength + $this->indentLength;

        $dump = '[' . $this->eol;
        $index = 0;
        $still_linear = true;
        foreach ($input as $key => $value) {
            $item = $next_indent;
            $item_outer_length = $next_indent_length;

            if ($still_linear && $key === $index) {
                ++$index;
            } else {
                $still_linear = false;

                $key_dump = $this->dumpValue($key);
                $item .= $key_dump . ' => ';
                $item_outer_length += 4 + StringHelper::lengthUtf8($key_dump);
            }

            if (\is_array($value)) {
                // there will be trailing comma ',' after value, so outer length gives +1
                $value_dump = $this->dumpArray($value, $next_indent, $item_outer_length + 1);
            } else {
                $value_dump = $this->dumpValue($value);
            }

            $item .= $value_dump;

            $dump .= $item . ',' . $this->eol;
        }

        $dump .= $indent . ']';

        return $dump;
    }
protected function dumpArray(array $input, string $indent, int $outerLineLength): string
    {
        if (!$input) {
            return '[]';
        }

        if ($outerLineLength < $this->lineLength) {
            $dump = $this->tryDumpList($input, $outerLineLength, 1);
            if (null !== $dump) {
                return $dump;
            }
        }

        $next_indent = $indent . $this->indent;
        $next_indent_length = $outerLineLength + $this->indentLength;

        $dump = '[' . $this->eol;
        $index = 0;
        $still_linear = true;
        foreach ($input as $key => $value) {
            $item = $next_indent;
            $item_outer_length = $next_indent_length;

            if ($still_linear && $key === $index) {
                ++$index;
            } else {
                $still_linear = false;

                $key_dump = $this->dumpValue($key);
                $item .= $key_dump . ' => ';
                $item_outer_length += 4 + StringHelper::lengthUtf8($key_dump);
            }

            if (\is_array($value)) {
                // there will be trailing comma ',' after value, so outer length gives +1
                $value_dump = $this->dumpArray($value, $next_indent, $item_outer_length + 1);
            } else {
                $value_dump = $this->dumpValue($value);
            }

            $item .= $value_dump;

            $dump .= $item . ',' . $this->eol;
        }

        $dump .= $indent . ']';

        return $dump;
    }
protected function dumpArray ( array $ input , string $ indent , int $ outerLineLength ) : string { if ( ! $ input ) { return '[]' ; } if ( $ outerLineLength < $ this -> lineLength ) { $ dump = $ this -> tryDumpList ( $ input , $ outerLineLength , 1 ) ; if ( null !== $ dump ) { return $ dump ; } } $ next_indent = $ indent . $ this -> indent ; $ next_indent_length = $ outerLineLength + $ this -> indentLength ; $ dump = '[' . $ this -> eol ; $ index = 0 ; $ still_linear = true ; foreach ( $ input as $ key => $ value ) { $ item = $ next_indent ; $ item_outer_length = $ next_indent_length ; if ( $ still_linear && $ key === $ index ) { ++ $ index ; } else { $ still_linear = false ; $ key_dump = $ this -> dumpValue ( $ key ) ; $ item .= $ key_dump . ' => ' ; $ item_outer_length += 4 + StringHelper :: lengthUtf8 ( $ key_dump ) ; } if ( \ is_array ( $ value ) ) { // there will be trailing comma ',' after value, so outer length gives +1 $ value_dump = $ this -> dumpArray ( $ value , $ next_indent , $ item_outer_length + 1 ) ; } else { $ value_dump = $ this -> dumpValue ( $ value ) ; } $ item .= $ value_dump ; $ dump .= $ item . ',' . $ this -> eol ; } $ dump .= $ indent . ']' ; return $ dump ; }
Dumps an array with specific indention
@param array $input Input array
@param string $indent Full indention string
@param int $outerLineLength Length of `$indent` in characters
@return string PHP code
@throws \InvalidArgumentException In case of unsupported data type
Dumps an array with specific indention