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

SettingRenderer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 15 4
A html() 0 21 4
1
<?php
2
/**
3
 * additional setting classes specific to these settings
4
 *
5
 * @author    Chris Smith <[email protected]>
6
 */
7
8
namespace dokuwiki\plugin\config\core\Setting;
9
10
/**
11
 * Class setting_renderer
12
 */
13
class SettingRenderer extends SettingMultichoice {
14
    protected $prompts = array();
15
    protected $format = null;
16
17
    /** @inheritdoc */
18
    public function initialize($default = null, $local = null, $protected = null) {
19
        $format = $this->format;
20
21
        foreach(plugin_list('renderer') as $plugin) {
22
            $renderer = plugin_load('renderer', $plugin);
23
            if(method_exists($renderer, 'canRender') && $renderer->canRender($format)) {
0 ignored issues
show
Bug introduced by
The method canRender() does not seem to exist on object<DokuWiki_PluginInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
                $this->choices[] = $plugin;
25
26
                $info = $renderer->getInfo();
27
                $this->prompts[$plugin] = $info['name'];
28
            }
29
        }
30
31
        parent::initialize($default, $local, $protected);
32
    }
33
34
    /** @inheritdoc */
35
    public function html(\admin_plugin_config $plugin, $echo = false) {
36
37
        // make some language adjustments (there must be a better way)
38
        // transfer some plugin names to the config plugin
39
        foreach($this->choices as $choice) {
40
            if(!$plugin->getLang($this->key . '_o_' . $choice)) {
41
                if(!isset($this->prompts[$choice])) {
42
                    $plugin->addLang(
43
                        $this->key . '_o_' . $choice,
44
                        sprintf($plugin->getLang('renderer__core'), $choice)
45
                    );
46
                } else {
47
                    $plugin->addLang(
48
                        $this->key . '_o_' . $choice,
49
                        sprintf($plugin->getLang('renderer__plugin'), $this->prompts[$choice])
50
                    );
51
                }
52
            }
53
        }
54
        return parent::html($plugin, $echo);
55
    }
56
}
57