Issues (247)

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.

Database/Eloquent/Traits/SoftDeletingScope.php (7 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
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Database\Eloquent\Traits;
12
13
use Illuminate\Database\Eloquent\Builder;
14
use Illuminate\Database\Eloquent\Model;
15
use Illuminate\Database\Eloquent\Scope;
16
use Longman\Platfourm\Contracts\Auth\AuthUserService;
17
18
class SoftDeletingScope implements Scope
19
{
20
    /**
21
     * All of the extensions to be added to the builder.
22
     *
23
     * @var array
24
     */
25
    protected $extensions = ['ForceDelete', 'Restore', 'WithTrashed', 'OnlyTrashed'];
26
27
    /**
28
     * Apply the scope to a given Eloquent query builder.
29
     *
30
     * @param  \Illuminate\Database\Eloquent\Builder $builder
31
     * @param  \Illuminate\Database\Eloquent\Model   $model
32
     * @return void
33
     */
34
    public function apply(Builder $builder, Model $model)
35
    {
36
        $builder->whereNull($model->getQualifiedDeletedAtColumn());
0 ignored issues
show
The method getQualifiedDeletedAtColumn() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean delete()?

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...
37
    }
38
39
    /**
40
     * Extend the query builder with the needed functions.
41
     *
42
     * @param  \Illuminate\Database\Eloquent\Builder $builder
43
     * @return void
44
     */
45
    public function extend(Builder $builder)
46
    {
47
        foreach ($this->extensions as $extension) {
48
            $this->{"add{$extension}"}($builder);
49
        }
50
51
        $builder->onDelete(function (Builder $builder) {
52
53
            $update = [
54
                $this->getDeletedAtColumn($builder) => $builder->getModel()->freshTimestampString(),
55
            ];
56
57
            $userService = app()->make(AuthUserService::class);
58
            if ($userService->check()) {
59
                $update[$this->getDeletedByColumn($builder)] = $userService->user()->id;
60
            }
61
62
            return $builder->update($update);
63
        });
64
    }
65
66
    /**
67
     * Get the "deleted at" column for the builder.
68
     *
69
     * @param  \Illuminate\Database\Eloquent\Builder $builder
70
     * @return string
71
     */
72
    protected function getDeletedAtColumn(Builder $builder)
73
    {
74
        if (count($builder->getQuery()->joins) > 0) {
75
            return $builder->getModel()->getQualifiedDeletedAtColumn();
0 ignored issues
show
The method getQualifiedDeletedAtColumn() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean delete()?

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...
76
        } else {
77
            return $builder->getModel()->getDeletedAtColumn();
0 ignored issues
show
The method getDeletedAtColumn() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean delete()?

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...
78
        }
79
    }
80
81
    /**
82
     * Get the "deleted by" column for the builder.
83
     *
84
     * @param  \Illuminate\Database\Eloquent\Builder $builder
85
     * @return string
86
     */
87
    protected function getDeletedByColumn(Builder $builder)
88
    {
89
        if (count($builder->getQuery()->joins) > 0) {
90
            return $builder->getModel()->getQualifiedDeletedByColumn();
0 ignored issues
show
The method getQualifiedDeletedByColumn() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean delete()?

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...
91
        } else {
92
            return $builder->getModel()->getDeletedByColumn();
0 ignored issues
show
The method getDeletedByColumn() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean delete()?

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...
93
        }
94
    }
95
96
    /**
97
     * Add the force delete extension to the builder.
98
     *
99
     * @param  \Illuminate\Database\Eloquent\Builder $builder
100
     * @return void
101
     */
102
    protected function addForceDelete(Builder $builder)
103
    {
104
        $builder->macro('forceDelete', function (Builder $builder) {
105
            return $builder->getQuery()->delete();
106
        });
107
    }
108
109
    /**
110
     * Add the restore extension to the builder.
111
     *
112
     * @param  \Illuminate\Database\Eloquent\Builder $builder
113
     * @return void
114
     */
115
    protected function addRestore(Builder $builder)
116
    {
117
        $builder->macro('restore', function (Builder $builder) {
118
            $builder->withTrashed();
119
120
            return $builder->update([$builder->getModel()->getDeletedAtColumn() => null]);
0 ignored issues
show
The method getDeletedAtColumn() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean delete()?

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...
121
        });
122
    }
123
124
    /**
125
     * Add the with-trashed extension to the builder.
126
     *
127
     * @param  \Illuminate\Database\Eloquent\Builder $builder
128
     * @return void
129
     */
130
    protected function addWithTrashed(Builder $builder)
131
    {
132
        $builder->macro('withTrashed', function (Builder $builder) {
133
            return $builder->withoutGlobalScope($this);
134
        });
135
    }
136
137
    /**
138
     * Add the only-trashed extension to the builder.
139
     *
140
     * @param  \Illuminate\Database\Eloquent\Builder $builder
141
     * @return void
142
     */
143
    protected function addOnlyTrashed(Builder $builder)
144
    {
145
        $builder->macro('onlyTrashed', function (Builder $builder) {
146
            $model = $builder->getModel();
147
148
            $builder->withoutGlobalScope($this)->whereNotNull(
149
                $model->getQualifiedDeletedAtColumn()
0 ignored issues
show
The method getQualifiedDeletedAtColumn() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean delete()?

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...
150
            );
151
152
            return $builder;
153
        });
154
    }
155
}
156