Completed
Push — master ( f81666...55a9f3 )
by Alexey
05:42
created

Open   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A rowButton() 0 11 4
1
<?php
2
3
/**
4
 * Data manager open action
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2016 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Ui\DataManager\Action;
13
14
class Open extends \Ui\DataManager\Action
15
{
16
    public static $name = 'Просмотр';
17
    public static $groupAction = false;
18
    public static $rowAction = true;
19
20
    public static function rowButton($dataManager, $item, $params, $actionParams)
1 ignored issue
show
Coding Style introduced by
rowButton 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...
21
    {
22
        if (\App::$cur->name != 'admin') {
23
            return '';
24
        }
25
        $query = [
26
            'formName' => !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager',
27
            'redirectUrl' => !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : str_replace('\\', '/', $modelName)
0 ignored issues
show
Bug introduced by
The variable $modelName does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
28
        ];
29
        return "<a href='/admin/" . str_replace('\\', '/view/', get_class($item)) . "/{$item->pk()}?" . http_build_query($query) . "'><i class='glyphicon glyphicon-eye-open'></i></a>";
30
    }
31
32
}
33