Completed
Push — master ( 0c2ef0...55e98a )
by Patrick
02:54
created

FlipAdminPage::addCard()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 4
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
namespace Http;
3
class FlipAdminPage extends LoginRequiredPage
4
{
5
    public $is_admin = false;
6
7
    public function __construct($title, $adminGroup = 'LDAPAdmins')
8
    {
9
        parent::__construct($title);
10
        $this->is_admin = $this->userIsAdmin($adminGroup);
11
        $this->setTemplateName('admin.html');
12
    }
13
14 View Code Duplication
    protected function userIsAdmin($adminGroup)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
15
    {
16
        if($this->user === false || $this->user === null)
0 ignored issues
show
Bug introduced by
The property user does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
        {
18
            return false;
19
        }
20
        return $this->user->isInGroupNamed($adminGroup);
21
    }
22
23
    public function isAdmin()
24
    {
25
        return $this->is_admin;
26
    }
27
28
    protected function getContent()
29
    {
30
        if($this->isAdmin() === false)
31
        {
32
            $this->body = '
33
        <div class="row">
34
            <div class="col-lg-12">
35
                <h1 class="page-header">The current user does not have access rights to the '.$this->content['pageTitle'].' Admin system!</h1>
0 ignored issues
show
Bug introduced by
The property content does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
            </div>
37
        </div>';
38
        }
39
        return parent::getContent();
40
    }
41
42
    const CARD_GREEN  = 'green';
43
    const CARD_BLUE   = 'blue';
44
    const CARD_YELLOW = 'yellow';
45
    const CARD_RED    = 'red';
46
47
    public function addCard($icon, $text, $link, $color = false)
48
    {
49
        if(!isset($this->content['cards']))
50
        {
51
            $this->content['cards'] = array();
52
        }
53
        $card = array('icon' => $icon, 'text' => $text, 'link' => $link);
54
        if($color !== false)
55
        {
56
            $card['color'] = $color;
57
        }
58
        array_push($this->content['cards'], $card);
59
    }
60
}
61
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
62