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 Widget { |
||
| 5 | |||
| 6 | public static $js; |
||
| 7 | public static $css; |
||
| 8 | private static $config; |
||
| 9 | private static $app; |
||
| 10 | private static $view; |
||
| 11 | private static $property; |
||
| 12 | private static $path; |
||
| 13 | private static $uri; |
||
|
0 ignored issues
–
show
|
|||
| 14 | |||
| 15 | public function __construct(){ |
||
|
0 ignored issues
–
show
__construct 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...
|
|||
| 16 | # Config |
||
| 17 | self::$config = (new Config)->get(); |
||
| 18 | # Url |
||
| 19 | self::$path = explode('/',parse_url(urldecode($_SERVER['REQUEST_URI']))['path']); |
||
| 20 | foreach(self::$path as $key=>$value){ |
||
| 21 | $value = trim($value); |
||
| 22 | if(empty($value)) unset(self::$path[$key]); |
||
| 23 | } |
||
| 24 | self::$path = array_values(self::$path); |
||
| 25 | # Application |
||
| 26 | self::$app = new Application; |
||
| 27 | # View |
||
| 28 | self::$view = new View; |
||
| 29 | # Js |
||
| 30 | self::$js = new Js; |
||
| 31 | # Css |
||
| 32 | self::$css = new Css; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function __get($name){ |
||
| 36 | self::$property= $name; |
||
| 37 | return new self; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function __call($_name,$value){ |
||
| 41 | if(isset($value[0]) && !empty($value[0]) && is_array($value[0])) extract($value[0]); |
||
| 42 | $file = self::$config['core']['widget'].'/'.self::$property.'/'.$_name.'.phtml'; |
||
| 43 | if(is_file($file)) require($file); |
||
| 44 | } |
||
| 45 | |||
| 46 | } |
||
| 47 | ?> |
||
| 48 |
This check marks private properties in classes that are never used. Those properties can be removed.