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 OcLegacy\Template; |
||
4 | |||
5 | trait LegacyTemplateTrait |
||
6 | { |
||
7 | /** |
||
8 | * @param int $menu |
||
9 | */ |
||
10 | protected function setMenu($menu) |
||
0 ignored issues
–
show
|
|||
11 | { |
||
12 | $GLOBALS['tpl']->menuitem = $menu; |
||
13 | } |
||
14 | |||
15 | /** |
||
16 | * @param string $title |
||
17 | */ |
||
18 | protected function setTitle($title) |
||
0 ignored issues
–
show
setTitle uses the super-global variable $GLOBALS 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...
|
|||
19 | { |
||
20 | $GLOBALS['tpl']->title = $title; |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @param string $url |
||
25 | */ |
||
26 | protected function setTarget($url) |
||
0 ignored issues
–
show
setTarget uses the super-global variable $GLOBALS 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...
|
|||
27 | { |
||
28 | $GLOBALS['tpl']->target = $url; |
||
29 | } |
||
30 | } |
||
31 |
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: