Completed
Push — master ( 5bbc33...8440a4 )
by Alexey
07:26
created

DashboardController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 5 1
B siteConfigAction() 0 23 4
A phpInfoAction() 0 3 1
1
<?php
2
3
/**
4
 * Dashboard admin controller
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
class DashboardController extends adminController {
12
13
  public function indexAction() {
14
    $sections = $this->module->getSnippets('adminDashboardWidget');
15
    $this->view->setTitle('Панель управления');
16
    $this->view->page(['data' => compact('sections')]);
17
  }
18
19
  public function siteConfigAction() {
2 ignored issues
show
Coding Style introduced by
siteConfigAction uses the super-global variable $_POST 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...
Coding Style introduced by
siteConfigAction uses the super-global variable $_FILES 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...
20
    if (isset($_POST['site_name'])) {
21
      $config = \App::$primary->config;
22
      $config['site']['name'] = $_POST['site_name'];
23
      $config['site']['company_name'] = $_POST['company_name'];
24
      $config['site']['email'] = $_POST['site_email'];
25
      $config['site']['keywords'] = $_POST['site_keywords'];
26
      $config['site']['description'] = $_POST['site_description'];
27
      $config['site']['domain'] = $_POST['site_domain'];
28
      if (isset($_POST['metatags'])) {
29
        $config['site']['metatags'] = $_POST['metatags'];
30
      }
31
      if (!empty($_FILES['site_logo']['tmp_name'])) {
32
        $fileId = $this->Files->upload($_FILES['site_logo'], array('file_code' => 'site_logo'));
33
        $config['site']['site_logo'] = Files\File::get($fileId)->path;
34
      }
35
      Config::save('app', $config);
36
      Tools::redirect('/admin/dashboard/siteConfig', 'Изменения сохранены', 'success');
37
    }
38
39
    $this->view->setTitle('Общие настройки сайта');
40
    $this->view->page();
41
  }
42
43
  public function phpInfoAction() {
44
    $this->view->page();
45
  }
46
47
}
48