Issues (126)

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/Db/Entity/Tracking.php (9 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
declare(strict_types=1);
3
/**
4
 * Minotaur
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
 * use this file except in compliance with the License. You may obtain a copy of
8
 * the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 * License for the specific language governing permissions and limitations under
16
 * the License.
17
 *
18
 * @copyright 2015-2017 Appertly
19
 * @license   Apache-2.0
20
 */
21
namespace Minotaur\Db\Entity;
22
23
/**
24
 * A trait for entities which can track changes.
25
 */
26
trait Tracking
27
{
28
    /**
29
     * @var array<string,array<string,mixed>> Changes to persist.
30
     */
31
    protected $changes = [];
32
33
    /**
34
     * Gets the pending changes.
35
     *
36
     * @return array<string,array<string,mixed>> The pending changes
37
     */
38
    public function getChanges(): array
39
    {
40
        return $this->changes;
41
    }
42
43
    /**
44
     * Whether the object has any changes.
45
     *
46
     * @return - Whether the object has any changes
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
47
     */
48
    public function isDirty(): bool
49
    {
50
        return !empty($this->changes);
51
    }
52
53
    /**
54
     * Sets a field for update.
55
     *
56
     * @param $field - The field name
57
     * @param $value - The field value
58
     * @return - provides a fluent interface
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
59
     */
60
    protected function fieldSet(string $field, $value): self
61
    {
62
        if (!array_key_exists('$set', $this->changes)) {
63
            $this->changes['$set'] = [];
64
        }
65
        $this->changes['$set'][$field] = $value;
66
        return $this;
67
    }
68
69
    /**
70
     * Sets a field for removal.
71
     *
72
     * @param $field - The field name
73
     * @return - provides a fluent interface
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
74
     */
75
    protected function fieldUnset(string $field): self
76
    {
77
        if (!array_key_exists('$unset', $this->changes)) {
78
            $this->changes['$unset'] = [];
79
        }
80
        $this->changes['$unset'][$field] = '';
81
        return $this;
82
    }
83
84
    /**
85
     * Sets a field for increment.
86
     *
87
     * @param $field - The field name
88
     * @param $value - Optional. The increment value. Default is `1`.
89
     * @return - provides a fluent interface
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
90
     */
91
    protected function fieldIncrement(string $field, int $value = 1): self
92
    {
93
        if (!array_key_exists('$inc', $this->changes)) {
94
            $this->changes['$inc'] = [];
95
        }
96
        $this->changes['$inc'][$field] = $value;
97
        return $this;
98
    }
99
100
    /**
101
     * Sets a field to the current date.
102
     *
103
     * @param $field - The field name
104
     * @return - provides a fluent interface
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
105
     */
106
    protected function fieldNow(string $field): self
107
    {
108
        if (!array_key_exists('$currentDate', $this->changes)) {
109
            $this->changes['$currentDate'] = [];
110
        }
111
        $this->changes['$currentDate'][$field] = true;
112
        return $this;
113
    }
114
115
    /**
116
     * Pushes a value onto a field.
117
     *
118
     * @param $field - The field name
119
     * @param $value - The value to push
120
     * @return - provides a fluent interface
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
121
     */
122
    protected function fieldPush(string $field, $value): self
123
    {
124
        if (!array_key_exists('$push', $this->changes)) {
125
            $this->changes['$push'] = [];
126
        }
127
        $this->changes['$push'][$field] = $value;
128
        return $this;
129
    }
130
131
    /**
132
     * Pushes a value onto an array field.
133
     *
134
     * @param $field - The field name
135
     * @param $value - The values to push
136
     * @return - provides a fluent interface
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
137
     */
138
    protected function fieldPushAll(string $field, iterable $value): self
139
    {
140
        if (!array_key_exists('$push', $this->changes)) {
141
            $this->changes['$push'] = [];
142
        }
143
        $this->changes['$push'][$field] = ['$each' => is_array($value) ? $value : iterator_to_array($value, false)];
144
        return $this;
145
    }
146
147
    /**
148
     * Pulls a value from a array field.
149
     *
150
     * In addition to a single value, you can also specify a query document.
151
     * ```
152
     * $this->fieldPull('vegetables', 'carrot');
153
     * $this->fieldPull('listOfDocs', ['foo' => 'bar']);
154
     * ```
155
     *
156
     * @param $field - The field name
157
     * @param $value - The value to pull
158
     * @return - provides a fluent interface
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
159
     */
160
    protected function fieldPull(string $field, $value): self
161
    {
162
        if (!array_key_exists('$pull', $this->changes)) {
163
            $this->changes['$pull'] = [];
164
        }
165
        $this->changes['$pull'][$field] = $value;
166
        return $this;
167
    }
168
169
    /**
170
     * Takes all the changes from a `Modifiable` and copies them under a field name.
171
     *
172
     * @param $child - The object containing updates
173
     * @param $field - The field name
174
     * @return - provides a fluent interface
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
175
     */
176
    protected function aggregateChanges(Modifiable $child, string $field): self
177
    {
178
        foreach ($child->getChanges() as $op => $sets) {
179
            if (!array_key_exists($op, $this->changes)) {
180
                $this->changes[$op] = [];
181
            }
182
            foreach ($sets as $k => $v) {
183
                $this->changes[$op]["$field.$k"] = $v;
184
            }
185
        }
186
        return $this;
187
    }
188
}
189