Issues (38)

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.

Unit/Symfony2/EntitySimpleGetterSetterTest.php (5 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 MS\PHPMD\Tests\Unit\Symfony2;
4
5
use MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter;
6
use MS\PHPMD\Tests\Unit\AbstractApplyTest;
7
8
/**
9
 * Class EntitySimpleGetterSetterTest
10
 *
11
 * @package MS\PHPMD\Tests\Unit\Symfony2
12
 */
13
class EntitySimpleGetterSetterTest extends AbstractApplyTest
14
{
15
    const CLASS_NAME = 'TestEntity';
16
17
    /**
18
     * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter
19
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
20
     */
21
    public function testApplyNoEntity()
22
    {
23
        $node = \Mockery::mock('PHPMD\Node\ClassNode');
24
        $node->shouldReceive('getDocComment')->andReturn('');
25
        $node->shouldReceive('isAbstract')->andReturn(false);
26
27
        $this->assertRule($node, 0);
28
29
        $node = \Mockery::mock('PHPMD\Node\ClassNode');
30
        $node->shouldReceive('getDocComment')->andReturn('* @covers ORM\Entity');
31
        $node->shouldReceive('isAbstract')->andReturn(false);
32
33
        $this->assertRule($node, 0);
34
    }
35
36
    /**
37
     * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter
38
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
39
     */
40 View Code Duplication
    public function testValidEntity()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $methodNode = $this->getMethodNode(self::CLASS_NAME, 'getData', [
43
            'ScopeStatement' => [],
44
            'ReturnStatement' => array_fill(0, 1, $this->getNode('return')),
45
            'Variable' => array_fill(0, 1, $this->getNode('$this')),
46
        ]);
47
        $classNode = $this->getClassNode([$methodNode]);
48
49
        $this->assertRule($classNode, 0);
50
    }
51
52
    /**
53
     * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter
54
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
55
     */
56 View Code Duplication
    public function testValidEntityWithWhitelist()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
    {
58
        $methodNode = $this->getMethodNode(self::CLASS_NAME, '__construct');
59
        $classNode = $this->getClassNode([$methodNode]);
60
61
        $this->assertRule($classNode, 0);
62
    }
63
64
    /**
65
     * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter
66
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
67
     */
68 View Code Duplication
    public function testWrongMethodPrefix()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $methodNode = $this->getMethodNode(self::CLASS_NAME, 'doSomething');
71
        $classNode = $this->getClassNode([$methodNode]);
72
73
        $this->assertRule($classNode, 1);
74
    }
75
76
    /**
77
     * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter
78
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
79
     */
80
    public function testForbiddenScope()
81
    {
82
        $methodNode = $this->getMethodNode(self::CLASS_NAME, 'getData', [
83
            'ScopeStatement' => array_fill(0, 1, $this->getNode('if')),
84
        ]);
85
        $classNode = $this->getClassNode([$methodNode]);
86
87
        $this->assertRule($classNode, 1);
88
    }
89
90
    /**
91
     * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter
92
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
93
     */
94 View Code Duplication
    public function testMultipleReturns()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $methodNode = $this->getMethodNode(self::CLASS_NAME, 'getData', [
97
            'ScopeStatement' => [],
98
            'ReturnStatement' => array_fill(0, 2, $this->getNode('return')),
99
            'Variable' => array_fill(0, 1, $this->getNode('$this')),
100
        ]);
101
        $classNode = $this->getClassNode([$methodNode]);
102
103
        $this->assertRule($classNode, 1);
104
    }
105
106
    /**
107
     * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter
108
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
109
     */
110
    public function testRelationReturnToThis()
111
    {
112
        $methodNode = $this->getMethodNode(self::CLASS_NAME, 'getData', [
113
            'ScopeStatement' => [],
114
            'ReturnStatement' => [],
115
            'Variable' => array_fill(0, 2, $this->getNode('$this')),
116
        ]);
117
        $classNode = $this->getClassNode([$methodNode]);
118
119
        $this->assertRule($classNode, 1);
120
121
        $methodNode = $this->getMethodNode(self::CLASS_NAME, 'getData', [
122
            'ScopeStatement' => [],
123
            'ReturnStatement' => array_fill(0, 1, $this->getNode('return')),
124
            'Variable' => array_fill(0, 3, $this->getNode('$this')),
125
        ]);
126
        $classNode = $this->getClassNode([$methodNode]);
127
128
        $this->assertRule($classNode, 1);
129
    }
130
131
    /**
132
     * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter
133
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
134
     */
135 View Code Duplication
    public function testAbstractClass()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
136
    {
137
        $node = \Mockery::mock('PHPMD\Node\ClassNode');
138
        $node->shouldReceive('getDocComment')->andReturn('');
139
        $node->shouldReceive('isAbstract')->andReturn(true);
140
141
        $this->assertRule($node, 0);
142
    }
143
144
    /**
145
     * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter
146
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
147
     */
148
    public function testForceClassIsAnEntity()
149
    {
150
        $methodNode = $this->getMethodNode(self::CLASS_NAME, 'getData', [
151
            'ScopeStatement' => [],
152
            'ReturnStatement' => array_fill(0, 1, $this->getNode('return')),
153
            'Variable' => array_fill(0, 3, $this->getNode('$this')),
154
        ]);
155
156
        $classNode = \Mockery::mock('PHPMD\Node\ClassNode');
157
        $classNode->shouldReceive('getDocComment')->andReturn('* @isEntity');
158
        $classNode->shouldReceive('getImage')->andReturn(self::CLASS_NAME);
159
        $classNode->shouldReceive('isAbstract')->andReturn(true);
160
        $classNode->shouldReceive('getMethods')->andReturn([$methodNode]);
161
162
        $this->assertRule($classNode, 1);
163
    }
164
165
    /**
166
     * @param array $methodNodes
167
     *
168
     * @return \Mockery\MockInterface
169
     */
170
    private function getClassNode(array $methodNodes)
171
    {
172
        $classNode = \Mockery::mock('PHPMD\Node\ClassNode');
173
        $classNode->shouldReceive('getDocComment')->andReturn('* @ORM\Entity()');
174
        $classNode->shouldReceive('getImage')->andReturn(self::CLASS_NAME);
175
        $classNode->shouldReceive('isAbstract')->andReturn(false);
176
        $classNode->shouldReceive('getMethods')->andReturn($methodNodes);
177
178
        return $classNode;
179
    }
180
181
    /**
182
     * @return EntitySimpleGetterSetter
183
     */
184
    protected function getRule()
185
    {
186
        $rule = new EntitySimpleGetterSetter();
187
        $rule->addProperty('delimiter', ',');
188
        $rule->addProperty('prefixes', 'get,set');
189
        $rule->addProperty('whitelist', '__construct');
190
        $rule->addProperty('entityRegex', '(\*\s*@\S*Entity)i');
191
        $rule->addProperty('classIsEntityRegex', '(\*\s*@isEntity)i');
192
193
        return $rule;
194
    }
195
}
196