Completed
Push — FVSv2 ( 6cb237...94c8ac )
by Patrick
01:20
created

VolunteerPage::printPage()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 1
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
ini_set('display_errors', 1);
3
error_reporting(E_ALL);
4
require_once('class.SecurePage.php');
5
require_once('class.FlipSession.php');
6
require_once('app/VolunteerAutoload.php');
7
class VolunteerPage extends SecurePage
8
{
9
    public  $volunteerRoot;
10
11
    function __construct($title)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
    {
13
        parent::__construct($title);
14
        $root = $_SERVER['DOCUMENT_ROOT'];
15
        $script_dir = dirname(__FILE__);
16
        $this->volunteerRoot = substr($script_dir, strlen($root));
17
        $this->addJS($this->volunteerRoot.'/js/volunteer.js', false);
0 ignored issues
show
Unused Code introduced by
The call to VolunteerPage::addJS() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
18
        $this->addTemplateDir(dirname(__FILE__).'/templates', 'Volunteer');
19
        $this->setTemplateName('@Volunteer/main.html');
20
        $this->addCSS('https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/css/select2.min.css');
21
        $this->addJS('https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/js/select2.min.js');
22
        if($this->isAdmin() || $this->isLead())
23
        {
24
            $this->addLink('Admin', '_admin/');
25
        }
26
        if($this->user !== false && $this->user !== null)
1 ignored issue
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...
27
        {
28
            $this->addLink('Settings', 'settings.php');
29
        }
30
    }
31
32
    function printPage($header = true)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33
    {
34
        if($this->user === false || $this->user === null)
35
        {
36
            $this->body = '
37
<div id="content">
38
    <h1>You must <a href="https://profiles.burningflipside.com/login.php?return='.$this->currentURL().'">log in <span class="fa fa-sign-in-alt"></span></a> to access the Burning Flipside Volunteer system!</h1>
39
</div>';
40
        }
41
        parent::printPage($header);
0 ignored issues
show
Unused Code introduced by
The call to SecurePage::printPage() has too many arguments starting with $header.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
42
    }
43
44
    function isAdmin()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
45
    {
46
        if($this->user === false || $this->user === null)
47
        {
48
            return false;
49
        }
50
        return $this->user->isInGroupNamed('VolunteerAdmins');
51
    }
52
53
    function isLead()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
54
    {
55
        if($this->user === false || $this->user === null)
56
        {
57
            return false;
58
        }
59
        return $this->user->isInGroupNamed('Leads');
60
    }
61
}
62