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

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\Matcher\CallableMatcher;
14
use Rafrsr\LibArray2Object\Matcher\CamelizeMatcher;
15
use Rafrsr\LibArray2Object\Matcher\IdenticalMatcher;
16
use Rafrsr\LibArray2Object\Matcher\LevenshteinMatcher;
17
use Rafrsr\LibArray2Object\Matcher\MapMatcher;
18
use Rafrsr\LibArray2Object\Traits\MatcherAwareTrait;
19
use Rafrsr\LibArray2Object\Writer\AccessorWriter;
20
use Rafrsr\LibArray2Object\Writer\PropertyWriterInterface;
21
use Rafrsr\LibArray2Object\Writer\ReflectionWriter;
22
23
/**
24
 * Class Array2ObjectBuilder.
25
 */
26
class Array2ObjectBuilder extends AbstractBuilder
27
{
28
    use MatcherAwareTrait;
29
30
    /**
31
     * @var PropertyWriterInterface
32
     */
33
    private $writer;
34
35
    /**
36
     * @return PropertyWriterInterface
37
     */
38
    public function getWriter()
39
    {
40
        return $this->writer;
41
    }
42
43
    /**
44
     * @param PropertyWriterInterface $writer
45
     *
46
     * @return $this
47
     */
48
    public function setWriter($writer)
49
    {
50
        $this->writer = $writer;
51
52
        return $this;
53
    }
54
55
    /**
56
     * Array keys and property names are identical.
57
     *
58
     * @return $this
59
     */
60
    public function useIdenticalMatcher()
61
    {
62
        $this->setMatcher(new IdenticalMatcher());
63
64
        return $this;
65
    }
66
67
    /**
68
     * Array keys and property names are compared using some property possible versions
69
     * e.g, propertyName => property_name.
70
     *
71
     * @return $this
72
     */
73
    public function useCamelizeMatcher()
74
    {
75
        $this->setMatcher(new CamelizeMatcher());
76
77
        return $this;
78
    }
79
80
    /**
81
     * Array keys and property names are compared using levenshtein algorithm to find similar strings.
82
     *
83
     * @return $this
84
     */
85
    public function useLevenshteinMatcher()
86
    {
87
        $this->setMatcher(new LevenshteinMatcher());
88
89
        return $this;
90
    }
91
92
    /**
93
     * Array keys and property names are compared using the given property and array key map.
94
     *
95
     * @param array $map
96
     *
97
     * @return $this
98
     */
99
    public function useMapMatcher(array $map)
100
    {
101
        $this->setMatcher(new MapMatcher($map));
102
103
        return $this;
104
    }
105
106
    /**
107
     * Array keys and property names are compared using custom function
108
     * the given function receive two parameters \ReflectionProperty $property, $givenName.
109
     *
110
     * @param callable $callback
111
     *
112
     * @return $this
113
     */
114
    public function useCallableMatcher(callable $callback)
115
    {
116
        $this->setMatcher(new CallableMatcher($callback));
117
118
        return $this;
119
    }
120
121
    /**
122
     * Write the property directly without use setters.
123
     *
124
     * @param bool $onlyPublicProperties only public properties should be exported
125
     *
126
     * @return $this
127
     */
128
    public function disableSetters($onlyPublicProperties = false)
129
    {
130
        $this->setWriter(new ReflectionWriter($onlyPublicProperties));
131
132
        return $this;
133
    }
134
135
    /**
136
     * Build custom Array2Object instance.
137
     */
138
    public function build()
139
    {
140
        if ($this->getContext()) {
141
            $context = $this->getContext();
142
        } else {
143
            $context = new Array2ObjectContext();
144
        }
145
146
        $this->prepareContext($context);
147
148
        return new Array2Object($context);
0 ignored issues
show
$context of type object<Rafrsr\LibArray2Object\AbstractContext> is not a sub-type of object<Rafrsr\LibArray2O...ct\Array2ObjectContext>. 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...
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154
    protected function prepareContext(AbstractContext $context)
155
    {
156
        parent::prepareContext($context);
157
158
        if ($context instanceof Array2ObjectContext) {
159
            $context->setWriter($this->getWriter() ?: new AccessorWriter());
160
            $context->setMatcher($this->getMatcher() ?: new CamelizeMatcher());
161
        }
162
    }
163
}
164