• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aplus-framework / config / 10034566442

28 Jun 2024 10:04PM UTC coverage: 100.0%. Remained the same
10034566442

push

github

natanfelles
Merge branch 'refs/heads/4.x' into development

206 of 206 relevant lines covered (100.0%)

2.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Parsers/XmlParser.php
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
 */
10
namespace Framework\Config\Parsers;
11

12
use Framework\Config\Parsers\Extra\JsonXMLElement;
13

14
/**
15
 * Class XmlParser.
16
 *
17
 * @package config
18
 */
19
class XmlParser extends Parser
20
{
21
    /**
22
     * Parses an XML file.
23
     *
24
     * @param mixed $config path to the XML file
25
     *
26
     * @throws ParserException
27
     *
28
     * @return array<mixed> The XML parsed data
29
     */
30
    public static function parse(mixed $config) : array
31
    {
32
        static::checkConfig($config);
2✔
33
        return static::parseOrThrow(static function () use ($config) : array {
2✔
34
            $config = \file_get_contents($config);
2✔
35
            $config = \simplexml_load_string($config, JsonXMLElement::class); // @phpstan-ignore-line
2✔
36
            $config = \json_encode($config);
1✔
37
            $config = \json_decode($config, true); // @phpstan-ignore-line
1✔
38
            $data = [];
1✔
39
            foreach ($config as $instance => $values) {
1✔
40
                foreach ($values as &$value) {
1✔
41
                    $value = static::parseValue($value);
1✔
42
                }
43
                unset($value);
1✔
44
                $data[$instance] = $values;
1✔
45
            }
46
            return static::ksortRecursive($data);
1✔
47
        });
2✔
48
    }
49

50
    /**
51
     * @param array<int|string,mixed>|string $value
52
     *
53
     * @return array<int|string,mixed>|bool|float|int|string|null
54
     */
55
    protected static function parseValue(array|string $value) : array|bool|int|float|string|null
56
    {
57
        if (\is_array($value)) {
1✔
58
            foreach ($value as &$val) {
1✔
59
                $val = static::parseValue($val);
1✔
60
            }
61
            return $value;
1✔
62
        }
63
        return static::getValue($value);
1✔
64
    }
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc