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

Labels
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
 * 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 PDepend\Application;
21
use PDepend\Engine;
22
use PDepend\Input\ExcludePathFilter;
23
use PDepend\Input\ExtensionFilter;
24
25
/**
26
 * Simple factory that is used to return a ready to use PDepend instance.
27
 */
28
class ParserFactory
29
{
30
    /** @var string The default config file name */
31
    const PDEPEND_CONFIG_FILE_NAME = '/pdepend.xml';
32
33
    /** @var string The distribution config file name */
34
    const PDEPEND_CONFIG_FILE_NAME_DIST = '/pdepend.xml.dist';
35
36
    /**
37
     * Mapping between phpmd option names and those used by pdepend.
38
     *
39
     * @var array
40
     */
41
    private $phpmd2pdepend = array(
42
        'coverage' => 'coverage-report',
43
    );
44
45 12
    /**
46
     * Creates the used {@link \PHPMD\Parser} analyzer instance.
47 12
     *
48 12
     * @param \PHPMD\PHPMD $phpmd
49
     * @return \PHPMD\Parser
50 12
     */
51
    public function create(PHPMD $phpmd)
52
    {
53
        $pdepend = $this->createInstance();
54
        $pdepend = $this->init($pdepend, $phpmd);
0 ignored issues
show
It seems like $pdepend can be null; however, init() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
55
56
        return new Parser($pdepend);
57
    }
58 12
59
    /**
60 12
     * Creates a clean php depend instance with some base settings.
61
     *
62 12
     * @return \PDepend\Engine
63
     */
64 12
    private function createInstance()
65 10
    {
66
        $application = new Application();
67
68 12
        $workingDirectory = getcwd();
69
        if (file_exists($workingDirectory . self::PDEPEND_CONFIG_FILE_NAME)) {
70
            $application->setConfigurationFile($workingDirectory . self::PDEPEND_CONFIG_FILE_NAME);
71
        } elseif (file_exists($workingDirectory . self::PDEPEND_CONFIG_FILE_NAME_DIST)) {
72
            $application->setConfigurationFile($workingDirectory . self::PDEPEND_CONFIG_FILE_NAME_DIST);
73
        }
74
75
        return $application->getEngine();
76
    }
77
78 12
    /**
79
     * Configures the given PDepend\Engine instance based on some user settings.
80 12
     *
81 12
     * @param \PDepend\Engine $pdepend
82 12
     * @param \PHPMD\PHPMD $phpmd
83 12
     * @return \PDepend\Engine
84
     */
85 12
    private function init(Engine $pdepend, PHPMD $phpmd)
86
    {
87
        $this->initOptions($pdepend, $phpmd);
88
        $this->initInput($pdepend, $phpmd);
89
        $this->initIgnores($pdepend, $phpmd);
90
        $this->initExtensions($pdepend, $phpmd);
91
92
        return $pdepend;
93
    }
94
95 12
    /**
96
     * Configures the input source.
97 12
     *
98 12
     * @param \PDepend\Engine $pdepend
99 12
     * @param \PHPMD\PHPMD $phpmd
100 3
     * @return void
101 3
     */
102
    private function initInput(Engine $pdepend, PHPMD $phpmd)
103 10
    {
104
        foreach (explode(',', $phpmd->getInput()) as $path) {
105 12
            $trimmedPath = trim($path);
106
            if (is_dir($trimmedPath)) {
107
                $pdepend->addDirectory($trimmedPath);
108
                continue;
109
            }
110
            $pdepend->addFile($trimmedPath);
111
        }
112
    }
113
114 12
    /**
115
     * Initializes the ignored files and path's.
116 12
     *
117 12
     * @param \PDepend\Engine $pdepend
118 12
     * @param \PHPMD\PHPMD $phpmd
119
     * @return void
120
     */
121 12
    private function initIgnores(Engine $pdepend, PHPMD $phpmd)
122
    {
123
        if (count($phpmd->getIgnorePatterns()) > 0) {
124
            $pdepend->addFileFilter(
125
                new ExcludePathFilter($phpmd->getIgnorePatterns())
126
            );
127
        }
128
    }
129
130 12
    /**
131
     * Initializes the accepted php source file extensions.
132 12
     *
133 12
     * @param \PDepend\Engine $pdepend
134 12
     * @param \PHPMD\PHPMD $phpmd
135
     * @return void
136
     */
137 12
    private function initExtensions(Engine $pdepend, PHPMD $phpmd)
138
    {
139
        if (count($phpmd->getFileExtensions()) > 0) {
140
            $pdepend->addFileFilter(
141
                new ExtensionFilter($phpmd->getFileExtensions())
142
            );
143
        }
144
    }
145
146 12
    /**
147
     * Initializes additional options for pdepend.
148 12
     *
149 12
     * @param \PDepend\Engine $pdepend
150
     * @param \PHPMD\PHPMD $phpmd
151
     * @return void
152
     */
153
    private function initOptions(Engine $pdepend, PHPMD $phpmd)
154 12
    {
155 12
        $options = array();
156
        foreach (array_filter($phpmd->getOptions()) as $name => $value) {
157
            if (isset($this->phpmd2pdepend[$name])) {
158
                $options[$this->phpmd2pdepend[$name]] = $value;
159
            }
160
        }
161
        $pdepend->setOptions($options);
162
    }
163
}
164