Issues (10)

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/SubqueryMagic/Scopes/SubqueryMagicScope.php (10 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 MaksimM\SubqueryMagic\Scopes;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\Relation;
8
use Illuminate\Database\Eloquent\Scope;
9
use Illuminate\Support\Facades\DB;
10
11
class SubqueryMagicScope implements Scope
12
{
13
    /**
14
     * All of the extensions to be added to the builder.
15
     *
16
     * @var array
17
     */
18
    protected $extensions = [
19
        'LeftJoinSubquery',
20
        'JoinSubquery',
21
        'RightJoinSubquery',
22
        'WhereInSubquery',
23
        'WhereNotInSubquery',
24
        'OrWhereInSubquery',
25
        'OrWhereNotInSubquery',
26
        'FromSubquery',
27
    ];
28
29
    /**
30
     * Apply the scope to a given Eloquent query builder.
31
     *
32
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
0 ignored issues
show
Consider making the type for parameter $builder a bit more specific; maybe use Builder.
Loading history...
33
     * @param \Illuminate\Database\Eloquent\Model            $model
34
     */
35
    public function apply(Builder $builder, Model $model)
36
    {
37
    }
38
39
    /**
40
     * Extend the query builder with the needed functions.
41
     *
42
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
0 ignored issues
show
Consider making the type for parameter $builder a bit more specific; maybe use Builder.
Loading history...
43
     */
44
    public function extend(Builder $builder)
45
    {
46
        foreach ($this->extensions as $extension) {
47
            $this->{"add{$extension}"}($builder);
48
        }
49
    }
50
51
    /**
52
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
53
     * @param array                                          $bindings
54
     * @param string                                         $type
55
     */
56
    private function addBindings($builder, $bindings, $type = 'where')
57
    {
58
        $builder->addBinding($bindings, $type);
59
    }
60
61
    /**
62
     * Add extension to the builder.
63
     *
64
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
65
     */
66 View Code Duplication
    protected function addLeftJoinSubquery($builder)
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...
67
    {
68
        $builder->macro('leftJoinSubquery', function ($builder, $subquery, $alias, \Closure $on) {
69
            /*
70
             * @var $builder \Illuminate\Database\Eloquent\Builder|Relation
71
             * @var $subquery \Illuminate\Database\Eloquent\Builder|Relation
72
             */
73
            $builder->leftJoin(DB::raw('('.$subquery->toSql().') '.$builder->getQuery()->getGrammar()->wrap($alias)), $on);
74
            //merge bindings from subquery
75
            $this->addBindings($builder, $subquery->getBindings(), 'join');
76
77
            return $builder;
78
        });
79
    }
80
81
    /**
82
     * Add extension to the builder.
83
     *
84
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
85
     */
86 View Code Duplication
    protected function addRightJoinSubquery($builder)
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...
87
    {
88
        $builder->macro('rightJoinSubquery', function ($builder, $subquery, $alias, \Closure $on) {
89
            /*
90
             * @var $builder \Illuminate\Database\Eloquent\Builder|Relation
91
             * @var $subquery \Illuminate\Database\Eloquent\Builder|Relation
92
             */
93
            $builder->rightJoin(DB::raw('('.$subquery->toSql().') '.$builder->getQuery()->getGrammar()->wrap($alias)), $on);
94
            //merge bindings from subquery
95
            $this->addBindings($builder, $subquery->getBindings(), 'join');
96
97
            return $builder;
98
        });
99
    }
100
101
    /**
102
     * Add extension to the builder.
103
     *
104
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
105
     */
106 View Code Duplication
    protected function addJoinSubquery($builder)
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...
107
    {
108
        $builder->macro('joinSubquery', function ($builder, $subquery, $alias, \Closure $on) {
109
            /*
110
             * @var $builder \Illuminate\Database\Eloquent\Builder|Relation
111
             * @var $subquery \Illuminate\Database\Eloquent\Builder|Relation
112
             */
113
            $builder->join(DB::raw('('.$subquery->toSql().') '.$builder->getQuery()->getGrammar()->wrap($alias)), $on);
114
            //merge bindings from subquery
115
            $this->addBindings($builder, $subquery->getBindings(), 'join');
116
117
            return $builder;
118
        });
119
    }
120
121
    /**
122
     * Add extension to the builder.
123
     *
124
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
125
     */
126 View Code Duplication
    protected function addWhereInSubquery($builder)
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...
127
    {
128
        $builder->macro('whereInSubquery', function ($builder, $field, $subquery) {
129
            /*
130
             * @var $builder \Illuminate\Database\Eloquent\Builder|Relation
131
             * @var $subquery \Illuminate\Database\Eloquent\Builder|Relation
132
             */
133
            $builder->whereRaw($builder->getQuery()->getGrammar()->wrap($field).' IN ('.$subquery->toSql().')');
134
            //merge bindings from subquery
135
            $this->addBindings($builder, $subquery->getBindings(), 'where');
136
137
            return $builder;
138
        });
139
    }
140
141
    /**
142
     * Add extension to the builder.
143
     *
144
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
145
     */
146 View Code Duplication
    protected function addWhereNotInSubquery($builder)
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...
147
    {
148
        $builder->macro('whereNotInSubquery', function ($builder, $field, $subquery) {
149
            /*
150
             * @var $builder \Illuminate\Database\Eloquent\Builder|Relation
151
             * @var $subquery \Illuminate\Database\Eloquent\Builder|Relation
152
             */
153
            $builder->whereRaw($builder->getQuery()->getGrammar()->wrap($field).' NOT IN ('.$subquery->toSql().')');
154
            //merge bindings from subquery
155
            $this->addBindings($builder, $subquery->getBindings(), 'where');
156
157
            return $builder;
158
        });
159
    }
160
161
    /**
162
     * Add extension to the builder.
163
     *
164
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
165
     */
166 View Code Duplication
    protected function addOrWhereInSubquery($builder)
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...
167
    {
168
        $builder->macro('orWhereInSubquery', function ($builder, $field, $subquery) {
169
            /*
170
             * @var $builder \Illuminate\Database\Eloquent\Builder|Relation
171
             * @var $subquery \Illuminate\Database\Eloquent\Builder|Relation
172
             */
173
            $builder->orWhereRaw($builder->getQuery()->getGrammar()->wrap($field).' IN ('.$subquery->toSql().')');
174
            //merge bindings from subquery
175
            $this->addBindings($builder, $subquery->getBindings(), 'where');
176
177
            return $builder;
178
        });
179
    }
180
181
    /**
182
     * Add extension to the builder.
183
     *
184
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
185
     */
186 View Code Duplication
    protected function addOrWhereNotInSubquery($builder)
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...
187
    {
188
        $builder->macro('orWhereNotInSubquery', function ($builder, $field, $subquery) {
189
            /*
190
             * @var $builder \Illuminate\Database\Eloquent\Builder|Relation
191
             * @var $subquery \Illuminate\Database\Eloquent\Builder|Relation
192
             */
193
            $builder->orWhereRaw($builder->getQuery()->getGrammar()->wrap($field).' NOT IN ('.$subquery->toSql().')');
194
            //merge bindings from subquery
195
            $this->addBindings($builder, $subquery->getBindings(), 'where');
196
197
            return $builder;
198
        });
199
    }
200
201
    /**
202
     * Add extension to the builder.
203
     *
204
     * @param \Illuminate\Database\Eloquent\Builder|Relation $builder
205
     */
206 View Code Duplication
    protected function addFromSubquery($builder)
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...
207
    {
208
        $builder->macro('fromSubquery', function ($builder, $subquery, $alias) {
209
            /*
210
             * @var $builder \Illuminate\Database\Eloquent\Builder|Relation
211
             * @var $subquery \Illuminate\Database\Eloquent\Builder|Relation
212
             */
213
            $builder->from(DB::raw('('.$subquery->toSql().') '.$builder->getQuery()->getGrammar()->wrap($alias)));
214
            //merge bindings from subquery
215
            $builder->setBindings(array_merge($subquery->getBindings(), $builder->getBindings()));
216
217
            return $builder;
218
        });
219
    }
220
}
221