Issues (249)

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/main/php/PHPMD/AbstractNode.php (9 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 PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD;
19
20
use BadMethodCallException;
21
use PDepend\Source\AST\AbstractASTArtifact;
22
use PDepend\Source\AST\ASTVariable;
23
use PHPMD\Node\ASTNode;
24
25
/**
26
 * This is an abstract base class for PHPMD code nodes, it is just a wrapper
27
 * around PDepend's object model.
28
 */
29
abstract class AbstractNode
30
{
31
    /**
32
     * @var \PDepend\Source\AST\ASTArtifact|\PDepend\Source\AST\ASTNode $node
33
     */
34
    private $node = null;
35
36
    /**
37
     * The collected metrics for this node.
38
     *
39
     * @var array<string, mixed>
40
     */
41
    private $metrics = null;
42
43
    /**
44
     * Constructs a new PHPMD node.
45 59
     *
46
     * @param \PDepend\Source\AST\ASTArtifact|\PDepend\Source\AST\ASTNode $node
47 59
     */
48 59
    public function __construct($node)
49
    {
50
        $this->node = $node;
51
    }
52
53
    /**
54
     * The magic call method is used to pipe requests from rules direct
55
     * to the underlying PDepend AST node.
56
     *
57
     * @param string $name
58
     * @param array $args
59
     * @return mixed
60 36
     * @throws BadMethodCallException When the underlying PDepend node
61
     *         does not contain a method named <b>$name</b>.
62 36
     */
63 36
    public function __call($name, array $args)
64
    {
65
        $node = $this->getNode();
66
        if (!method_exists($node, $name)) {
67
            throw new BadMethodCallException(
68 36
                sprintf('Invalid method %s() called.', $name)
69
            );
70
        }
71
72
        return call_user_func_array(array($node, $name), $args);
73
    }
74
75
    /**
76
     * Returns the parent of this node or <b>null</b> when no parent node
77 8
     * exists.
78
     *
79 8
     * @return ASTNode
80
     */
81
    public function getParent()
82 8
    {
83
        $node = $this->node->getParent();
0 ignored issues
show
The method getParent does only exist in PDepend\Source\AST\ASTNode, but not in PDepend\Source\AST\ASTArtifact.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
84
        if ($node === null) {
85
            return null;
86
        }
87
88
        return new ASTNode($node, $this->getFileName());
89
    }
90
91 13
    /**
92
     * Returns a child node at the given index.
93 13
     *
94 13
     * @param integer $index The child offset.
95 13
     * @return \PHPMD\Node\ASTNode
96
     */
97
    public function getChild($index)
98
    {
99
        return new ASTNode(
100
            $this->node->getChild($index),
0 ignored issues
show
The method getChild does only exist in PDepend\Source\AST\ASTNode, but not in PDepend\Source\AST\ASTArtifact.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
101
            $this->getFileName()
102
        );
103
    }
104
105
    /**
106 22
     * Returns the first child of the given type or <b>null</b> when this node
107
     * has no child of the given type.
108 22
     *
109 22
     * @param string $type The searched child type.
110
     * @return ASTNode|null
111
     */
112 22
    public function getFirstChildOfType($type)
113
    {
114
        $node = $this->node->getFirstChildOfType('PDepend\Source\AST\AST' . $type);
0 ignored issues
show
The method getFirstChildOfType does only exist in PDepend\Source\AST\ASTNode, but not in PDepend\Source\AST\ASTArtifact.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
115
116
        if ($node === null) {
117
            return null;
118
        }
119
120
        return new ASTNode($node, $this->getFileName());
121
    }
122 55
123
    /**
124 55
     * Searches recursive for all children of this node that are of the given
125
     * type.
126 55
     *
127 55
     * @param string $type The searched child type.
128 51
     * @return ASTNode[]
129
     */
130 55
    public function findChildrenOfType($type)
131
    {
132
        $children = $this->node->findChildrenOfType('PDepend\Source\AST\AST' . $type);
0 ignored issues
show
The method findChildrenOfType does only exist in PDepend\Source\AST\ASTNode, but not in PDepend\Source\AST\ASTArtifact.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
133
134
        $nodes = array();
135
136
        foreach ($children as $child) {
137
            $nodes[] = new ASTNode($child, $this->getFileName());
138
        }
139 2
140
        return $nodes;
141 2
    }
142 2
143
    /**
144
     * Searches recursive for all children of this node that are of variable.
145
     *
146
     * @return ASTVariable[]
147
     * @todo Cover by a test.
148
     */
149
    public function findChildrenOfTypeVariable()
150 2
    {
151
        return $this->findChildrenOfType('Variable');
152 2
    }
153
154
    /**
155
     * Tests if this node represents the the given type.
156
     *
157
     * @param string $type The expected node type.
158
     * @return boolean
159
     */
160
    public function isInstanceOf($type)
161 15
    {
162
        $class = 'PDepend\Source\AST\AST' . $type;
163 15
164
        return ($this->node instanceof $class);
165
    }
166
167
    /**
168
     * Returns the image of the underlying node.
169
     *
170
     * @return string
171 6
     */
172
    public function getImage()
173 6
    {
174
        return $this->node->getName();
0 ignored issues
show
The method getName does only exist in PDepend\Source\AST\ASTArtifact, but not in PDepend\Source\AST\ASTNode.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
175
    }
176
177
    /**
178
     * Returns the source name for this node, maybe a class or interface name,
179
     * or a package, method, function name.
180
     *
181
     * @return string
182
     */
183
    public function getName()
184
    {
185
        return $this->node->getName();
0 ignored issues
show
The method getName does only exist in PDepend\Source\AST\ASTArtifact, but not in PDepend\Source\AST\ASTNode.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
186
    }
187
188
    /**
189
     * Returns the begin line for this node in the php source code file.
190
     *
191 54
     * @return integer
192
     */
193 54
    public function getBeginLine()
194
    {
195
        return $this->node->getStartLine();
0 ignored issues
show
The method getStartLine does only exist in PDepend\Source\AST\ASTNode, but not in PDepend\Source\AST\ASTArtifact.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
196
    }
197
198
    /**
199
     * Returns the end line for this node in the php source code file.
200
     *
201 51
     * @return integer
202
     */
203 51
    public function getEndLine()
204
    {
205
        return $this->node->getEndLine();
0 ignored issues
show
The method getEndLine does only exist in PDepend\Source\AST\ASTNode, but not in PDepend\Source\AST\ASTArtifact.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
206
    }
207
208
    /**
209
     * Returns the name of the declaring source file.
210
     *
211 3
     * @return string|null
212
     */
213 3
    public function getFileName()
214 3
    {
215
        $compilationUnit = $this->node instanceof AbstractASTArtifact
216
            ? $this->node->getCompilationUnit()
217
            : null;
218
219
        return $compilationUnit
220
            ? (string)$compilationUnit->getFileName()
221
            : null; // @TODO: Find the name from some parent node https://github.com/phpmd/phpmd/issues/837
222
    }
223
224 3
    /**
225
     * Returns the wrapped PDepend node instance.
226 3
     *
227 3
     * @return \PDepend\Source\AST\ASTArtifact
228
     */
229
    public function getNode()
230
    {
231
        return $this->node;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->node; of type PDepend\Source\AST\ASTAr...pend\Source\AST\ASTNode adds the type PDepend\Source\AST\ASTNode to the return on line 231 which is incompatible with the return type documented by PHPMD\AbstractNode::getNode of type PDepend\Source\AST\ASTArtifact.
Loading history...
232
    }
233
234
    /**
235
     * Returns a textual representation/name for the concrete node type.
236
     *
237
     * @return string
238 6
     */
239
    public function getType()
240 6
    {
241 6
        $type = explode('\\', get_class($this));
242
243 6
        return preg_replace('(node$)', '', strtolower(array_pop($type)));
244
    }
245
246
    /**
247
     * This method will return the metric value for the given identifier or
248
     * <b>null</b> when no such metric exists.
249
     *
250
     * @param string $name The metric name or abbreviation.
251
     * @return mixed
252
     */
253
    public function getMetric($name)
254
    {
255
        if (isset($this->metrics[$name])) {
256
            return $this->metrics[$name];
257
        }
258
259
        return null;
260
    }
261
262
    /**
263
     * This method will set the metrics for this node.
264
     *
265
     * @param array<string, mixed> $metrics The collected node metrics.
266
     * @return void
267
     */
268
    public function setMetrics(array $metrics)
269
    {
270
        if ($this->metrics === null) {
271
            $this->metrics = $metrics;
272
        }
273
    }
274
275
    /**
276
     * Checks if this node has a suppressed annotation for the given rule
277
     * instance.
278
     *
279
     * @param \PHPMD\Rule $rule
280
     * @return boolean
281
     */
282
    abstract public function hasSuppressWarningsAnnotationFor(Rule $rule);
283
284
    /**
285
     * Returns the full qualified name of a class, an interface, a method or
286
     * a function.
287
     *
288
     * @return string
289
     */
290
    abstract public function getFullQualifiedName();
291
292
    /**
293
     * Returns the name of the parent type or <b>null</b> when this node has no
294
     * parent type.
295
     *
296
     * @return string
297
     */
298
    abstract public function getParentName();
299
300
    /**
301
     * Returns the name of the parent package.
302
     *
303
     * @return string
304
     */
305
    abstract public function getNamespaceName();
306
}
307