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

SettingDirchoice   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B initialize() 0 20 9
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