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.

Descriptor/InterfaceDescriptorTest.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
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Descriptor;
13
14
use Mockery as m;
15
use phpDocumentor\Descriptor\Tag\AuthorDescriptor;
16
use phpDocumentor\Descriptor\Tag\VersionDescriptor;
17
18
/**
19
 * Tests the functionality for the InterfaceDescriptor class.
20
 * @coversDefaultClass \phpDocumentor\Descriptor\InterfaceDescriptor
21
 */
22
class InterfaceDescriptorTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
23
{
24
    /** @var InterfaceDescriptor $fixture */
25
    protected $fixture;
26
27
    /**
28
     * Creates a new (empty) fixture object.
29
     */
30
    protected function setUp()
31
    {
32
        $this->fixture = new InterfaceDescriptor();
33
    }
34
35
    /**
36
     * Tests whether all collection objects are properly initialized.
37
     *
38
     * @covers ::__construct
39
     */
40
    public function testInitialize()
41
    {
42
        $this->assertAttributeInstanceOf(Collection::class, 'parents', $this->fixture);
43
        $this->assertAttributeInstanceOf(Collection::class, 'constants', $this->fixture);
44
        $this->assertAttributeInstanceOf(Collection::class, 'methods', $this->fixture);
45
    }
46
47
    /**
48
     * @covers ::setParent
49
     * @covers ::getParent
50
     */
51
    public function testSettingAndGettingParentInterfaces()
52
    {
53
        $this->assertInstanceOf(Collection::class, $this->fixture->getParent());
54
55
        $mock = m::mock(Collection::class);
56
57
        $this->fixture->setParent($mock);
58
59
        $this->assertSame($mock, $this->fixture->getParent());
60
    }
61
62
    /**
63
     * @covers ::setConstants
64
     * @covers ::getConstants
65
     */
66
    public function testSettingAndGettingConstants()
67
    {
68
        $this->assertInstanceOf(Collection::class, $this->fixture->getConstants());
69
70
        $mock = m::mock(Collection::class);
71
72
        $this->fixture->setConstants($mock);
73
74
        $this->assertSame($mock, $this->fixture->getConstants());
75
    }
76
77
    /**
78
     * @covers ::setMethods
79
     * @covers ::getMethods
80
     */
81
    public function testSettingAndGettingMethods()
82
    {
83
        $this->assertInstanceOf(Collection::class, $this->fixture->getMethods());
84
85
        $mock = m::mock(Collection::class);
86
87
        $this->fixture->setMethods($mock);
88
89
        $this->assertSame($mock, $this->fixture->getMethods());
90
    }
91
92
    /**
93
     * @covers ::getInheritedConstants
94
     */
95
    public function testGetInheritedConstantsNoParent()
96
    {
97
        $descriptor = new InterfaceDescriptor();
98
        $this->assertInstanceOf(Collection::class, $descriptor->getInheritedConstants());
99
100
        $descriptor->setParent(new \stdClass());
0 ignored issues
show
new \stdClass() is of type object<stdClass>, 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...
101
        $this->assertInstanceOf(Collection::class, $descriptor->getInheritedConstants());
102
    }
103
104
    /**
105
     * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getSummary
106
     */
107
    public function testSummaryInheritsWhenNoneIsPresent()
108
    {
109
        // Arrange
110
        $summary = 'This is a summary';
111
        $this->fixture->setSummary(null);
112
        $parentInterface = $this->whenFixtureHasParentInterface();
113
        $parentInterface->setSummary($summary);
114
115
        // Act
116
        $result = $this->fixture->getSummary();
117
118
        // Assert
119
        $this->assertSame($summary, $result);
120
    }
121
122
    /**
123
     * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getDescription
124
     */
125
    public function testDescriptionInheritsWhenNoneIsPresent()
126
    {
127
        // Arrange
128
        $description = 'This is a description';
129
        $this->fixture->setDescription(null);
130
        $parentInterface = $this->whenFixtureHasParentInterface();
131
        $parentInterface->setDescription($description);
132
133
        // Act
134
        $result = $this->fixture->getDescription();
135
136
        // Assert
137
        $this->assertSame($description, $result);
138
    }
139
140
    /**
141
     * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getAuthor
142
     */
143
    public function testAuthorTagsInheritWhenNoneArePresent()
144
    {
145
        // Arrange
146
        $authorTagDescriptor = new AuthorDescriptor('author');
147
        $authorCollection = new Collection([$authorTagDescriptor]);
148
        $this->fixture->getTags()->clear();
149
        $parentProperty = $this->whenFixtureHasParentInterface();
150
        $parentProperty->getTags()->set('author', $authorCollection);
151
152
        // Act
153
        $result = $this->fixture->getAuthor();
154
155
        // Assert
156
        $this->assertSame($authorCollection, $result);
157
    }
158
159
    /**
160
     * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getCopyright
161
     */
162
    public function testCopyrightTagsInheritWhenNoneArePresent()
163
    {
164
        // Arrange
165
        $copyrightTagDescriptor = new TagDescriptor('copyright');
166
        $copyrightCollection = new Collection([$copyrightTagDescriptor]);
167
        $this->fixture->getTags()->clear();
168
        $parentProperty = $this->whenFixtureHasParentInterface();
169
        $parentProperty->getTags()->set('copyright', $copyrightCollection);
170
171
        // Act
172
        $result = $this->fixture->getCopyright();
173
174
        // Assert
175
        $this->assertSame($copyrightCollection, $result);
176
    }
177
178
    /**
179
     * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getVersion
180
     */
181
    public function testVersionTagsInheritWhenNoneArePresent()
182
    {
183
        // Arrange
184
        $versionTagDescriptor = new VersionDescriptor('version');
185
        $versionCollection = new Collection([$versionTagDescriptor]);
186
        $this->fixture->getTags()->clear();
187
        $parentProperty = $this->whenFixtureHasParentInterface();
188
        $parentProperty->getTags()->set('version', $versionCollection);
189
190
        // Act
191
        $result = $this->fixture->getVersion();
192
193
        // Assert
194
        $this->assertSame($versionCollection, $result);
195
    }
196
197
    /**
198
     * @covers ::getInheritedConstants
199
     */
200
    public function testGetInheritedConstantsWithClassDescriptorParent()
201
    {
202
        $constantInParent = $this->givenConstantWithName('constant');
203
        $constantInGrandParent = $this->givenConstantWithName('constantInGrandParent');
204
        $constantInParentClass = $this->givenConstantWithName('constantInClass');
205
206
        $parentInterface = new InterfaceDescriptor();
207
        $parentInterface->setConstants(new Collection([$constantInParent]));
208
209
        $parentClass = new ClassDescriptor();
210
        $parentClass->setConstants(new Collection([$constantInParentClass]));
211
212
        $grandParentInterface = new InterfaceDescriptor();
213
        $grandParentInterface->setConstants(new Collection([$constantInGrandParent]));
214
215
        $parentInterface->setParent(new Collection([$grandParentInterface]));
216
        $this->fixture->setParent(new Collection([$parentInterface, $parentClass]));
217
218
        $result = $this->fixture->getInheritedConstants();
219
220
        $this->assertInstanceOf(Collection::class, $result);
221
        $this->assertSame([$constantInParent, $constantInGrandParent], $result->getAll());
222
    }
223
224
    /**
225
     * @covers ::getInheritedMethods
226
     */
227
    public function testRetrievingInheritedMethodsReturnsEmptyCollectionWithoutParent()
228
    {
229
        $inheritedMethods = $this->fixture->getInheritedMethods();
230
        $this->assertInstanceOf(Collection::class, $inheritedMethods);
231
        $this->assertCount(0, $inheritedMethods);
232
    }
233
234
    /**
235
     * @covers ::getInheritedMethods
236
     */
237
    public function testRetrievingInheritedMethodsReturnsCollectionWithParent()
238
    {
239
        $parentDescriptor = new MethodDescriptor();
240
        $parentDescriptor->setName('parent');
241
        $parentDescriptorCollection = new Collection();
242
        $parentDescriptorCollection->add($parentDescriptor);
243
        $parent = new InterfaceDescriptor();
244
        $parent->setMethods($parentDescriptorCollection);
245
        $parentCollection = new Collection();
246
        $parentCollection->add($parent);
247
248
        $grandParentDescriptor = new MethodDescriptor();
249
        $grandParentDescriptor->setName('grandparent');
250
        $grandParentDescriptorCollection = new Collection();
251
        $grandParentDescriptorCollection->add($grandParentDescriptor);
252
        $grandParent = new InterfaceDescriptor();
253
        $grandParent->setMethods($grandParentDescriptorCollection);
254
        $grandParentCollection = new Collection();
255
        $grandParentCollection->add($grandParent);
256
257
        $parent->setParent($grandParentCollection);
258
259
        $this->fixture->setParent($parentCollection);
260
        $result = $this->fixture->getInheritedMethods();
261
262
        $this->assertInstanceOf(Collection::class, $result);
263
264
        $this->assertSame([$parentDescriptor, $grandParentDescriptor], $result->getAll());
265
    }
266
267
    /**
268
     * @return InterfaceDescriptor
269
     */
270
    protected function whenFixtureHasParentInterface()
271
    {
272
        $interface = new InterfaceDescriptor();
273
        $this->fixture->getParent()->set('IA', $interface);
274
275
        return $interface;
276
    }
277
278
    private function givenConstantWithName(string $name): ConstantDescriptor
279
    {
280
        $constantInParent = new ConstantDescriptor();
281
        $constantInParent->setName($name);
282
283
        return $constantInParent;
284
    }
285
}
286