MembersOnlyPage_Controller   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 5 1
1
<?php
0 ignored issues
show
Coding Style introduced by
File has mixed line endings; this may cause incorrect results
Loading history...
2
3
class MembersOnlyPage extends Page
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...
4
{
5
    private static $add_action = 'Members Only Page';
0 ignored issues
show
Unused Code introduced by
The property $add_action is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
6
7
    private static $icon = 'mysite/images/treeicons/MembersOnlyPage';
0 ignored issues
show
Unused Code introduced by
The property $icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
8
9
    private static $default_parent = 'MembersOnlyPage';
0 ignored issues
show
Unused Code introduced by
The property $default_parent is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
11
    private static $allowed_children = array("MembersOnlyPage");
0 ignored issues
show
Unused Code introduced by
The property $allowed_children is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
13
    private static $group_code = "intranet-users";
14
    public static function set_group_code($v)
15
    {
16
        self::$group_code = $v;
17
    }
18
    public static function get_group_code()
19
    {
20
        return self::$group_code;
21
    }
22
23
    private static $group_name = "intranet users";
24
    public static function set_group_name($v)
25
    {
26
        self::$group_name = $v;
27
    }
28
    public static function get_group_name()
29
    {
30
        return self::$group_name;
31
    }
32
33
    private static $permission_code = "INTRANET_USERS";
34
    public static function set_permission_code($v)
35
    {
36
        self::$permission_code = $v;
37
    }
38
    public static function get_permission_code()
39
    {
40
        return self::$permission_code;
41
    }
42
43
    private static $defaults = array(
0 ignored issues
show
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
44
        "ProvideComments" => 1,
45
        "ShowInSearch" => 0
46
    );
47
48
49
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
50
    {
51
        $fields = parent::getCMSFields();
52
        return $fields;
53
    }
54
55
    public function canView($member = null)
56
    {
57
        if ($member = Member::currentUser()) {
58
            if ($member->inGroup("ADMIN") || Permission::checkMember($member, self::$permission_code)) {
59
                return true;
60
            }
61
        }
62
        return false;
63
    }
64
65
    public function getShowInMenus()
66
    {
67
        return $this->canView();
68
    }
69
70
    public function ShowInMenus()
71
    {
72
        return $this->canView();
73
    }
74
75
    public function getShowInSearch()
76
    {
77
        return $this->canView();
78
    }
79
80
    public function ShowInSearch()
81
    {
82
        return $this->canView();
83
    }
84
85
    public function requireDefaultRecords()
86
    {
87
        parent::requireDefaultRecords();
88
        $intranetGroup = Group::get()->filter(array("Code" => $this->Config()->get("group_code")))->first();
89
        if ($intranetGroup && $intranetGroup->exists()) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
90
            //do nothing
91
        } else {
92
            $intranetGroup = new Group();
93
            DB::alteration_message($this->Config()->get("group_name").' group created', "created");
94
        }
95
        if ($intranetGroup) {
96
            $intranetGroup->Code = $this->Config()->get("group_code");
97
            $intranetGroup->Title = $this->Config()->get("group_name");
98
            $intranetGroup->write();
99
            Permission::grant($intranetGroup->ID, $this->Config()->get("permission_code"));
100
            if (DB::query("
101
				SELECT *
102
				FROM Permission
103
				WHERE \"GroupID\" = '".$intranetGroup->ID."'
104
					AND \"Code\" LIKE '".$this->Config()->get("permission_code")."'")->numRecords() == 0
105
            ) {
106
                Permission::grant($intranetGroup->ID, $this->Config()->get("permission_code"));
107
                DB::alteration_message($this->Config()->get("group_name").' permissions granted', "created");
108
            }
109
        }
110
    }
111
}
112
113
class MembersOnlyPage_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
114
{
115
    public function init()
116
    {
117
        parent::init();
118
        Requirements::themedCSS("MembersOnlyPage", "membersonlypages");
119
    }
120
}
121