Passed
Push — master ( 72cab2...77b286 )
by Andreas
65:38 queued 23:02
created

midcom_helper_toolbar_host   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 43
ccs 22
cts 30
cp 0.7332
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add_commands() 0 33 3
A __construct() 0 6 1
1
<?php
2
/**
3
 * @package midcom.helper
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
/**
10
 * This class is a host toolbar class.
11
 *
12
 * @package midcom.helper
13
 */
14
class midcom_helper_toolbar_host extends midcom_helper_toolbar
15
{
16 8
    public function __construct()
17
    {
18 8
        $config = midcom::get()->config;
19 8
        parent::__construct($config->get('toolbars_host_style_class'), $config->get('toolbars_host_style_id'));
0 ignored issues
show
Bug introduced by
It seems like $config->get('toolbars_host_style_class') can also be of type null; however, parameter $class_style of midcom_helper_toolbar::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        parent::__construct(/** @scrutinizer ignore-type */ $config->get('toolbars_host_style_class'), $config->get('toolbars_host_style_id'));
Loading history...
20 8
        $this->label = midcom::get()->i18n->get_string('host', 'midcom');
21 8
        $this->add_commands();
22 8
    }
23
24 8
    private function add_commands()
25
    {
26 8
        $buttons = [];
27 8
        if (midcom::get()->auth->user) {
28 8
            $buttons[] = [
29 8
                MIDCOM_TOOLBAR_URL => midcom_connection::get_url('self') . "midcom-logout-",
30 8
                MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('logout', 'midcom'),
31 8
                MIDCOM_TOOLBAR_GLYPHICON => 'sign-out',
32 8
                MIDCOM_TOOLBAR_ACCESSKEY => 'l',
33
            ];
34
        }
35
36 8
        $buttons[] = [
37 8
            MIDCOM_TOOLBAR_URL => midcom_connection::get_url('self') . "__mfa/asgard/",
38 8
            MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('midgard.admin.asgard', 'midgard.admin.asgard'),
39 8
            MIDCOM_TOOLBAR_GLYPHICON => 'server',
40 8
            MIDCOM_TOOLBAR_ACCESSKEY => 'a',
41 8
            MIDCOM_TOOLBAR_ENABLED => midcom::get()->auth->can_user_do('midgard.admin.asgard:access', null, 'midgard_admin_asgard_plugin'),
42
        ];
43
44 8
        if (midcom_connection::is_admin()) {
45
            $buttons[] = [
46
                MIDCOM_TOOLBAR_URL => midcom_connection::get_url('self') . "midcom-cache-invalidate",
47
                MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('invalidate cache', 'midcom'),
48
                MIDCOM_TOOLBAR_GLYPHICON => 'refresh',
49
            ];
50
            $workflow = new midcom\workflow\viewer;
51
            $buttons[] = $workflow->get_button(midcom_connection::get_url('self') . "midcom-config-test", [
52
                MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('test settings', 'midcom'),
53
                MIDCOM_TOOLBAR_GLYPHICON => 'wrench',
54
            ]);
55
        }
56 8
        $this->add_items($buttons);
57 8
    }
58
}
59