Completed
Push — master ( 6af878...d015d4 )
by Mikołaj
02:37
created

Controller   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 54
rs 10
wmc 7
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
C show() 0 48 7
1
<?php
2
3
namespace Rudolf\Modules\Tools\Admin\One\DatabaseImport;
4
5
use Rudolf\Component\Alerts\Alert;
6
use Rudolf\Component\Alerts\AlertsCollection;
7
use Rudolf\Framework\Controller\AdminController;
8
9
class Controller extends AdminController
10
{
11
    /**
12
     * @throws \Exception
13
     */
14
    public function show()
0 ignored issues
show
Coding Style introduced by
show 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
show 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...
15
    {
16
        if (isset($_POST['upload'])) {
17
            $error = 0;
18
            $file = $_FILES['sqlfile'];
19
20
            /** @var array $_FILES */
21
            if ($file['error'] !== UPLOAD_ERR_OK
22
                || !is_uploaded_file($file['tmp_name'])) {
23
                $error = 1;
24
                AlertsCollection::add(new Alert(
25
                    'error',
26
                    'Uszkodzony plik.',
27
                    ALERT::MODE_IMMEDIATELY
28
                ));
29
            } elseif ('application/sql' !== $file['type']) {
30
                $error = 1;
31
                AlertsCollection::add(new Alert(
32
                    'error',
33
                    'Nieprawidłowy plik. Tylko .sql.',
34
                    ALERT::MODE_IMMEDIATELY
35
                ));
36
            }
37
38
            if (0 === $error) {
39
                $model = new Model();
40
                $model->clear();
41
                $queries = $model->import(file_get_contents($file['tmp_name']));
42
                if ($queries) {
43
                    AlertsCollection::add(new Alert(
44
                        'success',
45
                        'Poprawnie zaimportowano ' . $file['name'].'! Wykonano '.$queries.' zapytań.'
46
                    ));
47
                    $this->redirectTo(DIR.'/admin/tools/db-import');
48
                } else {
49
                    AlertsCollection::add(new Alert(
50
                        'error',
51
                        'Nastąpił błąd podczas importu!',
52
                        ALERT::MODE_IMMEDIATELY
53
                    ));
54
                }
55
            }
56
        }
57
58
        $view = new View();
59
        $view->setData($data = []);
60
        $view->render('admin');
61
    }
62
}
63