Issues (12)

Security Analysis    no request data  

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/Helper/Processor.php (3 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 Saxulum\PaginationProvider\Helper;
4
5
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
6
use Symfony\Component\Translation\TranslatorInterface;
7
8
/**
9
 * Pagination data processor
10
 *
11
 * Common data processor for all templating engines
12
 *
13
 * @author RafaƂ Wrzeszcz <[email protected]>
14
 */
15
class Processor
16
{
17
    /**
18
     * @var UrlGeneratorInterface
19
     */
20
    protected $urlGenerator;
21
22
    /**
23
     * @var TranslatorInterface
24
     */
25
    protected $translator;
26
27
    public function __construct(UrlGeneratorInterface $urlGenerator, TranslatorInterface $translator)
28
    {
29
        $this->urlGenerator = $urlGenerator;
30
        $this->translator = $translator;
31
    }
32
33
    /**
34
     * Generates pagination template data
35
     *
36
     * @param array $queryParams
37
     * @param array $viewParams
38
     *
39
     * @return array
40
     */
41
    public function render($pagination, array $queryParams = array(), array $viewParams = array())
42
    {
43
        $data = $pagination->getPaginationData();
44
45
        $data['route'] = $pagination->getRoute();
46
        $data['query'] = array_merge($pagination->getParams(), $queryParams);
47
48
        return array_merge(
49
            $pagination->getPaginatorOptions(), // options given to paginator when paginated
50
            $pagination->getCustomParameters(), // all custom parameters for view
51
            $viewParams, // additional custom parameters for view
52
            $data // merging base route parameters last, to avoid broke of integrity
53
        );
54
    }
55
56
    /**
57
     * Create a sort url for the field named $title
58
     * and identified by $key which consists of
59
     * alias and field. $options holds all link
60
     * parameters like "alt, class" and so on.
61
     *
62
     * $key example: "article.title"
63
     *
64
     * @param  string $title
65
     * @param  string $key
66
     * @param  array  $options
67
     * @param  array  $params
68
     * @return array
69
     */
70
    public function sortable($pagination, $title, $key, $options = array(), $params = array())
71
    {
72
        $options = array_merge(array(
73
            'absolute' => false,
74
            'translationParameters' => array(),
75
            'translationDomain' => null,
76
            'translationCount' => null,
77
        ), $options);
78
79
        $params = array_merge($pagination->getParams(), $params);
80
81
        $direction = isset($options[$pagination->getPaginatorOption('sortDirectionParameterName')])
82
            ? $options[$pagination->getPaginatorOption('sortDirectionParameterName')]
83
            : (isset($options['defaultDirection']) ? $options['defaultDirection'] : 'asc')
84
        ;
85
86
        $sorted = $pagination->isSorted($key, $params);
87
88
        if ($sorted) {
89
            $direction = $params[$pagination->getPaginatorOption('sortDirectionParameterName')];
90
            $direction = (strtolower($direction) == 'asc') ? 'desc' : 'asc';
91
            $class = $direction == 'asc' ? 'desc' : 'asc';
92
93
            if (isset($options['class'])) {
94
                $options['class'] .= ' ' . $class;
95
            } else {
96
                $options['class'] = $class;
97
            }
98
        } else {
99
            $options['class'] = 'sortable';
100
        }
101
102
        if (is_array($title) && array_key_exists($direction, $title)) {
103
            $title = $title[$direction];
104
        }
105
106
        $params = array_merge(
107
            $params,
108
            array(
109
                $pagination->getPaginatorOption('sortFieldParameterName') => $key,
110
                $pagination->getPaginatorOption('sortDirectionParameterName') => $direction,
111
                $pagination->getPaginatorOption('pageParameterName') => 1 // reset to 1 on sort
112
            )
113
        );
114
115
        $options['href'] = $this->urlGenerator->generate($pagination->getRoute(), $params, $options['absolute']);
116
117
        if (null !== $options['translationDomain']) {
118
            if (null !== $options['translationCount']) {
119
                $title = $this->translator->transChoice($title, $options['translationCount'], $options['translationParameters'], $options['translationDomain']);
120
            } else {
121
                $title = $this->translator->trans($title, $options['translationParameters'], $options['translationDomain']);
122
            }
123
        }
124
125
        if (!isset($options['title'])) {
126
            $options['title'] = $title;
127
        }
128
129
        unset($options['absolute'], $options['translationDomain'], $options['translationParameters']);
130
131
        return array_merge(
132
            $pagination->getPaginatorOptions(),
133
            $pagination->getCustomParameters(),
134
            compact('options', 'title', 'direction', 'sorted', 'key')
135
        );
136
    }
137
138
    /**
139
     * Create a filter url for the field named $title
140
     * and identified by $key which consists of
141
     * alias and field. $options holds all link
142
     * parameters like "alt, class" and so on.
143
     *
144
     * $key example: "article.title"
145
     *
146
     * @param  string $title
0 ignored issues
show
There is no parameter named $title. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
147
     * @param  string $key
0 ignored issues
show
There is no parameter named $key. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
148
     * @param  array  $options
149
     * @param  array  $params
150
     * @return array
151
     */
152
    public function filter($pagination, array $fields, $options = array(), $params = array())
153
    {
154
        $options = array_merge(array(
155
            'absolute' => false,
156
            'translationParameters' => array(),
157
            'translationDomain' => null,
158
            'button' => 'Filter',
159
        ), $options);
160
161
        $params = array_merge($pagination->getParams(), $params);
162
        $params[$pagination->getPaginatorOption('pageParameterName')] = 1; // reset to 1 on filter
163
164
        $filterFieldName = $pagination->getPaginatorOption('filterFieldParameterName');
165
        $filterValueName = $pagination->getPaginatorOption('filterValueParameterName');
166
167
        $selectedField = isset($params[$filterFieldName]) ? $params[$filterFieldName] : null;
168
        $selectedValue = isset($params[$filterValueName]) ? $params[$filterValueName] : null;
169
170
        $action = $this->urlGenerator->generate($pagination->getRoute(), $params, $options['absolute']);
0 ignored issues
show
$options['absolute'] is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
171
172
        foreach ($fields as $field => $title) {
173
            $fields[$field] = $this->translator->trans($title, $options['translationParameters'], $options['translationDomain']);
174
        }
175
        $options['button'] = $this->translator->trans($options['button'], $options['translationParameters'], $options['translationDomain']);
176
177
        unset($options['absolute'], $options['translationDomain'], $options['translationParameters']);
178
179
        return array_merge(
180
            $pagination->getPaginatorOptions(),
181
            $pagination->getCustomParameters(),
182
            compact('fields', 'action', 'filterFieldName', 'filterValueName', 'selectedField', 'selectedValue', 'options')
183
        );
184
    }
185
}
186