Completed
Pull Request — master (#243)
by Дмитрий
05:05
created

ArraySet::humanToPlain()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 5
eloc 13
nc 2
nop 1
dl 0
loc 19
rs 8.8571
1
<?php
2
3
namespace PHPDaemon\Config\Entry;
4
5
/**
6
 * Array config entry
7
 *
8
 * @package    Core
9
 * @subpackage Config
10
 *
11
 * @author     Vasily Zorin <[email protected]>
12
 */
13
class ArraySet extends Generic
14
{
15
    /**
16
     * Converts human-readable value to plain
17
     * @param array|string $value
18
     * @return array
19
     */
20
    public static function humanToPlain($value)
21
    {
22
        if (is_array($value)) {
23
            return $value;
24
        }
25
        $value = preg_replace_callback('~(".*?")|(\'.*?\')|(\s*,\s*)~s', function ($m) {
26
            if (!empty($m[3])) {
27
                return "\x00";
28
            }
29
            if (!empty($m[2])) {
30
                return substr($m[2], 1, -1);
31
            }
32
            if (!empty($m[1])) {
33
                return substr($m[1], 1, -1);
34
            }
35
            return null;
36
        }, $value);
37
        return explode("\x00", $value);
38
    }
39
}
40