Completed
Push — master ( 0e57e6...32019c )
by Alexey
04:45
created

File::parseRequest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 11
nc 3
nop 1
dl 17
loc 17
rs 9.4285
c 1
b 0
f 1
1
<?php
2
3
/**
4
 * Active form input files
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
12
namespace Ui\ActiveForm\Input;
13
14
class File extends \Ui\ActiveForm\Input {
15
16 View Code Duplication
  public function parseRequest($request) {
1 ignored issue
show
Coding Style introduced by
parseRequest 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...
17
    if (!empty($_FILES[$this->activeForm->requestFormName]['tmp_name'][$this->modelName][$this->colName])) {
18
      $file_id = \App::$primary->files->upload([
19
          'tmp_name' => $_FILES[$this->activeForm->requestFormName]['tmp_name'][$this->modelName][$this->colName],
20
          'name' => $_FILES[$this->activeForm->requestFormName]['name'][$this->modelName][$this->colName],
21
          'type' => $_FILES[$this->activeForm->requestFormName]['type'][$this->modelName][$this->colName],
22
          'size' => $_FILES[$this->activeForm->requestFormName]['size'][$this->modelName][$this->colName],
23
          'error' => $_FILES[$this->activeForm->requestFormName]['error'][$this->modelName][$this->colName],
24
              ], [
25
          'upload_code' => 'activeForm:' . $this->activeForm->modelName . ':' . $this->activeForm->model->pk()
26
      ]);
27
28
      if ($file_id) {
29
        $this->activeForm->model->{$this->colName} = $file_id;
30
      }
31
    }
32
  }
33
34
}
35