Issues (2)

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/CascadeSoftDeletes.php (2 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 Iatstuti\Database\Support;
4
5
use LogicException;
6
use Illuminate\Support\Str;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
9
use Illuminate\Database\Eloquent\Relations\Relation;
10
11
trait CascadeSoftDeletes
12
{
13
    /**
14
     * Boot the trait.
15
     *
16
     * Listen for the deleting event of a soft deleting model, and run
17
     * the delete operation for any configured relationship methods.
18
     *
19 10
     * @throws \LogicException
20
     */
21
    protected static function bootCascadeSoftDeletes()
22 10
    {
23 1
        static::deleting(function ($model) {
24 1
            $model->validateCascadingSoftDelete();
25 1
26 1
            $model->runCascadingDeletes();
27
        });
28
    }
29 9
30 3
31 3
    /**
32 3
     * Validate that the calling model is correctly setup for cascading soft deletes.
33 3
     *
34 3
     * @throws \Iatstuti\Database\Support\CascadeSoftDeleteException
35
     */
36
    protected function validateCascadingSoftDelete()
37 6
    {
38
        if (! $this->implementsSoftDeletes()) {
39 6
            throw CascadeSoftDeleteException::softDeleteNotImplemented(get_called_class());
40 6
        }
41 1
42 1
        if ($invalidCascadingRelationships = $this->hasInvalidCascadingRelationships()) {
43 6
            throw CascadeSoftDeleteException::invalidRelationships($invalidCascadingRelationships);
44 5
        }
45 6
    }
46
47 6
48 9
    /**
49 7
     * Run the cascading soft delete for this model.
50
     *
51
     * @return void
52
     */
53
    protected function runCascadingDeletes()
54
    {
55
        foreach ($this->getActiveCascadingDeletes() as $relationship) {
56
            $this->cascadeSoftDeletes($relationship);
57 10
        }
58
    }
59 10
60
61
    /**
62
     * Cascade delete the given relationship on the given mode.
63
     *
64
     * @param  string  $relationship
65
     * @return return
0 ignored issues
show
Should the return type not be return|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
66
     */
67
    protected function cascadeSoftDeletes($relationship)
68
    {
69
        $delete = $this->forceDeleting ? 'forceDelete' : 'delete';
0 ignored issues
show
The property forceDeleting 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...
70
71 9
        foreach ($this->{$relationship}()->get() as $model) {
72
            $model->pivot ? $model->pivot->{$delete}() : $model->{$delete}();
73
        }
74 9
    }
75 9
76
77
    /**
78
     * Determine if the current model implements soft deletes.
79
     *
80
     * @return bool
81
     */
82
    protected function implementsSoftDeletes()
83
    {
84 9
        return method_exists($this, 'runSoftDelete');
85
    }
86 9
87
88
    /**
89
     * Determine if the current model has any invalid cascading relationships defined.
90
     *
91
     * A relationship is considered invalid when the method does not exist, or the relationship
92
     * method does not return an instance of Illuminate\Database\Eloquent\Relations\Relation.
93
     *
94
     * @return array
95
     */
96
    protected function hasInvalidCascadingRelationships()
97 6
    {
98 6
        return array_filter($this->getCascadingDeletes(), function ($relationship) {
99 6
            return ! method_exists($this, $relationship) || ! $this->{$relationship}() instanceof Relation;
100
        });
101
    }
102
103
104
    /**
105
     * Fetch the defined cascading soft deletes for this model.
106
     *
107
     * @return array
108
     */
109
    protected function getCascadingDeletes()
110
    {
111
        return isset($this->cascadeDeletes) ? (array) $this->cascadeDeletes : [];
112
    }
113
114
115
    /**
116
     * For the cascading deletes defined on the model, return only those that are not null.
117
     *
118
     * @return array
119
     */
120
    protected function getActiveCascadingDeletes()
121
    {
122
        return array_filter($this->getCascadingDeletes(), function ($relationship) {
123
            return ! is_null($this->{$relationship});
124
        });
125
    }
126
}
127