setDefaultTarget 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:
// BadclassRouter{publicfunctiongenerate($path){return$_SERVER['HOST'].$path;}}// BetterclassRouter{private$host;publicfunction__construct($host){$this->host=$host;}publicfunctiongenerate($path){return$this->host.$path;}}classController{publicfunctionmyAction(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% 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.
Loading history...
42
public function setAssets($assets)
43
{
44
// skip checks for performance
45
// if (!is_array($assets)) {
46
// throw new \Exception('Assets of '.static::class.' must be an array');
47
// }
48
// if (count($assets) != count($assets, COUNT_RECURSIVE)) {
49
// throw new \Exception('Assets of '.static::class.' must be a one-dimensional array');
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: