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.

Platfourm/Database/Eloquent/Traits/SoftDeletes.php (17 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
 * 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 Longman\Platfourm\Contracts\Auth\AuthUserService;
14
15
trait SoftDeletes
16
{
17
    /**
18
     * Indicates if the model is currently force deleting.
19
     *
20
     * @var bool
21
     */
22
    protected $forceDeleting = false;
23
24
    /**
25
     * Boot the soft deleting trait for a model.
26
     *
27
     * @return void
28
     */
29
    public static function bootSoftDeletes()
30
    {
31
        static::addGlobalScope(new SoftDeletingScope);
32
    }
33
34
    /**
35
     * Force a hard delete on a soft deleted model.
36
     *
37
     * @return bool|null
38
     */
39
    public function forceDelete()
40
    {
41
        $this->forceDeleting = true;
42
43
        $deleted = $this->delete();
0 ignored issues
show
The method delete() does not exist on Longman\Platfourm\Databa...uent\Traits\SoftDeletes. Did you maybe mean bootSoftDeletes()?

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...
44
45
        $this->forceDeleting = false;
46
47
        return $deleted;
48
    }
49
50
    /**
51
     * Perform the actual delete query on this model instance.
52
     *
53
     * @return mixed
54
     */
55
    protected function performDeleteOnModel()
56
    {
57
        if ($this->forceDeleting) {
58
            return $this->newQueryWithoutScopes()->where($this->getKeyName(), $this->getKey())->forceDelete();
0 ignored issues
show
It seems like newQueryWithoutScopes() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
It seems like getKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
59
        }
60
61
        return $this->runSoftDelete();
62
    }
63
64
    /**
65
     * Perform the actual delete query on this model instance.
66
     *
67
     * @return void
68
     */
69
    protected function runSoftDelete()
70
    {
71
        $query = $this->newQueryWithoutScopes()->where($this->getKeyName(), $this->getKey());
0 ignored issues
show
It seems like newQueryWithoutScopes() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
It seems like getKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
72
73
        $this->{$this->getDeletedAtColumn()} = $time = $this->freshTimestamp();
0 ignored issues
show
It seems like freshTimestamp() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
74
75
        $update = [
76
            $this->getDeletedAtColumn() => $this->fromDateTime($time),
0 ignored issues
show
It seems like fromDateTime() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
77
        ];
78
79
        $userService = app()->make(AuthUserService::class);
80
        if ($userService->check()) {
81
            $this->{$this->getDeletedByColumn()} = $userService->user()->id;
82
            $update[$this->getDeletedByColumn()] = $userService->user()->id;
83
        }
84
85
        $query->update($update);
86
    }
87
88
    /**
89
     * Restore a soft-deleted model instance.
90
     *
91
     * @return bool|null
92
     */
93
    public function restore()
94
    {
95
        // If the restoring event does not return false, we will proceed with this
96
        // restore operation. Otherwise, we bail out so the developer will stop
97
        // the restore totally. We will clear the deleted timestamp and save.
98
        if ($this->fireModelEvent('restoring') === false) {
0 ignored issues
show
It seems like fireModelEvent() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
99
            return false;
100
        }
101
102
        $this->{$this->getDeletedAtColumn()} = null;
103
        $this->{$this->getDeletedByColumn()} = null;
104
105
        // Once we have saved the model, we will fire the "restored" event so this
106
        // developer will do anything they need to after a restore operation is
107
        // totally finished. Then we will return the result of the save call.
108
        $this->exists = true;
0 ignored issues
show
The property exists 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...
109
110
        $result = $this->save();
0 ignored issues
show
It seems like save() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
111
112
        $this->fireModelEvent('restored', false);
0 ignored issues
show
It seems like fireModelEvent() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
113
114
        return $result;
115
    }
116
117
    /**
118
     * Determine if the model instance has been soft-deleted.
119
     *
120
     * @return bool
121
     */
122
    public function trashed()
123
    {
124
        return !is_null($this->{$this->getDeletedAtColumn()});
125
    }
126
127
    /**
128
     * Get a new query builder that includes soft deletes.
129
     *
130
     * @return \Illuminate\Database\Eloquent\Builder|static
131
     */
132
    public static function withTrashed()
133
    {
134
        return (new static)->newQueryWithoutScope(new SoftDeletingScope);
0 ignored issues
show
It seems like newQueryWithoutScope() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
135
    }
136
137
    /**
138
     * Get a new query builder that only includes soft deletes.
139
     *
140
     * @return \Illuminate\Database\Eloquent\Builder|static
141
     */
142
    public static function onlyTrashed()
143
    {
144
        $instance = new static;
145
146
        $column = $instance->getQualifiedDeletedAtColumn();
147
148
        return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column);
0 ignored issues
show
It seems like newQueryWithoutScope() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
149
    }
150
151
    /**
152
     * Register a restoring model event with the dispatcher.
153
     *
154
     * @param  \Closure|string $callback
155
     * @return void
156
     */
157
    public static function restoring($callback)
158
    {
159
        static::registerModelEvent('restoring', $callback);
160
    }
161
162
    /**
163
     * Register a restored model event with the dispatcher.
164
     *
165
     * @param  \Closure|string $callback
166
     * @return void
167
     */
168
    public static function restored($callback)
169
    {
170
        static::registerModelEvent('restored', $callback);
171
    }
172
173
    /**
174
     * Get the name of the "deleted at" column.
175
     *
176
     * @return string
177
     */
178
    public function getDeletedAtColumn()
179
    {
180
        return defined('static::DELETED_AT') ? static::DELETED_AT : 'deleted_at';
181
    }
182
183
    /**
184
     * Get the name of the "deleted by" column.
185
     *
186
     * @return string
187
     */
188
    public function getDeletedByColumn()
189
    {
190
        return defined('static::DELETED_BY') ? static::DELETED_BY : 'deleted_by';
191
    }
192
193
    /**
194
     * Get the fully qualified "deleted at" column.
195
     *
196
     * @return string
197
     */
198
    public function getQualifiedDeletedAtColumn()
199
    {
200
        return $this->getTable() . '.' . $this->getDeletedAtColumn();
0 ignored issues
show
It seems like getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
201
    }
202
203
    /**
204
     * Get the fully qualified "deleted by" column.
205
     *
206
     * @return string
207
     */
208
    public function getQualifiedDeletedByColumn()
209
    {
210
        return $this->getTable() . '.' . $this->getDeletedByColumn();
0 ignored issues
show
It seems like getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
211
    }
212
213
}
214