Issues (47)

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/Hydrator/ObjectProperty.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 Marek\Toggable\Hydrator;
4
5
use ReflectionClass;
6
use ReflectionProperty;
7
use ArrayObject;
8
use BadMethodCallException;
9
10
/**
11
 * Class ObjectProperty
12
 * @package Marek\Toggable\Hydrator
13
 */
14
class ObjectProperty implements HydratorInterface, StrategyEnabledInterface
15
{
16
    /**
17
    * The list with strategies that this hydrator has.
18
    *
19
    * @var \ArrayObject
20
    */
21
    protected $strategies;
22
23
    /**
24
     * ObjectProperty constructor.
25
     */
26 71
    public function __construct()
27
    {
28 71
        $this->strategies = new ArrayObject();
29 71
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 14
    public function extract($object)
35
    {
36 14
        if (!is_object($object)) {
37 1
            throw new BadMethodCallException(
38 1
                sprintf('%s expects the provided $object to be a PHP object)', __METHOD__)
39 1
            );
40
        }
41
42 13
        $properties = $this->getObjectProperties($object);
43
44 13
        $data = array();
45 13
        foreach ($properties as $name => $value) {
46
47 13
            if (!empty($object->$name) || $object->$name === false) {
48 13
                $data[$name] = $this->extractValue($name, $object->$name);
49 13
            }
50
51 13
        }
52
53 13
        return $data;
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59 14
    public function hydrate(array $data, $object)
60
    {
61 14
        if (!is_object($object)) {
62 1
            throw new BadMethodCallException(
63 1
                sprintf('%s expects the provided $object to be a PHP object)', __METHOD__)
64 1
            );
65
        }
66
67 13
        $props = $this->getObjectProperties($object);
68
69 13
        foreach ($data as $name => $value) {
70
71 13
            if (!isset($props[$name])) {
72 1
                continue;
73
            }
74
75 13
            $object->$name = $this->hydrateValue($name, $value);
76 13
        }
77
78 13
        return $object;
79
    }
80
81
    /**
82
     * @inheritDoc
83
     */
84 1
    public function canHydrate($object)
85
    {
86 1
        return true;
87
    }
88
89
    /**
90
     * @inheritDoc
91
     */
92 66
    public function addStrategy($name, StrategyInterface $strategy)
93
    {
94 66
        $this->strategies[$name] = $strategy;
95
96 66
        return $this;
97
    }
98
99
    /**
100
     * @inheritDoc
101
     */
102 21
    public function getStrategy($name)
103
    {
104 21
        return $this->strategies[$name];
105
    }
106
107
    /**
108
     * @inheritDoc
109
     */
110 29
    public function hasStrategy($name)
111
    {
112 29
        return array_key_exists($name, $this->strategies);
113
    }
114
115
    /**
116
     * @inheritDoc
117
     */
118 1
    public function removeStrategy($name)
119
    {
120 1
        unset($this->strategies[$name]);
121
122 1
        return $this;
123
    }
124
125
    /**
126
     * Converts a value for extraction. If no strategy exists the plain value is returned.
127
     *
128
     * @param string $name
129
     * @param mixed $value
130
     *
131
     * @return mixed
132
     */
133 13 View Code Duplication
    public function extractValue($name, $value)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
    {
135 13
        if ($this->hasStrategy($name)) {
136 10
            $strategy = $this->getStrategy($name);
137 10
            $value = $strategy->extract($value);
138 10
        }
139
140 13
        return $value;
141
    }
142
143
    /**
144
     * Converts a value for hydration. If no strategy exists the plain value is returned.
145
     *
146
     * @param string $name
147
     * @param mixed $value
148
     *
149
     * @return mixed
150
     */
151 13 View Code Duplication
    public function hydrateValue($name, $value)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153 13
        if ($this->hasStrategy($name)) {
154 10
            $strategy = $this->getStrategy($name);
155 10
            $value = $strategy->hydrate($value);
156 10
        }
157
158 13
        return $value;
159
    }
160
161
    /**
162
     * Return list of object properties
163
     *
164
     * @param object $object
165
     *
166
     * @return array
167
     */
168 26
    protected function getObjectProperties($object)
169
    {
170 26
        $reflection = new ReflectionClass($object);
171
172 26
        $properties = $reflection->getProperties(
173
            ReflectionProperty::IS_PRIVATE
174 26
            + ReflectionProperty::IS_PROTECTED
175 26
        );
176
177 26
        $props = array();
178
        /** @var ReflectionProperty $property */
179 26
        foreach ($properties as $property) {
180 26
            $props[$property->getName()] = true;
181 26
        }
182
183 26
        return $props;
184
    }
185
}
186