Issues (337)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/component/Html/Paging.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Rudolf\Component\Html;
4
5
class Paging
6
{
7
    /**
8
     * @var array
9
     */
10
    private $info;
11
12
    /**
13
     * @var string
14
     */
15
    private $path;
16
17
    /**
18
     * @var array
19
     */
20
    private $classes;
21
22
    /**
23
     * @var int
24
     */
25
    private $nesting;
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param array  $info     with data for loop
31
     *                        <page> - current page
32
     *                        <forstart> -
33
     *                        <forend> -
34
     *                        <allpages> - all pages
35
     *                        <prev> - prev page
36
     *                        <next> - next page
37
     * @param string $path    path with a slash at the beginning and at the end without him, like: '/kg'
38
     * @param array  $classes Specifies a pagination appearance
39
     *                        <ul> - main ul class
40
     *                        <current> - current active li class
41
     * @param int    $nesting
42
     */
43
    public function __construct(array $info = [], $path = '', array $classes = [], $nesting = 0)
44
    {
45
        $this->setInfo($info);
46
        $this->setPath($path);
47
        $this->setClasses($classes);
48
        $this->setNesting($nesting);
49
    }
50
51
    public function setInfo(array $info)
52
    {
53
        $this->info = $info;
54
    }
55
56
    public function getInfo()
57
    {
58
        return $this->info;
59
    }
60
61
    public function setPath($path)
62
    {
63
        $this->path = $path;
64
    }
65
66
    public function getPath()
67
    {
68
        return DIR.$this->path;
69
    }
70
71 View Code Duplication
    public function setClasses(array $classes)
0 ignored issues
show
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...
72
    {
73
        $this->classes = array_merge([
74
            'ul' => '',
75
            'li' => '',
76
            'li_current' => '',
77
            'a' => '',
78
            'a_current' => '',
79
        ], $classes);
80
    }
81
82
    public function getClasses()
83
    {
84
        return $this->classes;
85
    }
86
87
    public function setNesting($nesting)
88
    {
89
        $this->nesting = $nesting;
90
    }
91
92
    public function getNesting()
93
    {
94
        return $this->nesting;
95
    }
96
97
    /**
98
     * Put value is not empty.
99
     *
100
     * @param string       $attribute
101
     * @param string|array $value
102
     *
103
     * @return string
104
     */
105 View Code Duplication
    private function isAttribute($attribute, $value)
0 ignored issues
show
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...
106
    {
107
        if (is_array($value)) {
108
            array_filter($value);
109
            $value = trim(implode(' ', $value));
110
111
            return !empty($value) ? ' '.$attribute.'="'.$value.'"' : '';
112
        }
113
114
        return (isset($value) and !empty($value)) ? ' '.$attribute.'="'.trim($value).'"' : '';
115
    }
116
117
    public function create()
118
    {
119
        $nav = $this->getInfo();
120
        $path = $this->getPath();
121
        $classes = $this->getClasses();
122
        $nesting = $this->getNesting();
123
124
        $html[] = sprintf('<ul%1$s>', $this->isAttribute('class', $classes['ul']));
0 ignored issues
show
Coding Style Comprehensibility introduced by
$html was never initialized. Although not strictly required by PHP, it is generally a good practice to add $html = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
125
126
        $nest = str_repeat("\t", $nesting);
127
        $tab = str_repeat("\t", 1 + $nesting);
128
129
        if ($nav['page'] > 1) {
130
            $html[] = sprintf(
131
                '%1$s<li%2$s><a%3$s href="%4$s">«</a></li>',
132
                $tab,
133
                $this->isAttribute('class', $classes['li']),
134
                $this->isAttribute('class', $classes['a']),
135
                $path.'/page/'.$nav['prev']
136
            );
137
        }
138 View Code Duplication
        if ($nav['forstart'] > 1) {
0 ignored issues
show
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...
139
            $html[] = sprintf(
140
                '%1$s<li%2$s><a%3$s href="%4$s">1</a></li>',
141
                $tab,
142
                $this->isAttribute('class', $classes['li']),
143
                $this->isAttribute('class', $classes['a']),
144
                $path.'/page/1'
145
            );
146
        }
147 View Code Duplication
        if ($nav['forstart'] > 2) {
0 ignored issues
show
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...
148
            $html[] = sprintf(
149
                '%1$s<li%2$s><a%3$s>...</a></li>',
150
                $tab,
151
                $this->isAttribute('class', $classes['li']),
152
                $this->isAttribute('class', $classes['a'])
153
            );
154
        }
155
        for ($nav['forstart']; $nav['forstart'] < $nav['forend']; ++$nav['forstart']) {
156
            if ((int) $nav['forstart'] === $nav['page']) {
157
                $html[] = sprintf(
158
                    '%1$s<li%2$s><a%3$s href="%4$s">%5$s</a></li>',
159
                    $tab,
160
                    $this->isAttribute('class', [$classes['li'], $classes['li_current']]),
161
                    $this->isAttribute('class', [$classes['a'], $classes['a_current']]),
162
                    $path.'/page/'.$nav['forstart'],
163
                    $nav['forstart']
164
                );
165
            }
166 View Code Duplication
            if ((int) $nav['forstart'] !== $nav['page']) {
0 ignored issues
show
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...
167
                $html[] = sprintf(
168
                    '%1$s<li%2$s><a%3$s href="%4$s">%5$s</a></li>',
169
                    $tab,
170
                    $this->isAttribute('class', $classes['li']),
171
                    $this->isAttribute('class', $classes['a']),
172
                    $path.'/page/'.$nav['forstart'],
173
                    $nav['forstart']
174
                );
175
            }
176
        }
177 View Code Duplication
        if ($nav['forstart'] < $nav['allpages']) {
0 ignored issues
show
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...
178
            $html[] = sprintf(
179
                '%1$s<li%2$s><a%3$s>...</a></li>',
180
                $tab,
181
                $this->isAttribute('class', $classes['li']),
182
                $this->isAttribute('class', $classes['a'])
183
            );
184
        }
185 View Code Duplication
        if ($nav['forstart'] - 1 < $nav['allpages']) {
0 ignored issues
show
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...
186
            $html[] = sprintf(
187
                '%1$s<li%2$s><a%3$s href="%4$s">%5$s</a></li>',
188
                $tab,
189
                $this->isAttribute('class', $classes['li']),
190
                $this->isAttribute('class', $classes['a']),
191
                $path.'/page/'.$nav['allpages'],
192
                $nav['allpages']
193
            );
194
        }
195 View Code Duplication
        if ($nav['page'] < $nav['allpages']) {
0 ignored issues
show
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...
196
            $html[] = sprintf(
197
                '%1$s<li%2$s><a%3$s href="%4$s">»</a></li>',
198
                $tab,
199
                $this->isAttribute('class', $classes['li']),
200
                $this->isAttribute('class', $classes['a']),
201
                $path.'/page/'.$nav['next']
202
            );
203
        }
204
        $html[] = $nest.'</ul>'."\n";
205
206
        return implode("\n", $html);
207
    }
208
}
209