This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 KochTest\Http; |
||
4 | |||
5 | use Koch\Http\HttpRequest; |
||
6 | |||
7 | class HttpRequestTest extends \PHPUnit_Framework_TestCase |
||
8 | { |
||
9 | /** |
||
10 | * @var HttpRequest |
||
11 | */ |
||
12 | protected $request; |
||
13 | |||
14 | /** |
||
15 | * Sets up the fixture, for example, opens a network connection. |
||
16 | * This method is called before a test is executed. |
||
17 | */ |
||
18 | public function setUp() |
||
19 | { |
||
20 | $this->request = new HttpRequest(); |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Tears down the fixture, for example, closes a network connection. |
||
25 | * This method is called after a test is executed. |
||
26 | */ |
||
27 | public function tearDown() |
||
28 | { |
||
29 | unset($this->request); |
||
30 | } |
||
31 | |||
32 | public function testMethodcontructor_unsetsGlobalVars() |
||
0 ignored issues
–
show
testMethodcontructor_unsetsGlobalVars uses the super-global variable $_REQUEST which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
33 | { |
||
34 | $this->assertFalse(isset($_REQUEST)); |
||
35 | |||
36 | // Undefined variable: GLOBALS |
||
37 | // it's not possible to unset globals - phpunit side effect? |
||
38 | //$this->assertFalse(isset($GLOBALS)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
90% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
39 | } |
||
40 | |||
41 | public function testMethodgetRequestMethod() |
||
0 ignored issues
–
show
testMethodgetRequestMethod uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
42 | { |
||
43 | $_SERVER['REQUEST_METHOD'] = 'someMethod'; |
||
44 | $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'OverrideMethodName'; |
||
45 | $this->assertEquals('OverrideMethodName', HttpRequest::getRequestMethod()); |
||
46 | |||
47 | unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); |
||
48 | $_SERVER['REQUEST_METHOD'] = 'HEAD'; |
||
49 | $this->assertEquals('GET', HttpRequest::getRequestMethod()); |
||
50 | |||
51 | $this->request->setRequestMethod('BEAVIS'); |
||
52 | $this->assertEquals('BEAVIS', HttpRequest::getRequestMethod()); |
||
53 | |||
54 | unset($_SERVER['REQUEST_METHOD']); |
||
55 | } |
||
56 | |||
57 | public function testMethodsetRequestMethod() |
||
58 | { |
||
59 | $this->request->setRequestMethod('BUTTHEAD'); |
||
60 | $this->assertEquals('BUTTHEAD', HttpRequest::getRequestMethod()); |
||
61 | } |
||
62 | |||
63 | public function testMethodisGET() |
||
64 | { |
||
65 | $this->request->setRequestMethod('GET'); |
||
66 | $this->assertTrue($this->request->isGet()); |
||
67 | } |
||
68 | |||
69 | public function testMethodisPOST() |
||
70 | { |
||
71 | $this->request->setRequestMethod('POST'); |
||
72 | $this->assertTrue($this->request->isPost()); |
||
73 | } |
||
74 | |||
75 | public function testMethodisPUT() |
||
76 | { |
||
77 | $this->request->setRequestMethod('PUT'); |
||
78 | $this->assertTrue($this->request->isPut()); |
||
79 | } |
||
80 | |||
81 | public function testMethodisDELETE() |
||
82 | { |
||
83 | $this->request->setRequestMethod('DELETE'); |
||
84 | $this->assertTrue($this->request->isDelete()); |
||
85 | } |
||
86 | |||
87 | public function testMethodisAjax() |
||
0 ignored issues
–
show
testMethodisAjax uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
88 | { |
||
89 | $isAjax = $this->request->isAjax(); |
||
90 | $this->assertFalse($isAjax); |
||
91 | |||
92 | $_SERVER['X-Requested-With'] = 'XMLHttpRequest'; |
||
93 | $isAjax = $this->request->isAjax(); |
||
94 | $this->assertTrue($isAjax); |
||
95 | |||
96 | $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; |
||
97 | $isAjax = $this->request->isAjax(); |
||
98 | $this->assertTrue($isAjax); |
||
99 | |||
100 | unset($_SERVER['X-Requested-With']); |
||
101 | unset($_SERVER['HTTP_X_REQUESTED_WITH']); |
||
102 | } |
||
103 | |||
104 | /*public function testMethodgetPost() |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
57% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
105 | { |
||
106 | $_POST['POST-ABC'] = '123'; |
||
107 | $result = $this->request->getPost(); |
||
108 | $this->assertArrayHasKey('POST-ABC', $result); |
||
109 | |||
110 | // ArrayAccess via offsetExists |
||
111 | $this->assertEquals($this->request['POST-ABC'], '123'); |
||
112 | } |
||
113 | |||
114 | public function testMethodgetGet() |
||
115 | { |
||
116 | $_GET['GET-ABC'] = '123'; |
||
117 | $result = $this->request->getGET(); |
||
118 | $this->assertArrayHasKey('GETABC', $result); |
||
119 | }*/ |
||
120 | |||
121 | public function testMethodgetServerProtocol() |
||
0 ignored issues
–
show
testMethodgetServerProtocol uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
122 | { |
||
123 | $this->assertEquals($this->request->getServerProtocol(), 'http://'); |
||
124 | |||
125 | $_SERVER['HTTPS'] = 'on'; |
||
126 | $this->assertEquals($this->request->getServerProtocol(), 'https://'); |
||
127 | } |
||
128 | |||
129 | public function testMethodIsSecure() |
||
0 ignored issues
–
show
testMethodIsSecure uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
130 | { |
||
131 | $_SERVER['HTTPS'] = 'NO'; |
||
132 | $this->assertFalse($this->request->isSecure()); |
||
133 | |||
134 | $_SERVER['HTTPS'] = '1'; |
||
135 | $this->assertTrue($this->request->isSecure()); |
||
136 | } |
||
137 | |||
138 | public function testMethodgetBaseURL() |
||
0 ignored issues
–
show
testMethodgetBaseURL uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
139 | { |
||
140 | $_SERVER['HTTPS'] = 'off'; |
||
141 | $_SERVER['SERVER_NAME'] = 'localhost'; |
||
142 | $_SERVER['SERVER_PORT'] = 80; |
||
143 | $this->assertEquals($this->request->getBaseURL(), 'http://localhost'); |
||
144 | |||
145 | /*$_SERVER['HTTPS'] = 'on'; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
64% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
146 | $_SERVER['SERVER_NAME'] = 'localhost'; |
||
147 | $_SERVER['SERVER_PORT'] = 123; |
||
148 | $this->assertEquals($this->request->getBaseURL(), 'https://localhost:123'); |
||
149 | |||
150 | $_SERVER['HTTPS'] = 'on'; |
||
151 | $_SERVER['SERVER_NAME'] = 'localhost'; |
||
152 | $_SERVER['SERVER_PORT'] = 443; |
||
153 | $this->assertEquals($this->request->getBaseURL(), 'https://localhost');*/ |
||
154 | } |
||
155 | |||
156 | public function testMethodgetServerName() |
||
0 ignored issues
–
show
testMethodgetServerName uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
157 | { |
||
158 | $name = 'ServerName'; |
||
159 | $_SERVER['SERVER_NAME'] = $name; |
||
160 | $this->assertEquals($this->request->getServerName(), $name); |
||
161 | } |
||
162 | } |
||
163 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.