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.

Compiler/Pass/ExampleTagsEnricherTest.php (3 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\Compiler\Pass;
4
5
use Mockery as m;
6
use phpDocumentor\Descriptor\Example\Finder;
7
use phpDocumentor\Reflection\DocBlock\ExampleFinder;
8
9
/**
10
 * Tests the \phpDocumentor\Compiler\Pass\ExampleTagsEnricher class.
11
 */
12
class ExampleTagsEnricherTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
13
{
14
    /** @var Finder|m\MockInterface */
15
    private $finderMock;
16
17
    /** @var ExampleTagsEnricher */
18
    private $fixture;
19
20
    /**
21
     * Initializes the fixture and its dependencies.
22
     */
23
    protected function setUp()
24
    {
25
        $this->finderMock = m::mock(ExampleFinder::class);
26
        $this->fixture = new ExampleTagsEnricher($this->finderMock);
27
    }
28
29
    /**
30
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::getDescription
31
     */
32
    public function testDescriptionName()
33
    {
34
        $this->assertSame('Enriches inline example tags with their sources', $this->fixture->getDescription());
35
    }
36
37
    /**
38
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::__construct
39
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::execute
40
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::replaceInlineExamples
41
     */
42
    public function testReplaceExampleTagReturnsDescriptionIfItContainsNoExampleTags()
43
    {
44
        $description = 'This is a description';
45
46
        $descriptor = $this->givenAChildDescriptorWithDescription($description);
47
        $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $description);
48
49
        $project = $this->givenAProjectDescriptorWithChildDescriptors([$descriptor]);
50
51
        $this->fixture->execute($project);
52
53
        $this->assertTrue(true);
54
    }
55
56
    /**
57
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::__construct
58
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::execute
59
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::replaceInlineExamples
60
     */
61
    public function testReplaceExampleTagWithExampleContents()
62
    {
63
        $exampleText = 'Example Text';
64
        $description = 'This is a description with {@example example2.txt} without description.';
65
        $expected = "This is a description with `${exampleText}` without description.";
66
67
        $descriptor = $this->givenAChildDescriptorWithDescription($description);
68
        $this->whenExampleTxtFileContains($exampleText);
69
        $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected);
70
71
        $project = $this->givenAProjectDescriptorWithChildDescriptors([$descriptor]);
72
73
        $this->fixture->execute($project);
74
75
        $this->assertTrue(true);
76
    }
77
78
    /**
79
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::__construct
80
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::execute
81
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::replaceInlineExamples
82
     */
83
    public function testReplaceExampleTagWithExampleContentsAndDescription()
84
    {
85
        $exampleText = 'Example Text';
86
        $description = 'This is a description with {@example example.txt including description}.';
87
        $expected = "This is a description with *including description*`${exampleText}`.";
88
89
        $descriptor = $this->givenAChildDescriptorWithDescription($description);
90
        $this->whenExampleTxtFileContains($exampleText);
91
        $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected);
92
93
        $project = $this->givenAProjectDescriptorWithChildDescriptors([$descriptor]);
94
95
        $this->fixture->execute($project);
96
97
        $this->assertTrue(true);
98
    }
99
100
    /**
101
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::__construct
102
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::execute
103
     * @covers \phpDocumentor\Compiler\Pass\ExampleTagsEnricher::replaceInlineExamples
104
     */
105
    public function testReplacingOfDescriptionHappensOncePerExample()
106
    {
107
        $exampleText = 'Example Text';
108
        $description = 'This is a description with {@example example.txt} and {@example example.txt}.';
109
        $expected = "This is a description with `${exampleText}` and `${exampleText}`.";
110
111
        $descriptor = $this->givenAChildDescriptorWithDescription($description);
112
        $this->whenExampleTxtFileContainsAndMustBeCalledOnlyOnce($exampleText);
113
        $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected);
114
115
        $project = $this->givenAProjectDescriptorWithChildDescriptors([$descriptor]);
116
117
        $this->fixture->execute($project);
118
119
        $this->assertTrue(true);
120
    }
121
122
    /**
123
     * Returns a mocked Descriptor with its description set to the given value.
124
     *
125
     * @param string $description
126
     *
127
     * @return m\MockInterface
128
     */
129
    private function givenAChildDescriptorWithDescription($description)
130
    {
131
        $descriptor = m::mock('phpDocumentor\Descriptor\DescriptorAbstract');
132
        $descriptor->shouldReceive('getDescription')->andReturn($description);
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...
133
134
        return $descriptor;
135
    }
136
137
    /**
138
     * Returns a mocked Project Descriptor.
139
     *
140
     * @param m\MockInterface[] $descriptors
141
     *
142
     * @return m\MockInterface
143
     */
144
    private function givenAProjectDescriptorWithChildDescriptors($descriptors)
145
    {
146
        $projectDescriptor = m::mock('phpDocumentor\Descriptor\ProjectDescriptor');
147
        $projectDescriptor->shouldReceive('getIndexes->get')->with('elements')->andReturn($descriptors);
148
149
        return $projectDescriptor;
150
    }
151
152
    /**
153
     * Verifies if the given descriptor's setDescription method is called with the given value.
154
     *
155
     * @param m\MockInterface $descriptor
156
     * @param string          $expected
157
     */
158
    public function thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected)
159
    {
160
        $descriptor->shouldReceive('setDescription')->with($expected);
161
    }
162
163
    /**
164
     * Instructs the finder mock to return the given text when an example is requested.
165
     *
166
     * @param string $exampleText
167
     */
168
    private function whenExampleTxtFileContains($exampleText)
169
    {
170
        $this->finderMock->shouldReceive('find')->andReturn($exampleText);
0 ignored issues
show
The method shouldReceive does only exist in Mockery\MockInterface, but not in phpDocumentor\Descriptor\Example\Finder.

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...
171
    }
172
173
    /**
174
     * Instructs the finder mock to return the given text when an example is requested and verifies that that is only
175
     * done once.
176
     *
177
     * @param string $exampleText
178
     */
179
    private function whenExampleTxtFileContainsAndMustBeCalledOnlyOnce($exampleText)
180
    {
181
        $this->finderMock->shouldReceive('find')->once()->andReturn($exampleText);
0 ignored issues
show
The method shouldReceive does only exist in Mockery\MockInterface, but not in phpDocumentor\Descriptor\Example\Finder.

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...
182
    }
183
}
184