Completed
Push — master ( 684547...3485b7 )
by Myles
01:58
created

DevTasks::init()   F

Complexity

Conditions 11
Paths 259

Size

Total Lines 49
Code Lines 30

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 49
rs 3.8181
cc 11
eloc 30
nc 259
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Fancy Dev Build base class
5
 *
6
 * @package DevTasks
7
 *
8
 */
9
class DevTasks extends LeftAndMainExtension implements PermissionProvider
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
12
    public function init()
13
    {
14
        parent::init();
15
16
        if (!Permission::check("VIEW_DEVTASKS")) {
17
            return;
18
        }
19
20
        $default_tasks = array(
21
            'devbuild' => array(
22
                'title' => 'Dev/Build',
23
                'link' => 'dev/build',
24
                'reset_time' => '5000',
25
                'error_markup'=> '.xdebug-error,.xe-parse-error',
26
                'error_handler' => 'newtab',
27
                'success_markup'=> 'li[style="color: blue"],li[style="color: green"]',
28
                'success_handler' => 'ignore'
29
            )
30
        );
31
32
        $config_tasks = Config::inst()->get(__CLASS__, 'tasks');
33
34
        if (is_array($config_tasks)) {
35
            $tasks = array_merge($default_tasks, $config_tasks);
36
        }else{
37
            $tasks = $default_tasks;
38
        }
39
40
        foreach ($tasks as $item => $values) {
41
42
            $attributes = array(
43
                'class' => 'devbuild-trigger',
44
                'data-title' => (isset($values['title']) ? $values['title'] : $item),
45
                'data-link' => (isset($values['link']) ? $values['link'] : $default_tasks['devbuild']['link']),
46
                'data-reset-time' => (isset($values['reset_time']) ? $values['reset_time'] : $default_tasks['devbuild']['reset_time']),
47
                'data-error-markup' => (isset($values['error_markup']) ? $values['error_markup'] : $default_tasks['devbuild']['error_markup']),
48
                'data-error-handler' => (isset($values['error_handler']) ? $values['error_handler'] : $default_tasks['devbuild']['error_handler']),
49
                'data-success-markup' => (isset($values['success_markup']) ? $values['success_markup'] : $default_tasks['devbuild']['success_markup']),
50
                'data-success-handler' => (isset($values['success_handler']) ? $values['success_handler'] : $default_tasks['devbuild']['success_handler'])
51
            );
52
53
            // priority controls the ordering of the link in the stack. The
54
            // lower the number, the lower in the list
55
            $priority = -90;
56
57
            CMSMenu::add_link($item, '', '#', $priority, $attributes);
58
59
        }
60
    }
61
62
    public function providePermissions()
63
    {
64
        return array(
65
            "VIEW_DEVTASKS" => "Access dev task menu",
66
        );
67
    }
68
69
}
70
71
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
72