Issues (4)

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/Helpers/ObjectHelper.php (1 issue)

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  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/skeleton/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/skeleton
7
 */
8
9
namespace Flipbox\Skeleton\Helpers;
10
11
use Flipbox\Skeleton\Exceptions\InvalidConfigurationException;
12
use Flipbox\Skeleton\Object\ObjectInterface;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 2.0.0
17
 */
18
class ObjectHelper
19
{
20
    /**
21
     * Returns the public member variables of an object.
22
     *
23
     * @param ObjectInterface $object
24
     * @return array
25
     */
26
    public static function getObjectVars(ObjectInterface $object)
27
    {
28
        return get_object_vars($object);
29
    }
30
31
    /**
32
     * Configures an object with the initial property values.
33
     *
34
     * @param ObjectInterface $object
35
     * @param $properties
36
     * @return ObjectInterface
37
     */
38
    public static function configure(ObjectInterface $object, $properties)
39
    {
40
        // Populate model attributes
41
        if (!empty($properties)) {
42
            // To array
43
            if (!is_array($properties)) {
44
                $properties = ArrayHelper::toArray($properties, [], false);
45
            }
46
47
            foreach ($properties as $name => $value) {
48
                if ($object->canSetProperty($name)) {
49
                    $object->$name = $value;
50
                }
51
            }
52
        }
53
        return $object;
54
    }
55
56
    /**
57
     * Create a new object
58
     *
59
     * @param $config
60
     * @param null $instanceOf
61
     * @return ObjectInterface
62
     * @throws InvalidConfigurationException
63
     */
64
    public static function create($config, $instanceOf = null)
65
    {
66
        // Get class from config
67
        $class = static::checkConfig($config, $instanceOf);
68
69
        // New object
70
        return new $class($config);
71
    }
72
73
    /**
74
     * Checks the config for a valid class
75
     *
76
     * @param $config
77
     * @param null $instanceOf
78
     * @param bool $removeClass
79
     * @return null|string
80
     * @throws InvalidConfigurationException
81
     */
82
    public static function checkConfig(&$config, $instanceOf = null, $removeClass = true)
83
    {
84
        // Get class from config
85
        $class = static::getClassFromConfig($config, $removeClass);
86
87
        // Make sure we have a valid class
88
        if ($instanceOf && !is_subclass_of($class, $instanceOf)) {
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if $instanceOf can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
89
            throw new InvalidConfigurationException(
90
                sprintf(
91
                    "The class '%s' must be an instance of '%s'",
92
                    (string)$class,
93
                    (string)$instanceOf
94
                )
95
            );
96
        }
97
98
        return $class;
99
    }
100
101
    /**
102
     * Get a class from a config
103
     *
104
     * @param $config
105
     * @param bool $removeClass
106
     * @return string
107
     * @throws InvalidConfigurationException
108
     */
109
    public static function getClassFromConfig(&$config, $removeClass = false)
110
    {
111
        // Find class
112
        $class = static::findClassFromConfig($config, $removeClass);
113
114
        if (empty($class)) {
115
            throw new InvalidConfigurationException(
116
                sprintf(
117
                    "The configuration must specify a 'class' property: '%s'",
118
                    JsonHelper::encode($config)
119
                )
120
            );
121
        }
122
123
        return $class;
124
    }
125
126
    /**
127
     * Find a class from a config
128
     *
129
     * @param $config
130
     * @param bool $removeClass
131
     * @return null|string
132
     */
133
    public static function findClassFromConfig(&$config, $removeClass = false)
134
    {
135
        // Normalize the config
136
        if (is_string($config)) {
137
            $class = $config;
138
            $config = '';
139
        } elseif (is_object($config)) {
140
            return get_class($config);
141
        } else {
142
            // Force Array
143
            if (!is_array($config)) {
144
                $config = ArrayHelper::toArray($config, [], false);
145
            }
146
            if ($removeClass) {
147
                if (!$class = ArrayHelper::remove($config, 'class')) {
148
                    $class = ArrayHelper::remove($config, 'type');
149
                }
150
            } else {
151
                $class = ArrayHelper::getValue(
152
                    $config,
153
                    'class',
154
                    ArrayHelper::getValue($config, 'type')
155
                );
156
            }
157
        }
158
        return $class;
159
    }
160
}
161