Issues (387)

Branch: develop

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.

phpDocumentor/Descriptor/ProjectAnalyzerTest.php (4 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
namespace phpDocumentor\Descriptor;
4
5
use Mockery\Adapter\Phpunit\MockeryTestCase;
6
use Mockery as m;
7
8
/**
9
 * Tests for the \phpDocumentor\Descriptor\ProjectAnalyzer class.
10
 */
11
class ProjectAnalyzerTest extends MockeryTestCase
12
{
13
    /** @var ProjectAnalyzer */
14
    private $fixture;
15
16
    protected function setUp()
17
    {
18
        $this->fixture = new ProjectAnalyzer();
19
    }
20
21
    /**
22
     * @covers \phpDocumentor\Descriptor\ProjectAnalyzer::analyze
23
     */
24
    public function testFilesAreCounted()
25
    {
26
        // Arrange
27
        $projectDescriptor = $this->givenAProjectMock();
28
        $this->whenProjectDescriptorHasTheFollowingFiles($projectDescriptor, [1, 2, 3, 4]);
29
        $this->whenProjectDescriptorHasTheFollowingElements($projectDescriptor, []);
30
        $this->whenProjectHasTheFollowingChildrenOfRootNamespace($projectDescriptor, []);
31
32
        // Act
33
        $this->fixture->analyze($projectDescriptor);
34
35
        // Assert
36
        $this->assertAttributeSame(4, 'fileCount', $this->fixture);
37
    }
38
39
    /**
40
     * @covers \phpDocumentor\Descriptor\ProjectAnalyzer::analyze
41
     */
42
    public function testIfTopLevelNamespacesAreCounted()
43
    {
44
        // Arrange
45
        $projectDescriptor = $this->givenAProjectMock();
46
        $this->whenProjectDescriptorHasTheFollowingFiles($projectDescriptor, []);
47
        $this->whenProjectDescriptorHasTheFollowingElements($projectDescriptor, []);
48
        $this->whenProjectHasTheFollowingChildrenOfRootNamespace($projectDescriptor, [1, 2, 3]);
49
50
        // Act
51
        $this->fixture->analyze($projectDescriptor);
52
53
        // Assert
54
        $this->assertAttributeSame(3, 'topLevelNamespaceCount', $this->fixture);
55
    }
56
57
    /**
58
     * @covers \phpDocumentor\Descriptor\ProjectAnalyzer::analyze
59
     * @covers \phpDocumentor\Descriptor\ProjectAnalyzer::findAllElements
60
     * @covers \phpDocumentor\Descriptor\ProjectAnalyzer::incrementUnresolvedParentCounter
61
     */
62
    public function testIfUnresolvedClassesAreCounted()
63
    {
64
        // Arrange
65
        $classDescriptor1 = $this->givenAClassWithParent('phpDocumentor\Descriptor\ClassDescriptor');
66
        $projectDescriptor = $this->givenAProjectMock();
67
        $this->whenProjectDescriptorHasTheFollowingFiles($projectDescriptor, []);
68
        $this->whenProjectDescriptorHasTheFollowingElements(
69
            $projectDescriptor,
70
            [
71
                'ds1' => $classDescriptor1,
72
                'ds2' => $this->givenAClassWithParent($classDescriptor1),
73
                'ds3' => $this->givenAnInterfaceWithParent('123'),
74
            ]
75
        );
76
        $this->whenProjectHasTheFollowingChildrenOfRootNamespace($projectDescriptor, []);
77
78
        // Act
79
        $this->fixture->analyze($projectDescriptor);
80
81
        // Assert
82
        $this->assertAttributeSame(1, 'unresolvedParentClassesCount', $this->fixture);
83
    }
84
85
    /**
86
     * @covers \phpDocumentor\Descriptor\ProjectAnalyzer::analyze
87
     * @covers \phpDocumentor\Descriptor\ProjectAnalyzer::findAllElements
88
     * @covers \phpDocumentor\Descriptor\ProjectAnalyzer::addElementToCounter
89
     */
90
    public function testIfVariousDescriptorTypesAreCounted()
91
    {
92
        // Arrange
93
        $classDescriptor1 = $this->givenAClassWithParent('phpDocumentor\Descriptor\ClassDescriptor');
94
        $projectDescriptor = $this->givenAProjectMock();
95
        $this->whenProjectDescriptorHasTheFollowingFiles($projectDescriptor, []);
96
        $this->whenProjectDescriptorHasTheFollowingElements(
97
            $projectDescriptor,
98
            [
99
                'ds1' => $classDescriptor1,
100
                'ds2' => $this->givenAClassWithParent($classDescriptor1),
101
                'ds3' => $this->givenAnInterfaceWithParent('123'),
102
            ]
103
        );
104
        $this->whenProjectHasTheFollowingChildrenOfRootNamespace($projectDescriptor, []);
105
106
        // Act
107
        $this->fixture->analyze($projectDescriptor);
108
109
        // Assert
110
        $this->assertAttributeSame(
111
            [
112
                'phpDocumentor\Descriptor\ClassDescriptor' => 2,
113
                'phpDocumentor\Descriptor\InterfaceDescriptor' => 1,
114
            ],
115
            'descriptorCountByType',
116
            $this->fixture
117
        );
118
    }
119
120
    /**
121
     * @covers \phpDocumentor\Descriptor\ProjectAnalyzer::__toString
122
     */
123
    public function testIfStringOutputContainsAllCounters()
124
    {
125
        // Arrange
126
        $classDescriptor1 = $this->givenAClassWithParent('phpDocumentor\Descriptor\ClassDescriptor');
127
        $projectDescriptor = $this->givenAProjectMock();
128
        $this->whenProjectDescriptorHasTheFollowingFiles($projectDescriptor, [1, 2, 3, 4]);
129
        $this->whenProjectDescriptorHasTheFollowingElements(
130
            $projectDescriptor,
131
            [
132
                'ds1' => $classDescriptor1,
133
                'ds2' => $this->givenAClassWithParent($classDescriptor1),
134
                'ds3' => $this->givenAnInterfaceWithParent('123'),
135
            ]
136
        );
137
        $this->whenProjectHasTheFollowingChildrenOfRootNamespace($projectDescriptor, [1, 2, 3]);
138
        $this->fixture->analyze($projectDescriptor);
139
140
        $expected = <<<TEXT
141
In the ProjectDescriptor are:
142
         4 files
143
         3 top-level namespaces
144
         1 unresolvable parent classes
145
         2 phpDocumentor\Descriptor\ClassDescriptor elements
146
         1 phpDocumentor\Descriptor\InterfaceDescriptor elements
147
148
TEXT;
149
        $expected = str_replace("\n", PHP_EOL, $expected);
150
151
        // Act
152
        $result = (string) $this->fixture;
153
154
        // Assert
155
        $this->assertSame($expected, $result);
156
    }
157
158
    /**
159
     * Returns a class with the given parent set.
160
     *
161
     * @param string|DescriptorAbstract $parent
162
     */
163
    protected function givenAClassWithParent($parent): ClassDescriptor
164
    {
165
        $classDescriptor1 = new ClassDescriptor();
166
        $classDescriptor1->setParent($parent);
0 ignored issues
show
It seems like $parent defined by parameter $parent on line 163 can also be of type string; however, phpDocumentor\Descriptor...Descriptor::setParent() does only seem to accept object<phpDocumentor\Des...tor\DescriptorAbstract>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
167
        return $classDescriptor1;
168
    }
169
170
    /**
171
     * @param string $interfaceParent
172
     */
173
    protected function givenAnInterfaceWithParent($interfaceParent): InterfaceDescriptor
174
    {
175
        $classDescriptor3 = new InterfaceDescriptor();
176
        $classDescriptor3->setParent($interfaceParent);
0 ignored issues
show
$interfaceParent is of type string, but the function expects a object<phpDocumentor\Descriptor\Collection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
178
        return $classDescriptor3;
179
    }
180
181
    /**
182
     * Returns a mocked ProjectDescriptor object.
183
     */
184
    protected function givenAProjectMock(): m\MockInterface
185
    {
186
        return m::mock('phpDocumentor\Descriptor\ProjectDescriptor')->shouldIgnoreMissing();
187
    }
188
189
    /**
190
     * Ensures that the ProjectDescriptor contains and returns the provided files.
191
     */
192
    protected function whenProjectDescriptorHasTheFollowingFiles(m\MockInterface $projectDescriptor, array $files)
193
    {
194
        $projectDescriptor->shouldReceive('getFiles')->andReturn($files);
0 ignored issues
show
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

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...
195
    }
196
197
    /**
198
     * Ensures that the ProjectDescriptor has an index 'elements' with the provided elements.
199
     */
200
    protected function whenProjectDescriptorHasTheFollowingElements(m\MockInterface $projectDescriptor, array $elements)
201
    {
202
        $projectDescriptor->shouldReceive('getIndexes->get')
203
            ->with('elements', m::type('phpDocumentor\Descriptor\Collection'))
204
            ->andReturn(new Collection($elements));
205
    }
206
207
    /**
208
     * Ensures that the ProjectDescriptor has a root namespace with the provided array as children of that namespace.
209
     */
210
    protected function whenProjectHasTheFollowingChildrenOfRootNamespace(
211
        m\MockInterface $projectDescriptor,
212
        array $rootNamespaceChildren
213
    ) {
214
        $projectDescriptor->shouldReceive('getNamespace->getChildren')->andReturn(
0 ignored issues
show
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

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...
215
            new Collection($rootNamespaceChildren)
216
        );
217
    }
218
}
219