Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
IniParser
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 parse
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
3
1<?php declare(strict_types=1);
2/*
3 * This file is part of Aplus Framework Config Library.
4 *
5 * (c) Natan Felles <natanfelles@gmail.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10namespace Framework\Config\Parsers;
11
12/**
13 * Class IniParser.
14 *
15 * @package config
16 */
17class IniParser extends Parser
18{
19    /**
20     * Parses an INI file.
21     *
22     * @param mixed $config path to the INI file
23     *
24     * @throws ParserException
25     *
26     * @return array<mixed> The INI parsed data
27     */
28    public static function parse(mixed $config) : array
29    {
30        static::checkConfig($config);
31        return static::parseOrThrow(static function () use ($config) : array {
32            $parsed = \parse_ini_file($config, true, \INI_SCANNER_TYPED);
33            $data = [];
34            // @phpstan-ignore-next-line
35            foreach ($parsed as $section => $values) {
36                $data[$section] = [];
37                foreach ($values as $key => $value) {
38                    $key = \explode('.', $key);
39                    $parent = [];
40                    static::addChild($parent, $key, $value);
41                    $data[$section] = \array_replace_recursive(
42                        $data[$section],
43                        $parent
44                    );
45                }
46            }
47            return static::ksortRecursive($data);
48        });
49    }
50}