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 Almendra\Http; |
||
4 | |||
5 | use Almendra\Http\Interfaces\ServerInterface; |
||
6 | |||
7 | /** |
||
8 | * A wrapper for the superglobals $_SERVER, $_GET and $_POST. |
||
9 | * |
||
10 | * @package Almendra\PSR7 |
||
11 | * @author Richard Trujillo Torres <[email protected]> |
||
12 | */ |
||
13 | class Server implements ServerInterface |
||
14 | { |
||
15 | /** |
||
16 | * Retrieves a value defined in the superglobal $_SERVER. |
||
17 | * |
||
18 | * @param string $value The key's name. |
||
19 | * @return string|mixed |
||
20 | */ |
||
21 | public static function getValue($value, $default = '') |
||
0 ignored issues
–
show
|
|||
22 | { |
||
23 | if (array_key_exists($value, $_SERVER)) { |
||
24 | return $_SERVER[$value]; |
||
25 | } |
||
26 | |||
27 | return $default; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Retrieves all values defined in the superglobal $_SERVER. |
||
32 | * |
||
33 | * @return string|mixed |
||
34 | */ |
||
35 | public static function getValues() |
||
0 ignored issues
–
show
getValues 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);
}
}
![]() |
|||
36 | { |
||
37 | return $_SERVER; |
||
38 | } |
||
39 | |||
40 | |||
41 | /** |
||
42 | * Returns a value from the $_GET superglobal. |
||
43 | * Null if none exists. |
||
44 | * |
||
45 | * @param string $name The value's name |
||
46 | * @return mixed |
||
47 | */ |
||
48 | public static function get($name) |
||
0 ignored issues
–
show
get uses the super-global variable $_GET 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);
}
}
![]() |
|||
49 | { |
||
50 | if (isset($_GET[$name])) { |
||
51 | return $_GET[$name]; |
||
52 | } |
||
53 | |||
54 | return null; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Returns all values from the $_GET superglobal. |
||
59 | * Null if none exists. |
||
60 | * |
||
61 | * @param array $values An array containing value names to be retrieved |
||
62 | * @return mixed |
||
63 | */ |
||
64 | View Code Duplication | public static function gets(array $values = null) |
|
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. ![]() gets uses the super-global variable $_GET 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);
}
}
![]() |
|||
65 | { |
||
66 | $fields = []; |
||
67 | if (isset($values) && null !== $values) { |
||
68 | foreach ($values as $name) { |
||
69 | $fields[] = self::get($name); |
||
70 | } |
||
71 | |||
72 | return $fields; |
||
73 | } |
||
74 | |||
75 | return isset($_GET) ? $_GET : null; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Returns a value from the $_POST superglobal. |
||
80 | * Null if none exists. |
||
81 | * |
||
82 | * @param string $name The value's name |
||
83 | * @return mixed |
||
84 | */ |
||
85 | public static function post($name) |
||
0 ignored issues
–
show
post uses the super-global variable $_POST 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);
}
}
![]() |
|||
86 | { |
||
87 | if (isset($_POST[$name])) { |
||
88 | return $_POST[$name]; |
||
89 | } |
||
90 | |||
91 | return null; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Returns all values from the $_POST superglobal. |
||
96 | * Null if none exists. |
||
97 | * |
||
98 | * @param array $values |
||
99 | * @return mixed |
||
100 | */ |
||
101 | View Code Duplication | public static function posts(array $values = null) |
|
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. ![]() posts uses the super-global variable $_POST 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);
}
}
![]() |
|||
102 | { |
||
103 | $fields = []; |
||
104 | if (isset($values) && null !== $values) { |
||
105 | foreach ($values as $name) { |
||
106 | $fields[] = self::post($name); |
||
107 | } |
||
108 | |||
109 | return $fields; |
||
110 | } |
||
111 | |||
112 | return isset($_POST) ? $_POST : null; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Returns a value from the $_FILES superglobal. |
||
117 | * Null if none exists. |
||
118 | * |
||
119 | * @param string $name The value's name |
||
120 | * @return mixed |
||
121 | */ |
||
122 | public static function file($name) |
||
0 ignored issues
–
show
file uses the super-global variable $_FILES 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);
}
}
![]() |
|||
123 | { |
||
124 | if (isset($_FILES[$name])) { |
||
125 | return $_FILES[$name]; |
||
126 | } |
||
127 | |||
128 | return null; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Returns all values from the $_FILES superglobal. |
||
133 | * Null if none exists. |
||
134 | * |
||
135 | * @param array $values An array containing value names to be retrieved |
||
136 | * @return mixed |
||
137 | */ |
||
138 | View Code Duplication | public static function files(array $values = null) |
|
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. ![]() files uses the super-global variable $_FILES 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 | $fields = []; |
||
141 | if (isset($values) && null !== $values) { |
||
142 | foreach ($values as $name) { |
||
143 | $fields[] = self::file($name); |
||
144 | } |
||
145 | |||
146 | return $fields; |
||
147 | } |
||
148 | |||
149 | return isset($_FILES) ? $_FILES : null; |
||
150 | } |
||
151 | |||
152 | } |
||
153 |
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: