PhpReader::read()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 * Php.php - Jaxon config reader
5
 *
6
 * Read the config data from a PHP config file.
7
 *
8
 * @package jaxon-config
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2022 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
14
15
namespace Jaxon\Config\Reader;
16
17
use Jaxon\Config\Exception\FileAccess;
18
use Jaxon\Config\Exception\FileContent;
19
20
use function is_array;
21
use function realpath;
22
use function is_readable;
23
24
class PhpReader
25
{
26
    /**
27
     * Read options from a PHP config file
28
     *
29
     * @param string $sConfigFile The full path to the config file
30
     *
31
     * @return array
32
     * @throws FileAccess
33
     * @throws FileContent
34
     */
35
    public static function read(string $sConfigFile): array
36
    {
37
        $sConfigFile = realpath($sConfigFile);
38
        if(!is_readable($sConfigFile))
39
        {
40
            throw new FileAccess($sConfigFile);
41
        }
42
43
        $aConfigOptions = include($sConfigFile);
44
        if(!is_array($aConfigOptions))
45
        {
46
            throw new FileContent($sConfigFile);
47
        }
48
49
        return $aConfigOptions;
50
    }
51
}
52