Issues (245)

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/Parser/InterfaceParser.php (10 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
/**
4
 * \AppserverIo\Doppelgaenger\Parser\InterfaceParser
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Bernhard Wick <[email protected]>
15
 * @copyright 2015 TechDivision GmbH - <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/doppelgaenger
18
 * @link      http://www.appserver.io/
19
 */
20
21
namespace AppserverIo\Doppelgaenger\Parser;
22
23
use AppserverIo\Doppelgaenger\Entities\Definitions\InterfaceDefinition;
24
use AppserverIo\Doppelgaenger\Entities\Definitions\FileDefinition;
25
use AppserverIo\Doppelgaenger\Entities\Lists\StructureDefinitionList;
26
use AppserverIo\Doppelgaenger\Exceptions\GeneratorException;
27
use AppserverIo\Psr\MetaobjectProtocol\Dbc\Annotations\Invariant;
28
29
/**
30
 * The InterfaceParser class which is used to get an \AppserverIo\Doppelgaenger\Entities\Definitions\InterfaceDefinition
31
 * instance (or several) from a fail containing those definition(s)
32
 *
33
 * @author    Bernhard Wick <[email protected]>
34
 * @copyright 2015 TechDivision GmbH - <[email protected]>
35
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
36
 * @link      https://github.com/appserver-io/doppelgaenger
37
 * @link      http://www.appserver.io/
38
 */
39
class InterfaceParser extends AbstractStructureParser
40
{
41
42
    /**
43
     * Token representing the structure this parser is used for
44
     *
45
     * @var integer TOKEN
46
     */
47
    const TOKEN = T_INTERFACE;
48
49
    /**
50
     * Will return the token representing the structure the parser is used for e.g. T_CLASS
51
     *
52
     * @return integer
53
     */
54
    public function getToken()
55
    {
56
        return self::TOKEN;
57
    }
58
59
    /**
60
     * Will get all parent interfaces (if any).
61
     * Might return false on error
62
     *
63
     * @param array $tokens The token array
64
     *
65
     * @return array
66
     */
67
    public function getParents($tokens)
68
    {
69
        // Check the tokens
70
        $interfaceString = '';
71
        for ($i = 0; $i < count($tokens); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
72
            // If we got the interface name
73
            if ($tokens[$i][0] === T_EXTENDS) {
74
                for ($j = $i + 1; $j < count($tokens); $j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
75
                    if ($tokens[$j] === '{') {
76
                        // We got everything
77
                        break;
78
0 ignored issues
show
Blank line found at end of control structure
Loading history...
79
                    } elseif ($tokens[$j][0] === T_STRING) {
80
                        $interfaceString .= $tokens[$j][1];
81
                    }
82
                }
83
            }
84
        }
85
86
        // Normally we will have one or several interface names separated by commas
87
        $parents = explode(',', $interfaceString);
88
        foreach ($parents as $key => $parent) {
89
            $parents[$key] = trim($parent);
90
91
            // We do not want empty stuff
92
            if (empty($parents[$key])) {
93
                unset($parents[$key]);
94
            }
95
        }
96
97
        return $parents;
98
    }
99
100
    /**
101
     * Returns a ClassDefinition from a token array.
102
     *
103
     * This method will use a set of other methods to parse a token array and retrieve any
104
     * possible information from it. This information will be entered into a ClassDefinition object.
105
     *
106
     * @param array   $tokens       The token array
107
     * @param boolean $getRecursive Do we have to load the inherited contracts as well?
108
     *
109
     * @return \AppserverIo\Doppelgaenger\Entities\Definitions\InterfaceDefinition
110
     *
111
     * @throws \AppserverIo\Doppelgaenger\Exceptions\GeneratorException
112
     */
113
    protected function getDefinitionFromTokens($tokens, $getRecursive = true)
0 ignored issues
show
The parameter $getRecursive is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
114
    {
115
        // First of all we need a new InterfaceDefinition to fill
116 View Code Duplication
        if (is_null($this->currentDefinition)) {
117
            $this->currentDefinition = new InterfaceDefinition();
118
0 ignored issues
show
Blank line found at end of control structure
Loading history...
119
        } elseif (!$this->currentDefinition instanceof InterfaceDefinition) {
120
            throw new GeneratorException(sprintf(
121
                'The structure definition %s does not seem to be a interface definition.',
122
                $this->currentDefinition->getQualifiedName()
123
            ));
124
        }
125
126
        // Save the path of the original definition for later use
127
        $this->currentDefinition->setPath($this->file);
128
129
        // Get the interfaces own namespace and the namespace which are included via use
130
        $this->currentDefinition->setNamespace($this->getNamespace());
131
        $this->currentDefinition->setUsedStructures($this->getUsedStructures());
132
133
        // For our next step we would like to get the doc comment (if any)
134
        $this->currentDefinition->setDocBlock($this->getDocBlock($tokens, self::TOKEN));
135
136
        // Get start and end line
137
        $this->currentDefinition->setStartLine($this->getStartLine($tokens));
138
        $this->currentDefinition->setEndLine($this->getEndLine($tokens));
139
140
        // Get the interface identity
141
        $this->currentDefinition->setName($this->getName($tokens));
142
143
        // So we got our docBlock, now we can parse the invariant annotations from it
144
        $annotationParser = new AnnotationParser($this->file, $this->config, $this->tokens);
145
        $this->currentDefinition->setInvariantConditions($annotationParser->getConditions(
0 ignored issues
show
It seems like $annotationParser->getCo...\Invariant::ANNOTATION) targeting AppserverIo\Doppelgaenge...Parser::getConditions() can also be of type false; however, AppserverIo\Doppelgaenge...etInvariantConditions() does only seem to accept object<AppserverIo\Doppe...es\Lists\AssertionList>, did you maybe forget to handle an error condition?
Loading history...
146
            $this->currentDefinition->getDocBlock(),
147
            Invariant::ANNOTATION
148
        ));
149
150
        // Lets check if there is any inheritance, or if we implement any interfaces
151
        $parentNames = $this->getParents($tokens);
152
        if (count($this->currentDefinition->getUsedStructures()) === 0) {
153
            foreach ($parentNames as $parentName) {
154
                if (strpos($parentName, '\\') !== false) {
155
                    $this->currentDefinition->getExtends()[] = $parentName;
156
0 ignored issues
show
Blank line found at end of control structure
Loading history...
157
                } else {
158
                    $this->currentDefinition->getExtends()[] = '\\' . $this->currentDefinition->getNamespace() . '\\' . $parentName;
159
                }
160
            }
161
0 ignored issues
show
Blank line found at end of control structure
Loading history...
162
        } else {
163
            foreach ($this->currentDefinition->getUsedStructures() as $alias) {
164
                foreach ($parentNames as $parentName) {
165
                    if (strpos($alias, $parentName) !== false) {
166
                        $this->currentDefinition->setExtends('\\' . $alias);
167
                    }
168
                }
169
            }
170
        }
171
172
        // Clean possible double-\
173
        $this->currentDefinition->setExtends(str_replace('\\\\', '\\', $this->currentDefinition->getExtends()));
174
175
        $this->currentDefinition->setConstants($this->getConstants($tokens));
0 ignored issues
show
The call to InterfaceParser::getConstants() has too many arguments starting with $tokens.

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...
176
177
        // Only thing still missing are the methods, so ramp up our FunctionParser
178
        $functionParser = new FunctionParser(
179
            $this->file,
180
            $this->config,
181
            $this->structureDefinitionHierarchy,
182
            $this->structureMap,
183
            $this->currentDefinition,
184
            $this->tokens
185
        );
186
187
        $this->currentDefinition->setFunctionDefinitions($functionParser->getDefinitionListFromTokens($tokens));
0 ignored issues
show
It seems like $functionParser->getDefi...ListFromTokens($tokens) targeting AppserverIo\Doppelgaenge...initionListFromTokens() can also be of type false; however, AppserverIo\Doppelgaenge...etFunctionDefinitions() does only seem to accept object<AppserverIo\Doppe...FunctionDefinitionList>, did you maybe forget to handle an error condition?
Loading history...
188
189
        return $this->currentDefinition;
190
    }
191
}
192