src/Mordilion/Configurable/Configuration/Writer/Ini.php
private function encode($configuration): string
    {
        if ($configuration instanceof ConfigurationInterface) {
            $configuration = $configuration->toArray();
        }

        if (!is_array($configuration)) {
            throw new \InvalidArgumentException('The provided configuration is not an array or an instance of ConfigurationInterface.');
        }

        $noSection = [];
        $result = '';
        $temp = '';

        foreach ($configuration as $section => $values) {
            if (!is_array($values)) {
                // it's not in a section
                $noSection[$section] = $values;
                continue;
            }

            $result .= '[' . $section . ']' . PHP_EOL;

            foreach ($values as $key => $value) {
                $result .= $this->encodeKeyValuePair($key, $value);
            }

            $result .= PHP_EOL;
        }

        foreach ($noSection as $key => $value) {
            $temp .= $this->encodeKeyValuePair($key, $value);
        }

        return (empty($temp) ?: $temp . PHP_EOL) . trim($result);
    }
private function encode($configuration): string
    {
        if ($configuration instanceof ConfigurationInterface) {
            $configuration = $configuration->toArray();
        }

        if (!is_array($configuration)) {
            throw new \InvalidArgumentException('The provided configuration is not an array or an instance of ConfigurationInterface.');
        }

        $noSection = [];
        $result = '';
        $temp = '';

        foreach ($configuration as $section => $values) {
            if (!is_array($values)) {
                // it's not in a section
                $noSection[$section] = $values;
                continue;
            }

            $result .= '[' . $section . ']' . PHP_EOL;

            foreach ($values as $key => $value) {
                $result .= $this->encodeKeyValuePair($key, $value);
            }

            $result .= PHP_EOL;
        }

        foreach ($noSection as $key => $value) {
            $temp .= $this->encodeKeyValuePair($key, $value);
        }

        return (empty($temp) ?: $temp . PHP_EOL) . trim($result);
    }
Encodes the provided $configuration into an ini string.

@param array|ConfigurationInterface $configuration

@throws \InvalidArgumentException if the provided configuration is not an array or an instance of ConfigurationInterface
@throws \RuntimeException if the decoding throwed some errors

@return string