Completed
Push — svgpagetools ( 17ef2a...7c844e )
by Andreas
04:40
created

Edit::__construct()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 34
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 26
nc 6
nop 0
dl 0
loc 34
rs 6.7272
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Menu\Item;
4
5
class Edit extends AbstractItem {
6
7
    /** @inheritdoc */
8
    public function __construct() {
9
        global $ACT;
10
        global $INFO;
11
        global $REV;
12
13
        parent::__construct();
14
15
        if($ACT == 'show' || $ACT == 'search') {
16
            $this->method = 'post';
17
            if($INFO['writable']) {
18
                $this->accesskey = 'e';
19
                if(!empty($INFO['draft'])) {
20
                    $this->type = 'draft';
21
                    $this->params['do'] = 'draft';
22
                } else {
23
                    $this->params['rev'] = $REV;
24
                    if(!$INFO['exists']) {
25
                        $this->type = 'create';
26
                    }
27
                }
28
            } else {
29
                if(!actionOK($this->type)) throw new \RuntimeException("action disabled: source");
30
                $params['rev'] = $REV;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
31
                $this->type = 'source';
32
                $this->accesskey = 'v';
33
            }
34
        } else {
35
            $this->params = array('do' => '');
36
            $this->type = 'show';
37
            $this->accesskey = 'v';
38
        }
39
40
        $this->setIcon();
41
    }
42
43
    /**
44
     * change the icon according to what type the edit button has
45
     */
46
    protected function setIcon() {
47
        $icons = array(
48
            'edit' => '01-edit_pencil.svg',
49
            'create' => '02-create_pencil.svg',
50
            'draft' => '03-draft_android-studio.svg',
51
            'show' => '04-show_file-document.svg',
52
            'source' => '05-source_file-xml.svg',
53
        );
54
        if(isset($icons[$this->type])) {
55
            $this->svg = DOKU_INC . 'lib/images/menu/' . $icons[$this->type];
56
        }
57
    }
58
59
}
60