Issues (49)

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/Container/FlatContainer.php (6 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
 * This file is part of Graze DataStructure
4
 *
5
 * Copyright (c) 2017 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/data-structure/blob/master/LICENSE
11
 * @link http://github.com/graze/data-structure
12
 */
13
14
namespace Graze\DataStructure\Container;
15
16
use ArrayAccess;
17
use RecursiveArrayIterator;
18
19
/**
20
 * FlatContainer accepts key access using a delimiter to represent child arrays
21
 *
22
 * ## Examples
23
 *
24
 * ```php
25
 * $container = new FlatContainer(['first' => 'value', 'second' => ['child' => 1, 'other' => 2]]);
26
 *
27
 * $container->get('second.child')
28
 * // 1
29
 *
30
 * $container->has('first.child')
31
 * // false
32
 *
33
 * $container->set('second.third', 3);
34
 * $container->getAll();
35
 * // ['first' => 'value', 'second' => ['child' => 1, 'other' => 2, 'third' => 3]]
36
 *
37
 * $container->remove('second.other');
38
 * $container->getAll();
39
 * // ['first' => 'value', 'second' => ['child' => 1, 'third' => 3]]
40
 * ```
41
 */
42
class FlatContainer extends Container
43
{
44
    const DEFAULT_DELIMITER = '.';
45
46
    /** @var string */
47
    protected $delimiter = self::DEFAULT_DELIMITER;
48
49
    /**
50
     * @param string $key
51
     *
52
     * @return mixed|null
53
     */
54 33
    private function getChild($key)
55
    {
56 33
        $top = $this->params;
57
58 33
        foreach (explode($this->delimiter, $key) as $node) {
59 33
            if (!isset($top[$node])) {
60 16
                return null;
61
            }
62 31
            $top = $top[$node];
63
        }
64 17
        return $top;
65
    }
66
67
    /**
68
     * @param string $key
69
     *
70
     * @return string[] split the key into everything up to the last delimiter, and the last key
71
     */
72 36
    private function splitToLast($key)
73
    {
74 36
        $split = explode($this->delimiter, $key);
75 36
        $key = implode($this->delimiter, array_slice($split, 0, -1));
76 36
        $last = end($split);
77
78 36
        return [$key, $last];
79
    }
80
81
    /**
82
     * @param string $key The key to access, supports delimiter based child access (e.g. `parent.child.node`)
83
     *
84
     * @return bool
85
     */
86 85 View Code Duplication
    public function has($key)
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...
87
    {
88 85
        if (mb_strpos($key, $this->delimiter) !== false) {
89 15
            return (!is_null($this->getChild($key)));
90
        }
91 71
        return parent::has($key);
92
    }
93
94
    /**
95
     * @param string $key The key to access, supports delimiter based child access (e.g. `parent.child.node`)
96
     *
97
     * @return mixed|null
98
     */
99 58 View Code Duplication
    public function get($key)
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...
100
    {
101 58
        if (mb_strpos($key, $this->delimiter) !== false) {
102 18
            return $this->getChild($key);
103
        }
104
105 45
        return parent::get($key);
106
    }
107
108
    /**
109
     * @param string $key The key to access, supports delimiter based child access (e.g. `parent.child.node`)
110
     * @param mixed  $value
111
     *
112
     * @return ContainerInterface
113
     */
114 78
    public function set($key, $value)
115
    {
116 78
        return $this->doSet($key, $value);
117
    }
118
119
    /**
120
     * @param string $key
121
     * @param mixed  $value
122
     *
123
     * @return ContainerInterface
124
     */
125 95
    protected function doSet($key, $value)
126
    {
127 95
        if (mb_strpos($key, $this->delimiter) !== false) {
128 19
            list($key, $last) = $this->splitToLast($key);
129
130 19
            $top = $this->get($key);
131 19 View Code Duplication
            if (is_null($top) || (!is_array($top) && !($top instanceof ArrayAccess))) {
0 ignored issues
show
This code seems to be duplicated across 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...
132 8
                $top = [];
133
            }
134
135 19
            if ($top instanceof ContainerInterface) {
136 9
                $top = $top->set($last, $value);
137
            } else {
138 14
                $top[$last] = $value;
139
            }
140
141 19
            return $this->doSet($key, $top);
142
        }
143
144 95
        return parent::set($key, $value);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (set() instead of doSet()). Are you sure this is correct? If so, you might want to change this to $this->set().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
145
    }
146
147
    /**
148
     * @param string $key The key to access, supports delimiter based child access (e.g. `parent.child.node`)
149
     *
150
     * @return ContainerInterface
151
     */
152 26
    public function remove($key)
153
    {
154 26
        return $this->doRemove($key);
155
    }
156
157
    /**
158
     * @param string $key
159
     *
160
     * @return ContainerInterface
161
     */
162 28
    protected function doRemove($key)
163
    {
164 28
        if (mb_strpos($key, $this->delimiter) !== false) {
165 17
            list($key, $last) = $this->splitToLast($key);
166
167 17
            $top = $this->get($key);
168 17 View Code Duplication
            if (is_null($top) || (!is_array($top) && !($top instanceof ArrayAccess))) {
0 ignored issues
show
This code seems to be duplicated across 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...
169 2
                return $this;
170
            }
171
172 15
            if ($top instanceof ContainerInterface) {
173 6
                $top = $top->remove($last);
174
            } else {
175 9
                unset($top[$last]);
176
            }
177
178 15
            return $this->doSet($key, $top);
179
        }
180
181 11
        return parent::remove($key);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (remove() instead of doRemove()). Are you sure this is correct? If so, you might want to change this to $this->remove().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
182
    }
183
184
    /**
185
     * @param string $delimiter
186
     *
187
     * @return FlatContainer
188
     */
189 1
    public function setDelimiter($delimiter)
190
    {
191 1
        $this->delimiter = $delimiter;
192 1
        return $this;
193
    }
194
195
    /**
196
     * @return string
197
     */
198 1
    public function getDelimiter()
199
    {
200 1
        return $this->delimiter;
201
    }
202
}
203