Issues (6)

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.

library/Nestedset/Model/Output.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
class Nestedset_Model_Output
4
{
5
    /**
6
     * Convert a tree array (with depth) into a hierarchical array.
7
     *
8
     * @param $nodes|array   Array with depth value.
9
     *
10
     * @return array
11
     */
12
    public function toArray(array $nodes)
13
    {
14
        $result     = array();
15
        $stackLevel = 0;
0 ignored issues
show
$stackLevel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
16
17
        // Node Stack. Used to help building the hierarchy
18
        $stack = array();
19
20
        foreach ($nodes as $node) {
21
            $node['children'] = array();
22
23
            // Number of stack items
24
            $stackLevel = count($stack);
25
26
            // Check if we're dealing with different levels
27
            while ($stackLevel > 0 && $stack[$stackLevel - 1]['depth'] >= $node['depth']) {
28
                array_pop($stack);
29
                $stackLevel--;
30
            }
31
32
            // Stack is empty (we are inspecting the root)
33
            if ($stackLevel == 0) {
34
                // Assigning the root node
35
                $i = count($result);
36
37
                $result[$i] = $node;
38
                $stack[] =& $result[$i];
39
            } else {
40
                // Add node to parent
41
                $i = count($stack[$stackLevel - 1]['children']);
42
43
                $stack[$stackLevel - 1]['children'][$i] = $node;
44
                $stack[] =& $stack[$stackLevel - 1]['children'][$i];
45
            }
46
        }
47
48
        return $result;
49
    }
50
51
    /**
52
     * Convert a tree array (with depth) into a hierarchical XML string.
53
     *
54
     * @param $nodes|array   Array with depth value.
55
     *
56
     * @return string
57
     */
58
    public function toXml(array $nodes)
59
    {
60
        $xml  = new DomDocument('1.0');
61
        $xml->preserveWhiteSpace = false;
62
        $root = $xml->createElement('root');
63
        $xml->appendChild($root);
64
65
        $depth = 0;
66
        $currentChildren = array();
67
68
        foreach ($nodes as $node) {
69
            $element = $xml->createElement('element');
70
            $element->setAttribute('id', $node['id']);
71
            $element->setAttribute('name', $node['name']);
72
            $element->setAttribute('lft', $node['lft']);
73
            $element->setAttribute('rgt', $node['rgt']);
74
75
            $children = $xml->createElement('children');
76
            $element->appendChild($children);
77
78
            if ($node['depth'] == 0) {
79
                // Handle root
80
                $root->appendChild($element);
81
                $currentChildren[0] = $children;
82
            } elseif ($node['depth'] > $depth) {
83
                // is a new sub level
84
                $currentChildren[$depth]->appendChild($element);
85
                $currentChildren[$node['depth']] = $children;
86
            } elseif ($node['depth'] == $depth || $node['depth'] < $depth) {
87
                // is at the same level
88
                $currentChildren[$node['depth'] - 1]->appendChild($element);
89
            }
90
91
            $depth = $node['depth'];
92
        }
93
94
        return $xml->saveXML();
95
    }
96
97
    /**
98
     * Return nested set as JSON
99
     *
100
     * @params $nodes|array          Original 'flat' nested tree
101
     *
102
     * @return string
103
     */
104
    public function toJson(array $nodes)
105
    {
106
        $nestedArray = $this->toArray($nodes);
107
        $result      = json_encode($nestedArray);
108
109
        return $result;
110
    }
111
112
    /**
113
     * Returns all elements as HTML structure
114
     *
115
     * Possible options:
116
     *  - list (simple <ul><li>)
117
     *
118
     * @param $model|NestedSet_Model    Nested set model
119
     *
120
     * @return string
121
     */
122
    public function toHtml(array $nodes, $method = 'list')
123
    {
124
        switch ($method) {
125
            case 'list':
126
            default:
127
                return $this->_toHtmlList($nodes);
128
        }
129
    }
130
131
    /**
132
     * Returns all elements as <ul>/<li> structure
133
     *
134
     * @param $nodes|array
135
     *
136
     * @return string
137
     */
138
    protected function _toHtmlList(array $nodes)
139
    {
140
        $result = "<ul>";
141
        $depth  = $nodes[0]['depth'];
142
143
        foreach ($nodes as $node) {
144
            if ($depth < $node['depth']) {
145
                $result .= "<ul>";
146
            } elseif ($depth == $node['depth'] && $depth > $nodes[0]['depth']) {
147
                $result .= "</li>";
148
            } elseif ($depth > $node['depth']) {
149
                for ($i = 0; $i < ($depth - $node['depth']); $i++) {
150
                    $result .= "</li></ul>";
151
                }
152
            }
153
154
            // XXX Currently it outputs results according to my actual needs
155
            // for testing purpose.
156
            $result .= "<li>{$node['name']} (id: {$node['id']} left: {$node['lft']} right: {$node['rgt']})";
157
158
            $depth = $node['depth'];
159
        }
160
161
        $result .= "</li></ul>";
162
        $result .= "</ul>";
163
164
        return $result;
165
    }
166
}
167