Ext_Users_Group   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 55.56 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 20
loc 36
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A requireDefaultRecords() 20 33 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * Overwrite group object so we can setup some more default groups
5
 *
6
 * @package Users
7
 * @author  i-lateral <[email protected]>
8
 */
9
class Ext_Users_Group extends DataExtension
10
{
11
    public function requireDefaultRecords()
12
    {
13
        parent::requireDefaultRecords();
14
15
        // Add default author group if no other group exists
16
        $frontend_group = Group::get()->filter("Code", "users-frontend");
17
18 View Code Duplication
        if (!$frontend_group->exists()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
            $frontend_group = new Group();
20
            $frontend_group->Code = 'users-frontend';
21
            $frontend_group->Title = "Frontend Users";
22
            $frontend_group->Sort = 1;
23
            $frontend_group->write();
24
            Permission::grant($frontend_group->ID, 'USERS_MANAGE_ACCOUNT');
25
26
            DB::alteration_message('Front end users group created', 'created');
27
        }
28
29
        // Add a verified users group (only used if we turn on
30
        // verification)
31
        $verify_group = Group::get()->filter("Code", "users-verified");
32
33 View Code Duplication
        if (!$verify_group->exists()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            $verify_group = new Group();
35
            $verify_group->Code = 'users-verified';
36
            $verify_group->Title = "Verified Users";
37
            $verify_group->Sort = 1;
38
            $verify_group->write();
39
            Permission::grant($verify_group->ID, 'USERS_VERIFIED');
40
41
            DB::alteration_message('Verified users group created', 'created');
42
        }
43
    }
44
}
45