Issues (5)

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/Editors/MergeIntoAssignable.php (2 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
/**
4
 * Copyright (c) 2015-present Ganbaro Digital Ltd
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 *   * Redistributions of source code must retain the above copyright
12
 *     notice, this list of conditions and the following disclaimer.
13
 *
14
 *   * Redistributions in binary form must reproduce the above copyright
15
 *     notice, this list of conditions and the following disclaimer in
16
 *     the documentation and/or other materials provided with the
17
 *     distribution.
18
 *
19
 *   * Neither the names of the copyright holders nor the names of his
20
 *     contributors may be used to endorse or promote products derived
21
 *     from this software without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 * POSSIBILITY OF SUCH DAMAGE.
35
 *
36
 * @category  Libraries
37
 * @package   DataContainers/Editors
38
 * @author    Stuart Herbert <[email protected]>
39
 * @copyright 2011-present Mediasift Ltd www.datasift.com
40
 * @copyright 2015-present Ganbaro Digital Ltd www.ganbarodigital.com
41
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
42
 * @link      http://code.ganbarodigital.com/php-data-containers
43
 */
44
45
namespace GanbaroDigital\DataContainers\Editors;
46
47
use Traversable;
48
use GanbaroDigital\DataContainers\Containers\DataBag;
49
use GanbaroDigital\DataContainers\Exceptions\E4xx_UnsupportedType;
50
use GanbaroDigital\DataContainers\Internal\Checks\ShouldOverwrite;
51
use GanbaroDigital\Reflection\Checks\IsAssignable;
52
use GanbaroDigital\Reflection\Checks\IsIndexable;
53
use GanbaroDigital\Reflection\Checks\IsTraversable;
54
use GanbaroDigital\Reflection\Requirements\RequireAssignable;
55
use GanbaroDigital\Reflection\Requirements\RequireTraversable;
56
use GanbaroDigital\Reflection\ValueBuilders\FirstMethodMatchingType;
57
use GanbaroDigital\Reflection\ValueBuilders\SimpleType;
58
59
class MergeIntoAssignable
60
{
61
    /**
62
     * merge their array into our object
63
     *
64
     * @param  object $ours
65
     *         the object that we want to merge into
66
     * @param  array|Traversable $theirs
67
     *         the array that we want to merge from
68
     * @return void
69
     */
70
    public static function fromArray($ours, $theirs)
71
    {
72
        // robustness!
73
        RequireAssignable::check($ours, E4xx_UnsupportedType::class);
74
        RequireTraversable::check($theirs, E4xx_UnsupportedType::class);
75
76
        // copy from them to us
77
        foreach ($theirs as $key => $value) {
78
            self::mergeKeyIntoAssignable($ours, $key, $value);
79
        }
80
81
        // all done
82
    }
83
84
    /**
85
     * merge a single key into our object
86
     *
87
     * @param  object $ours
88
     *         the object to merge into
89
     * @param  mixed $key
90
     *         the array key to merge into
91
     * @param  mixed $value
92
     *         the data to merge in
93
     * @return void
94
     */
95
    private static function mergeKeyIntoAssignable($ours, $key, $value)
96
    {
97
        // general case - overwrite because merging isn't possible
98
        if (ShouldOverwrite::intoObject($ours, $key, $value)) {
99
            $ours->$key = $value;
100
            return;
101
        }
102
103
        // special case - we are merging into an array
104
        if (IsIndexable::check($ours->$key)) {
105
            MergeIntoIndexable::from($ours->$key, $value);
106
            return;
107
        }
108
109
        // at this point, we are merging into an object, using recursion
110
        // for which I am going to hell
111
        MergeIntoAssignable::from($ours->$key, $value);
112
    }
113
114
    /**
115
     * merge their object into our object
116
     *
117
     * @param  object $ours
118
     *         the object that we want to merge into
119
     * @param  object $theirs
120
     *         the object that we want to merge from
121
     * @return void
122
     */
123
    public static function fromObject($ours, $theirs)
124
    {
125
        // robustness!
126
        RequireAssignable::check($theirs, E4xx_UnsupportedType::class);
127
        self::fromArray($ours, get_object_vars($theirs));
128
    }
129
130
    /**
131
     * merge their data into our object
132
     *
133
     * @param  object $ours
134
     *         the object that we want to merge into
135
     * @param  array|object $theirs
136
     *         the data that we want to merge from
137
     * @return void
138
     */
139
    public static function from($ours, $theirs)
140
    {
141
        if (IsAssignable::check($theirs)) {
142
            return self::fromObject($ours, $theirs);
0 ignored issues
show
It seems like $theirs defined by parameter $theirs on line 139 can also be of type array; however, GanbaroDigital\DataConta...ssignable::fromObject() does only seem to accept object, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
143
        }
144
145
        if (IsTraversable::check($theirs)) {
146
            return self::fromArray($ours, $theirs);
0 ignored issues
show
It seems like $theirs defined by parameter $theirs on line 139 can also be of type object; however, GanbaroDigital\DataConta...Assignable::fromArray() does only seem to accept array|object<Traversable>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
147
        }
148
149
        // cannot merge anything that reaches here!
150
        throw new E4xx_UnsupportedType(SimpleType::from($ours));
151
    }
152
153
    /**
154
     * merge their data into our object
155
     *
156
     * @deprecated since 2.2.0
157
     * @codeCoverageIgnore
158
     *
159
     * @param  object $ours
160
     *         the object that we want to merge into
161
     * @param  array|object $theirs
162
     *         the data that we want to merge from
163
     * @return void
164
     */
165
    public static function fromMixed($ours, $theirs)
166
    {
167
        return self::from($ours, $theirs);
168
    }
169
170
    /**
171
     * merge their data into our object
172
     *
173
     * @param  object $ours
174
     *         the object that we want to merge into
175
     * @param  array|object $theirs
176
     *         the data that we want to merge from
177
     * @return void
178
     */
179
    public function __invoke($ours, $theirs)
180
    {
181
        return self::from($ours, $theirs);
182
    }
183
}