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/Traits/Pageable.php (7 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
declare(strict_types=1);
4
5
namespace Rinvex\Pages\Traits;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Database\Eloquent\Relations\MorphToMany;
9
10
trait Pageable
11
{
12
    /**
13
     * Register a saved model event with the dispatcher.
14
     *
15
     * @param \Closure|string $callback
16
     *
17
     * @return void
18
     */
19
    abstract public static function saved($callback);
20
21
    /**
22
     * Register a deleted model event with the dispatcher.
23
     *
24
     * @param \Closure|string $callback
25
     *
26
     * @return void
27
     */
28
    abstract public static function deleted($callback);
29
30
    /**
31
     * Define a polymorphic many-to-many relationship.
32
     *
33
     * @param string $related
34
     * @param string $name
35
     * @param string $table
0 ignored issues
show
Should the type for parameter $table not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
36
     * @param string $foreignPivotKey
0 ignored issues
show
Should the type for parameter $foreignPivotKey not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
37
     * @param string $relatedPivotKey
0 ignored issues
show
Should the type for parameter $relatedPivotKey not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
38
     * @param string $parentKey
0 ignored issues
show
Should the type for parameter $parentKey not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
39
     * @param string $relatedKey
0 ignored issues
show
Should the type for parameter $relatedKey not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
40
     * @param bool   $inverse
41
     *
42
     * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
43
     */
44
    abstract public function morphToMany(
45
        $related,
46
        $name,
47
        $table = null,
48
        $foreignPivotKey = null,
49
        $relatedPivotKey = null,
50
        $parentKey = null,
51
        $relatedKey = null,
52
        $inverse = false
53
    );
54
55
    /**
56
     * Get all attached pages to the model.
57
     *
58
     * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
59
     */
60
    public function pages(): MorphToMany
61
    {
62
        return $this->morphToMany(config('rinvex.pages.models.page'), 'pageable', config('rinvex.pages.tables.pageables'), 'pageable_id', 'page_id')
0 ignored issues
show
The method orderBy() does not exist on Illuminate\Database\Eloquent\Relations\MorphToMany. Did you maybe mean orderByPivot()?

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...
63
                    ->orderBy('sort_order')
64
                    ->withTimestamps();
65
    }
66
67
    /**
68
     * Boot the pageable trait for the model.
69
     *
70
     * @return void
71
     */
72
    public static function bootPageable()
73
    {
74
        static::deleted(function (self $model) {
75
            $model->pages()->detach();
76
        });
77
    }
78
79
    /**
80
     * Attach the given page(s) to the model.
81
     *
82
     * @param mixed $pages
83
     *
84
     * @return void
85
     */
86
    public function setPagesAttribute($pages): void
87
    {
88
        static::saved(function (self $model) use ($pages) {
89
            $model->syncPages($pages);
90
        });
91
    }
92
93
    /**
94
     * Scope query with all the given pages.
95
     *
96
     * @param \Illuminate\Database\Eloquent\Builder $builder
97
     * @param mixed                                 $pages
98
     *
99
     * @return \Illuminate\Database\Eloquent\Builder
100
     */
101
    public function scopeWithAllPages(Builder $builder, $pages): Builder
102
    {
103
        collect($pages)->each(function ($page) use ($builder) {
104
            $builder->whereHas('pages', function (Builder $builder) use ($page) {
105
                return $builder->where('id', $page);
106
            });
107
        });
108
109
        return $builder;
110
    }
111
112
    /**
113
     * Scope query with any of the given pages.
114
     *
115
     * @param \Illuminate\Database\Eloquent\Builder $builder
116
     * @param mixed                                 $pages
117
     *
118
     * @return \Illuminate\Database\Eloquent\Builder
119
     */
120
    public function scopeWithAnyPages(Builder $builder, $pages): Builder
121
    {
122
        return $builder->whereHas('pages', function (Builder $builder) use ($pages) {
123
            $builder->whereIn('id', $pages);
124
        });
125
    }
126
127
    /**
128
     * Scope query without any of the given pages.
129
     *
130
     * @param \Illuminate\Database\Eloquent\Builder $builder
131
     * @param mixed                                 $pages
132
     *
133
     * @return \Illuminate\Database\Eloquent\Builder
134
     */
135
    public function scopeWithoutPages(Builder $builder, $pages): Builder
136
    {
137
        return $builder->whereDoesntHave('pages', function (Builder $builder) use ($pages) {
138
            $builder->whereIn('id', $pages);
139
        });
140
    }
141
142
    /**
143
     * Scope query without any pages.
144
     *
145
     * @param \Illuminate\Database\Eloquent\Builder $builder
146
     *
147
     * @return \Illuminate\Database\Eloquent\Builder
148
     */
149
    public function scopeWithoutAnyPages(Builder $builder): Builder
150
    {
151
        return $builder->doesntHave('pages');
152
    }
153
154
    /**
155
     * Determine if the model has any of the given pages.
156
     *
157
     * @param mixed $pages
158
     *
159
     * @return bool
160
     */
161
    public function hasAnyPages($pages): bool
162
    {
163
        return ! $this->pages->pluck('id')->intersect($pages)->isEmpty();
0 ignored issues
show
The property pages does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
164
    }
165
166
    /**
167
     * Determine if the model has all of the given pages.
168
     *
169
     * @param mixed $pages
170
     *
171
     * @return bool
172
     */
173
    public function hasAllPages($pages): bool
174
    {
175
        return collect($pages)->diff($this->pages->pluck('id'))->isEmpty();
176
    }
177
178
    /**
179
     * Attach model pages.
180
     *
181
     * @param mixed $pages
182
     *
183
     * @return $this
184
     */
185
    public function attachPages($pages)
186
    {
187
        // Use 'sync' not 'attach' to avoid Integrity constraint violation
188
        $this->pages()->sync($pages, false);
189
190
        return $this;
191
    }
192
193
    /**
194
     * Sync model pages.
195
     *
196
     * @param mixed $pages
197
     * @param bool  $detaching
198
     *
199
     * @return $this
200
     */
201
    public function syncPages($pages, bool $detaching = true)
202
    {
203
        $this->pages()->sync($pages, $detaching);
204
205
        return $this;
206
    }
207
208
    /**
209
     * Detach model pages.
210
     *
211
     * @param mixed $pages
212
     *
213
     * @return $this
214
     */
215
    public function detachPages($pages = null)
216
    {
217
        $this->pages()->detach($pages);
218
219
        return $this;
220
    }
221
}
222