Issues (18)

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/Converter/IteratableToNodeConverter.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
declare(strict_types=1);
4
5
namespace Saxulum\ElasticSearchQueryBuilder\Converter;
6
7
use Saxulum\ElasticSearchQueryBuilder\Node\AbstractNode;
8
use Saxulum\ElasticSearchQueryBuilder\Node\AbstractParentNode;
9
use Saxulum\ElasticSearchQueryBuilder\Node\ArrayNode;
10
use Saxulum\ElasticSearchQueryBuilder\Node\ObjectNode;
11
12
final class IteratableToNodeConverter implements IteratableToNodeConverterInterface
13
{
14
    /**
15
     * @var ScalarToNodeConverterInterface
16
     */
17
    private $scalarToNodeConverter;
18
19
    /**
20
     * @param ScalarToNodeConverterInterface $scalarToNodeConverter
21
     */
22 4
    public function __construct(ScalarToNodeConverterInterface $scalarToNodeConverter)
23
    {
24 4
        $this->scalarToNodeConverter = $scalarToNodeConverter;
25 4
    }
26
27
    /**
28
     * @param array|\Traversable $data
29
     * @param string             $path
30
     * @param bool               $allowSerializeEmpty
31
     *
32
     * @return AbstractParentNode
33
     *
34
     * @throws \InvalidArgumentException
35
     */
36 4
    public function convert($data, string $path = '', bool $allowSerializeEmpty = false): AbstractParentNode
37
    {
38 4
        if (!is_array($data) && !$data instanceof \Traversable) {
39 1
            throw new \InvalidArgumentException(sprintf('Params need to be array or %s', \Traversable::class));
40
        }
41
42 3
        $isArray = $this->isArray($data);
43 3
        $parentNode = $this->getParentNode($isArray, $allowSerializeEmpty);
44
45 3
        foreach ($data as $key => $value) {
46 3
            $this->addChildNode($parentNode, $key, $value, $path, $isArray, $allowSerializeEmpty);
47
        }
48
49 2
        return $parentNode;
50
    }
51
52
    /**
53
     * @param array|\Traversable $data
54
     *
55
     * @return bool
56
     */
57 3
    private function isArray($data): bool
58
    {
59 3
        $counter = 0;
60 3
        foreach ($data as $key => $value) {
61 3
            if ($key !== $counter) {
62 3
                return false;
63
            }
64
65 2
            ++$counter;
66
        }
67
68 3
        return true;
69
    }
70
71
    /**
72
     * @param bool $isArray
73
     * @param bool $allowSerializeEmpty
74
     *
75
     * @return AbstractParentNode
76
     */
77 3
    private function getParentNode(bool $isArray, bool $allowSerializeEmpty): AbstractParentNode
78
    {
79 3
        if ($isArray) {
80 3
            return ArrayNode::create($allowSerializeEmpty);
81
        }
82
83 3
        return ObjectNode::create($allowSerializeEmpty);
84
    }
85
86
    /**
87
     * @param AbstractParentNode $parentNode
88
     * @param int|string         $key
89
     * @param mixed              $value
90
     * @param string             $path
91
     * @param bool               $isArray
92
     * @param bool               $allowSerializeEmpty
93
     */
94 3
    private function addChildNode(
95
        AbstractParentNode $parentNode,
96
        $key,
97
        $value,
98
        string $path,
99
        bool $isArray,
100
        bool $allowSerializeEmpty
101
    ) {
102 3
        $subPath = $this->getSubPath($path, $key, $isArray);
103 3
        $node = $this->getNode($value, $subPath, $allowSerializeEmpty);
104
105 2
        if ($isArray) {
106 1
            $parentNode->add($node);
107
        } else {
108 2
            $parentNode->add((string) $key, $node);
109
        }
110 2
    }
111
112
    /**
113
     * @param string     $path
114
     * @param string|int $key
115
     * @param bool       $isArray
116
     *
117
     * @return string
118
     */
119 3
    private function getSubPath(string $path, $key, bool $isArray): string
120
    {
121 3
        $key = (string) $key;
122
123 3
        if ($isArray) {
124 2
            return $path.'['.$key.']';
125
        }
126
127 3
        return '' !== $path ? $path.'.'.$key : $key;
128
    }
129
130
    /**
131
     * @param mixed  $value
132
     * @param string $path
133
     * @param bool   $allowSerializeEmpty
134
     *
135
     * @return AbstractNode
136
     */
137 3
    private function getNode($value, string $path, bool $allowSerializeEmpty): AbstractNode
138
    {
139 3
        if (is_array($value) || $value instanceof \Traversable) {
140 3
            return $this->convert($value, $path, $allowSerializeEmpty);
141
        }
142
143 2
        return $this->scalarToNodeConverter->convert($value, $path, $allowSerializeEmpty);
0 ignored issues
show
The call to ScalarToNodeConverterInterface::convert() has too many arguments starting with $allowSerializeEmpty.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
144
    }
145
}
146