xezzus /
humanity
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace humanity; |
||
| 3 | |||
| 4 | class Uri { |
||
| 5 | |||
| 6 | private $requestUri = ''; |
||
| 7 | |||
| 8 | public function __construct(){ |
||
|
0 ignored issues
–
show
|
|||
| 9 | $this->requestUri = $_SERVER['REQUEST_URI']; |
||
| 10 | $tmp = explode('/',$this->requiestUri); |
||
|
0 ignored issues
–
show
The property
requiestUri does not seem to exist. Did you mean requestUri?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 11 | foreach($tmp as $key=>$value){ |
||
| 12 | $value = trim($value); |
||
| 13 | if(empty($value)) unset($tmp[$key]); |
||
| 14 | else $tmp[$key] = $value; |
||
| 15 | } |
||
| 16 | $tmp = array_values($tmp); |
||
| 17 | $this->requestUri = $tmp; |
||
|
0 ignored issues
–
show
It seems like
$tmp of type array<integer,?> is incompatible with the declared type string of property $requestUri.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 18 | } |
||
| 19 | |||
| 20 | public function full(){ |
||
| 21 | return '/'.implode('/',$this->requestUri); |
||
| 22 | } |
||
| 23 | |||
| 24 | public function part($number){ |
||
| 25 | if(isset($this->requestUri[$number])) return (string) urldecode($this->requestUri[$number]); |
||
| 26 | else return ''; |
||
| 27 | } |
||
| 28 | |||
| 29 | public function host(){ |
||
|
0 ignored issues
–
show
host 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);
}
}
Loading history...
|
|||
| 30 | return parse_url('http://'.$_SERVER['HTTP_HOST'])['host']; |
||
| 31 | } |
||
| 32 | |||
| 33 | } |
||
| 34 | ?> |
||
| 35 |
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: