Issues (27)

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

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
 * This file is part of the rafrsr/lib-array2object package.
5
 *
6
 * (c) Rafael SR <https://github.com/rafrsr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Rafrsr\LibArray2Object;
12
13
use Rafrsr\LibArray2Object\Naming\CallableNamingStrategy;
14
use Rafrsr\LibArray2Object\Naming\CamelCaseNamingStrategy;
15
use Rafrsr\LibArray2Object\Naming\IdenticalNamingStrategy;
16
use Rafrsr\LibArray2Object\Naming\UnderscoreNamingStrategy;
17
use Rafrsr\LibArray2Object\Reader\AccessorReader;
18
use Rafrsr\LibArray2Object\Reader\PropertyReaderInterface;
19
use Rafrsr\LibArray2Object\Reader\ReflectionReader;
20
use Rafrsr\LibArray2Object\Traits\IgnoreNullsTrait;
21
use Rafrsr\LibArray2Object\Traits\NamingStrategyAwareTrait;
22
23
class Object2ArrayBuilder extends AbstractBuilder
24
{
25
    use NamingStrategyAwareTrait;
26
    use IgnoreNullsTrait;
27
28
    /**
29
     * @var PropertyReaderInterface
30
     */
31
    private $reader;
32
33
    /**
34
     * @return PropertyReaderInterface
35
     */
36
    public function getReader()
37
    {
38
        return $this->reader;
39
    }
40
41
    /**
42
     * @param PropertyReaderInterface $reader
43
     *
44
     * @return $this
45
     */
46
    public function setReader($reader)
47
    {
48
        $this->reader = $reader;
49
50
        return $this;
51
    }
52
53
    /**
54
     * Name array keys as "PropertyName".
55
     *
56
     * @return $this
57
     */
58
    public function useUcFirstCamelCaseNamingStrategy()
59
    {
60
        $this->setNamingStrategy(new CamelCaseNamingStrategy(true));
61
62
        return $this;
63
    }
64
65
    /**
66
     * Name array keys as "propertyName".
67
     *
68
     * @return $this
69
     */
70
    public function useCamelCaseNamingStrategy()
71
    {
72
        $this->setNamingStrategy(new CamelCaseNamingStrategy());
73
74
        return $this;
75
    }
76
77
    /**
78
     * Name array keys as "property_name".
79
     *
80
     * @return $this
81
     */
82
    public function useUnderScoreNamingStrategy()
83
    {
84
        $this->setNamingStrategy(new UnderscoreNamingStrategy());
85
86
        return $this;
87
    }
88
89
    /**
90
     * The array keys is identical to property name.
91
     *
92
     * @return $this
93
     */
94
    public function useIdenticalNamingStrategy()
95
    {
96
        $this->setNamingStrategy(new IdenticalNamingStrategy());
97
98
        return $this;
99
    }
100
101
    /**
102
     * Use given callback to transform the array key.
103
     *
104
     * @param callable $callback
105
     *
106
     * @return $this
107
     */
108
    public function useCallbackNamingStrategy(callable  $callback)
109
    {
110
        $this->setNamingStrategy(new CallableNamingStrategy($callback));
111
112
        return $this;
113
    }
114
115
    /**
116
     * Read the property directly without use getters.
117
     *
118
     * @param bool $onlyPublicProperties only public properties should be exported
119
     *
120
     * @return $this
121
     */
122
    public function disableGetters($onlyPublicProperties = false)
123
    {
124
        $this->setReader(new ReflectionReader($onlyPublicProperties));
125
126
        return $this;
127
    }
128
129
    /**
130
     * Build custom Array2Object instance.
131
     */
132
    public function build()
133
    {
134
        if ($this->getContext()) {
135
            $context = $this->getContext();
136
        } else {
137
            $context = new Object2ArrayContext();
138
        }
139
140
        $this->prepareContext($context);
141
142
        return new Object2Array($context);
0 ignored issues
show
$context of type object<Rafrsr\LibArray2Object\AbstractContext> is not a sub-type of object<Rafrsr\LibArray2O...ct\Object2ArrayContext>. It seems like you assume a child class of the class Rafrsr\LibArray2Object\AbstractContext to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148
    protected function prepareContext(AbstractContext $context)
149
    {
150
        parent::prepareContext($context);
151
152
        if ($context instanceof Object2ArrayContext) {
153
            $context->setIgnoreNulls($this->isIgnoreNulls());
154
            $context->setReader($this->getReader() ?: new AccessorReader());
155
            $context->setNamingStrategy($this->getNamingStrategy() ?: new CamelCaseNamingStrategy());
156
        }
157
    }
158
}
159