Issues (33)

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/Processor.php (3 issues)

Labels
Severity

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 mav3rick177\RapidPagination;
4
5
use Illuminate\Database\Eloquent\Collection;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
8
use Illuminate\Support\Traits\Macroable;
9
use mav3rick177\RapidPagination\Base\AbstractProcessor;
10
use mav3rick177\RapidPagination\Base\Query;
11
12
/**
13
 * Class Processor
14
 *
15
 * @see AbstractProcessor
16
 */
17
class Processor extends AbstractProcessor
18
{
19
    use Macroable;
20
21
    /**
22
     * @var mixed
23
     */
24
    protected $builder;
25
26
    /**
27
     * Get result.
28
     *
29
     * @param  Query                       $query
30
     * @param  Collection|Model[]|object[] $rows
31
     * @return mixed
32
     */
33 2
    public function process(Query $query, $rows)
34
    {
35 2
        $this->builder = $query->builder();
36 2
        return parent::process($query, $rows);
37
    }
38
39
    /**
40
     * Return comparable value from a row.
41
     *
42
     * @param  mixed      $row
43
     * @param  string     $column
44
     * @return int|string
45
     */
46
    protected function field($row, $column)
47
    {
48
        $column = static::dropTablePrefix($column);
49
        if ($this->builder instanceof BelongsToMany && strpos($column, 'pivot_') === 0) {
50
            return $this->pivotField($row, substr($column, 6), $this->pivotAccessor());
51
        }
52
        $value = $row->$column;
53
        return is_object($value) ? (string)$value : $value;
54
    }
55
56
    /**
57
     * Extract pivot from a row.
58
     *
59
     * @param  mixed      $row
60
     * @param  string     $column
61
     * @param  string     $accessor
62
     * @throws \Exception
63
     * @return int|string
64
     */
65
    protected function pivotField($row, $column, $accessor)
66
    {
67
        $pivot = $row->$accessor;
68
        if (!isset($pivot->$column)) {
69
            throw new \Exception("The column `$column` is not included in the pivot \"$accessor\".");
70
        }
71
        return $this->field($pivot, $column);
72
    }
73
74
    /**
75
     * Extract pivot accessor from a relation.
76
     *
77
     * @return string
78
     */
79
    protected function pivotAccessor()
80
    {
81
        return $this->builder->getPivotAccessor();
82
    }
83
84
    /**
85
     * Return the n-th element of collection.
86
     * Must return null if not exists.
87
     *
88
     * @param  Collection|Model[]|object[] $rows
89
     * @param  int                         $offset
90
     * @return Model|object
91
     */
92 2
    protected function offset($rows, $offset)
93
    {
94 2
        return isset($rows[$offset]) ? $rows[$offset] : null;
95
    }
96
97
    /**
98
     * Slice rows, like PHP function array_slice().
99
     *
100
     * @param  Collection|Model[]|object[] $rows
101
     * @param  int                         $offset
102
     * @param  null|int                    $length
103
     * @return Collection|Model[]|object[]
104
     */
105
    protected function slice($rows, $offset, $length = null)
106
    {
107
        return $rows->slice($offset, $length)->values();
0 ignored issues
show
It seems like $rows is not always an object, but can also be of type array<integer,object>. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
108
    }
109
110
    /**
111
     * Count rows, like PHP function count().
112
     *
113
     * @param  Collection|Model[]|object[] $rows
114
     * @return int
115
     */
116 2
    protected function count($rows)
117
    {
118 2
        return $rows->count();
0 ignored issues
show
It seems like $rows is not always an object, but can also be of type array<integer,object>. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
119
    }
120
121
    /**
122
     * Reverse rows, like PHP function array_reverse().
123
     *
124
     * @param  Collection|Model[]|object[] $rows
125
     * @return Collection|Model[]|object[]
126
     */
127
    protected function reverse($rows)
128
    {
129
        return $rows->reverse()->values();
0 ignored issues
show
It seems like $rows is not always an object, but can also be of type array<integer,object>. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
130
    }
131
132
    /**
133
     * Format result.
134
     *
135
     * @param  Collection|Model[]|object[] $rows
136
     * @param  array                       $meta
137
     * @param  Query                       $query
138
     * @return PaginationResult
139
     */
140
    protected function defaultFormat($rows, array $meta, Query $query)
141
    {
142
        return new PaginationResult($rows, $meta);
143
    }
144
145
    /**
146
     * Drop table prefix on column name.
147
     *
148
     * @param  string $column
149
     * @return string
150
     */
151
    protected static function dropTablePrefix(string $column)
152
    {
153
        $segments = explode('.', $column);
154
155
        return end($segments);
156
    }
157
}
158