Passed
Push — main ( 2519a4...62a0e8 )
by Thierry
03:58
created

Php   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A read() 0 14 3
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-core
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\Utils\Config\File;
16
17
use Jaxon\Utils\Config\Exception\FileAccess;
18
use Jaxon\Utils\Config\Exception\FileContent;
19
20
use function is_array;
21
use function realpath;
22
use function is_readable;
23
24
class Php
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
        $aConfigOptions = include($sConfigFile);
43
        if(!is_array($aConfigOptions))
44
        {
45
            throw new FileContent($sConfigFile);
46
        }
47
48
        return $aConfigOptions;
49
    }
50
}
51