Passed
Push — main ( 673af6...acd800 )
by Thierry
01:40
created

Value::explodeName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Oprion.php
5
 *
6
 * Util functions for options values.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2025 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\Reader;
16
17
use function array_filter;
18
use function array_keys;
19
use function array_map;
20
use function count;
21
use function explode;
22
use function is_array;
23
use function is_string;
24
use function trim;
25
26
class Value
27
{
28
    /**
29
     * Check if a value is an array of options
30
     *
31
     * @param mixed $xValue
32
     *
33
     * @return bool
34
     */
35
    public static function containsOptions($xValue): bool
36
    {
37
        if(!is_array($xValue) || count($xValue) === 0)
38
        {
39
            return false;
40
        }
41
        foreach(array_keys($xValue) as $xKey)
42
        {
43
            if(!is_string($xKey))
44
            {
45
                return false;
46
            }
47
        }
48
        return true;
49
    }
50
51
    /**
52
     * Get an array of options names
53
     *
54
     * @param string $sName
55
     *
56
     * @return array
57
     */
58
    public static function explodeName(string $sName): array
59
    {
60
        $aNames = explode('.', $sName);
61
        $aNames = array_map(fn($sVal) => trim($sVal), $aNames);
62
        return array_filter($aNames, fn($sVal) => $sVal !== '');
63
    }
64
}
65