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/Transformer/Router/RendererTest.php (11 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 declare(strict_types=1);
2
3
/**
4
 * This file is part of phpDocumentor.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @copyright 2010-2018 Mike van Riel<[email protected]>
10
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
11
 * @link      http://phpdoc.org
12
 */
13
14
namespace phpDocumentor\Transformer\Router;
15
16
use Mockery as m;
17
use phpDocumentor\Descriptor\Collection;
18
use phpDocumentor\Descriptor\Type\CollectionDescriptor;
19
20
/**
21
 * Test class for phpDocumentor\Transformer\Router\Renderer
22
 *
23
 * @coversDefaultClass \phpDocumentor\Transformer\Router\Renderer
24
 * @covers ::<private>
25
 */
26
final class RendererTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
27
{
28
    /** @var Queue */
29
    private $queue;
30
31
    /** @var Renderer */
32
    private $renderer;
33
34
    protected function setUp()
35
    {
36
        $this->queue = m::mock('phpDocumentor\Transformer\Router\Queue');
37
38
        $this->renderer = new Renderer($this->queue);
39
    }
40
41
    /**
42
     * @covers \phpDocumentor\Transformer\Router\Renderer::__construct
43
     * @covers \phpDocumentor\Transformer\Router\Renderer::getDestination
44
     * @covers \phpDocumentor\Transformer\Router\Renderer::setDestination
45
     */
46
    public function testGetAndSetDestination(): void
47
    {
48
        $this->renderer->setDestination('destination');
49
50
        $this->assertSame('destination', $this->renderer->getDestination());
51
    }
52
53
    /**
54
     * @covers ::render
55
     * @covers ::convertToRootPath
56
     */
57
    public function testRenderWithFqsenAndRepresentationUrl(): void
58
    {
59
        $rule = $this->givenARule('/classes/My.Namespace.Class.html');
60
        $this->queue->shouldReceive('match')->andReturn($rule);
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<phpDocumentor\Transformer\Router\Queue>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
62
        $result = $this->renderer->render('\My\Namespace\Class', 'url');
63
64
        $this->assertSame('classes/My.Namespace.Class.html', $result);
65
    }
66
67
    /**
68
     * @covers ::render
69
     * @covers ::convertToRootPath
70
     */
71
    public function testRenderWithCollectionOfFqsensAndRepresentationUrl(): void
72
    {
73
        $rule = $this->givenARule('/classes/My.Namespace.Class.html');
74
        $this->queue->shouldReceive('match')->andReturn($rule);
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<phpDocumentor\Transformer\Router\Queue>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
76
        $this->renderer->setDestination(str_replace('/', DIRECTORY_SEPARATOR, '/root/of/project'));
77
        $collection = new Collection(['\My\Namespace\Class']);
78
        $result = $this->renderer->render($collection, 'url');
79
80
        $this->assertSame(['../../../classes/My.Namespace.Class.html'], $result);
81
    }
82
83
    /**
84
     * @covers ::render
85
     * @covers ::convertToRootPath
86
     */
87
    public function testRenderWithUrlAndNoRuleMatch(): void
88
    {
89
        $rule = $this->givenARule('@');
90
        $this->queue->shouldReceive('match')->with('file://phpdoc')->andReturn($rule);
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<phpDocumentor\Transformer\Router\Queue>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
        $this->queue->shouldReceive('match')->with('@')->andReturn(null);
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<phpDocumentor\Transformer\Router\Queue>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
93
        $result = $this->renderer->render('file://phpdoc', 'url');
94
95
        $this->assertNull($result);
96
    }
97
98
    /**
99
     * @covers ::convertToRootPath
100
     */
101
    public function testConvertToRootPathWithUrlAndAtSignInRelativePath(): void
102
    {
103
        $rule = $this->givenARule('@Class::$property');
104
        $this->queue->shouldReceive('match')->with('@Class::$property')->andReturn($rule);
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<phpDocumentor\Transformer\Router\Queue>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
105
106
        $result = $this->renderer->convertToRootPath('@Class::$property');
107
108
        $this->assertSame('@Class::$property', $result);
109
    }
110
111
    /**
112
     * @covers ::render
113
     * @covers ::convertToRootPath
114
     */
115
    public function testRenderWithCollectionDescriptorWithNameIsNotArrayAndRepresentationUrl(): void
116
    {
117
        $rule = $this->givenARule('ClassDescriptor');
118
        $this->queue->shouldReceive('match')->andReturn($rule);
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<phpDocumentor\Transformer\Router\Queue>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
119
120
        $collectionDescriptor = $this->givenACollectionDescriptor('class');
121
        $collectionDescriptor->setKeyTypes(['ClassDescriptor']);
122
        $result = $this->renderer->render($collectionDescriptor, 'url');
123
124
        $this->assertSame('ClassDescriptor&lt;ClassDescriptor,ClassDescriptor&gt;', $result);
125
    }
126
127
    /**
128
     * @covers ::render
129
     * @covers ::convertToRootPath
130
     */
131
    public function testRenderWithCollectionDescriptorWithNameIsArrayAndRepresentationUrl(): void
132
    {
133
        $rule = $this->givenARule('ClassDescriptor');
134
        $this->queue->shouldReceive('match')->andReturn($rule);
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<phpDocumentor\Transformer\Router\Queue>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135
136
        $collectionDescriptor = $this->givenACollectionDescriptor('array');
137
        $result = $this->renderer->render($collectionDescriptor, 'url');
138
139
        $this->assertSame('ClassDescriptor[]', $result);
140
    }
141
142
    /**
143
     * @covers ::render
144
     */
145
    public function testRenderWithFqsenAndRepresentationClassShort(): void
146
    {
147
        $rule = $this->givenARule('/classes/My.Namespace.Class.html');
148
        $this->queue->shouldReceive('match')->andReturn($rule);
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<phpDocumentor\Transformer\Router\Queue>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
149
150
        $result = $this->renderer->render('\My\Namespace\Class', 'class:short');
151
152
        $this->assertSame('<a href="classes/My.Namespace.Class.html">Class</a>', $result);
153
    }
154
155
    /**
156
     * @covers ::render
157
     * @dataProvider provideUrls
158
     */
159
    public function testRenderWithUrl(string $url): void
160
    {
161
        $rule = $this->givenARule($url);
162
        $this->queue->shouldReceive('match')->andReturn($rule);
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<phpDocumentor\Transformer\Router\Queue>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
163
164
        $result = $this->renderer->render($url, 'url');
165
166
        $this->assertSame($url, $result);
167
    }
168
169
    private function givenARule(string $returnValue): Rule
170
    {
171
        $rule = m::mock('phpDocumentor\Transformer\Router\Rule');
172
        $rule->shouldReceive('generate')->andReturn($returnValue);
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...
173
174
        return $rule;
175
    }
176
177
    private function givenACollectionDescriptor(string $name): CollectionDescriptor
178
    {
179
        $classDescriptor = m::mock('phpDocumentor\Descriptor\ClassDescriptor');
180
        $classDescriptor->shouldReceive('getName')->andReturn($name);
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...
181
        $collectionDescriptor = new CollectionDescriptor($classDescriptor);
182
        $collectionDescriptor->setTypes(['ClassDescriptor']);
183
        return $collectionDescriptor;
184
    }
185
186
    public function provideUrls(): array
187
    {
188
        return [
189
            ['http://phpdoc.org'],
190
            ['https://phpdoc.org'],
191
            ['ftp://phpdoc.org'],
192
        ];
193
    }
194
}
195