Failed Conditions
Push — psr2 ( 8eb28c...c68e26 )
by Andreas
28s queued 20s
created

SettingDirchoice::initialize()   B

Complexity

Conditions 9
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 12
nc 2
nop 3
dl 0
loc 20
rs 7.756
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\plugin\config\core\Setting;
4
5
/**
6
 * Class setting_dirchoice
7
 */
8
class SettingDirchoice extends SettingMultichoice {
9
10
    protected $dir = '';
11
12
    /** @inheritdoc */
13
    public function initialize($default = null, $local = null, $protected = null) {
14
15
        // populate $this->_choices with a list of directories
16
        $list = array();
17
18
        if($dh = @opendir($this->dir)) {
19
            while(false !== ($entry = readdir($dh))) {
20
                if($entry == '.' || $entry == '..') continue;
21
                if($this->pattern && !preg_match($this->pattern, $entry)) continue;
22
23
                $file = (is_link($this->dir . $entry)) ? readlink($this->dir . $entry) : $this->dir . $entry;
24
                if(is_dir($file)) $list[] = $entry;
25
            }
26
            closedir($dh);
27
        }
28
        sort($list);
29
        $this->choices = $list;
30
31
        parent::initialize($default, $local, $protected);
32
    }
33
}
34