Issues (12)

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/Source/EloquentSource.php (4 issues)

Labels

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 Boduch\Grid\Source;
4
5
use Boduch\Grid\Column;
6
use Boduch\Grid\Filters\FilterOperator;
7
use Boduch\Grid\Order;
8
use Illuminate\Database\Eloquent\Builder;
9
10
class EloquentSource implements SourceInterface
11
{
12
    /**
13
     * @var \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
14
     */
15
    protected $source;
16
17
    /**
18
     * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model $source
19
     */
20
    public function __construct($source)
21
    {
22
        $this->source = $source;
23
    }
24
25
    /**
26
     * @param Column[] $columns
27
     */
28
    public function applyFilters($columns)
29
    {
30
        foreach ($columns as $column) {
31
            /** @var \Boduch\Grid\Column $column */
32
            if ($column->isFilterable() && !$column->getFilter()->isEmpty()) {
33
                $this->buildQuery($column);
34
            }
35
        }
36
    }
37
38
    /**
39
     * @param int $perPage
40
     * @param int $currentPage
41
     * @param Order $order
42
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
43
     */
44
    public function execute($perPage, $currentPage, Order $order)
45
    {
46
        return $this
0 ignored issues
show
The method when does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
47
            ->source
48
            ->when($order->getColumn(), function (Builder $builder) use ($order) {
49
                return $builder->orderBy($order->getColumn(), $order->getDirection());
0 ignored issues
show
The method orderBy() does not exist on Illuminate\Database\Eloquent\Builder. Did you maybe mean enforceOrderBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
50
            })
51
            ->forPage($currentPage, $perPage)
52
            ->get();
53
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function total()
59
    {
60
        return $this->source->count();
61
    }
62
63
    /**
64
     * @param Column $column
65
     */
66
    protected function buildQuery(Column $column)
67
    {
68
        $name = $column->getFilter()->getName();
69
        $input = $column->getFilter()->getInput();
70
71
        if ($column->getFilter()->getOperator() == FilterOperator::OPERATOR_BETWEEN) {
72
            $this->source->whereBetween($name, $input);
73
        } else {
74
            $this->source->where(
0 ignored issues
show
The method where does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
75
                $name,
76
                $column->getFilter()->getOperator(),
77
                $this->normalizeValue($input, $column->getFilter()->getOperator())
0 ignored issues
show
It seems like $input defined by $column->getFilter()->getInput() on line 69 can also be of type array; however, Boduch\Grid\Source\Eloqu...ource::normalizeValue() does only seem to accept string|array<integer,string>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
78
            );
79
        }
80
    }
81
82
    /**
83
     * @param string|string[] $value
84
     * @param string $operator
85
     * @return mixed
86
     */
87
    protected function normalizeValue($value, $operator)
88
    {
89
        if (is_array($value)) {
90
            $value = array_filter($value);
91
        }
92
93
        if ($operator == FilterOperator::OPERATOR_LIKE || $operator == FilterOperator::OPERATOR_ILIKE) {
94
            $value = str_replace('*', '%', $value);
95
        }
96
97
        return $value;
98
    }
99
}
100