GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 221cb7...4c749c )
by Christian
04:35 queued 02:34
created

View::encodeHTML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * Class View
5
 * The part that handles all the output
6
 */
7
class View
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...
8
{
9
    /**
10
     * simply includes (=shows) the view. this is done from the controller. In the controller, you usually say
11
     * $this->view->render('help/index'); to show (in this example) the view index.php in the folder help.
12
     * Usually the Class and the method are the same like the view, but sometimes you need to show different views.
13
     * @param string $filename Path of the to-be-rendered view, usually folder/file(.php)
14
     * @param array $data Data to be used in the view
15
     */
16
    public function render($filename, $data = null)
17
    {
18
        if ($data) {
19
            foreach ($data as $key => $value) {
20
                $this->{$key} = $value;
21
            }
22
        }
23
24
        require Config::get('PATH_VIEW') . '_templates/header.php';
25
        require Config::get('PATH_VIEW') . $filename . '.php';
26
        require Config::get('PATH_VIEW') . '_templates/footer.php';
27
    }
28
29
    /**
30
     * Similar to render, but accepts an array of separate views to render between the header and footer. Use like
31
     * the following: $this->view->renderMulti(array('help/index', 'help/banner'));
32
     * @param array $filenames Array of the paths of the to-be-rendered view, usually folder/file(.php) for each
33
     * @param array $data Data to be used in the view
34
     * @return bool
35
     */
36
    public function renderMulti($filenames, $data = null)
37
    {
38
        if (!is_array($filenames)) {
39
            self::render($filenames, $data); 
40
            return false;
41
        }
42
43
        if ($data) {
44
            foreach ($data as $key => $value) {
45
                $this->{$key} = $value;
46
            }
47
        }
48
49
        require Config::get('PATH_VIEW') . '_templates/header.php';
50
51
        foreach($filenames as $filename) {
52
            require Config::get('PATH_VIEW') . $filename . '.php';
53
        }
54
55
        require Config::get('PATH_VIEW') . '_templates/footer.php';
56
    }
57
58
    /**
59
     * Same like render(), but does not include header and footer
60
     * @param string $filename Path of the to-be-rendered view, usually folder/file(.php)
61
     * @param mixed $data Data to be used in the view
62
     */
63
    public function renderWithoutHeaderAndFooter($filename, $data = null)
64
    {
65
        if ($data) {
66
            foreach ($data as $key => $value) {
67
                $this->{$key} = $value;
68
            }
69
        }
70
71
        require Config::get('PATH_VIEW') . $filename . '.php';
72
    }
73
74
    /**
75
     * Renders pure JSON to the browser, useful for API construction
76
     * @param $data
77
     */
78
    public function renderJSON($data)
79
    {
80
        header("Content-Type: application/json");
81
        echo json_encode($data);
82
    }
83
84
    /**
85
     * renders the feedback messages into the view
86
     */
87
    public function renderFeedbackMessages()
88
    {
89
        // echo out the feedback messages (errors and success messages etc.),
90
        // they are in $_SESSION["feedback_positive"] and $_SESSION["feedback_negative"]
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
91
        require Config::get('PATH_VIEW') . '_templates/feedback.php';
92
93
        // delete these messages (as they are not needed anymore and we want to avoid to show them twice
94
        Session::set('feedback_positive', null);
95
        Session::set('feedback_negative', null);
96
    }
97
98
    /**
99
     * Checks if the passed string is the currently active controller.
100
     * Useful for handling the navigation's active/non-active link.
101
     *
102
     * @param string $filename
103
     * @param string $navigation_controller
104
     *
105
     * @return bool Shows if the controller is used or not
106
     */
107
    public static function checkForActiveController($filename, $navigation_controller)
108
    {
109
        $split_filename = explode("/", $filename);
110
        $active_controller = $split_filename[0];
111
112
        if ($active_controller == $navigation_controller) {
113
            return true;
114
        }
115
116
        return false;
117
    }
118
119
    /**
120
     * Checks if the passed string is the currently active controller-action (=method).
121
     * Useful for handling the navigation's active/non-active link.
122
     *
123
     * @param string $filename
124
     * @param string $navigation_action
125
     *
126
     * @return bool Shows if the action/method is used or not
127
     */
128
    public static function checkForActiveAction($filename, $navigation_action)
129
    {
130
        $split_filename = explode("/", $filename);
131
        $active_action = $split_filename[1];
132
133
        if ($active_action == $navigation_action) {
134
            return true;
135
        }
136
137
        return false;
138
    }
139
140
    /**
141
     * Checks if the passed string is the currently active controller and controller-action.
142
     * Useful for handling the navigation's active/non-active link.
143
     *
144
     * @param string $filename
145
     * @param string $navigation_controller_and_action
146
     *
147
     * @return bool
148
     */
149
    public static function checkForActiveControllerAndAction($filename, $navigation_controller_and_action)
150
    {
151
        $split_filename = explode("/", $filename);
152
        $active_controller = $split_filename[0];
153
        $active_action = $split_filename[1];
154
155
        $split_filename = explode("/", $navigation_controller_and_action);
156
        $navigation_controller = $split_filename[0];
157
        $navigation_action = $split_filename[1];
158
159
        if ($active_controller == $navigation_controller AND $active_action == $navigation_action) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
160
            return true;
161
        }
162
163
        return false;
164
    }
165
    
166
    /**
167
     * Converts characters to HTML entities
168
     * This is important to avoid XSS attacks, and attempts to inject malicious code in your page.
169
     *
170
     * @param  string $str The string.
171
     * @return string
172
     */
173
    public function encodeHTML($str){
174
        return htmlentities($str, ENT_QUOTES, 'UTF-8');
175
    }
176
}
177