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

ArraySet   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 2 Features 0
Metric Value
c 2
b 2
f 0
dl 0
loc 27
rs 10
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B humanToPlain() 0 19 5
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