Uploader::setup()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
rs 8.5906
nc 5
cc 5
eloc 15
nop 1
1
<?php /** MicroUploader */
2
3
namespace Micro\Web;
4
5
/**
6
 * Uploader class file.
7
 *
8
 * Interface for upload files
9
 *
10
 * @author Oleg Lunegov <[email protected]>
11
 * @link https://github.com/linpax/microphp-framework
12
 * @copyright Copyright (c) 2013 Oleg Lunegov
13
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
14
 * @package Micro
15
 * @subpackage Web
16
 * @version 1.0
17
 * @since 1.0
18
 */
19
class Uploader
20
{
21
    /** @var array $files upload files */
22
    public $files = [];
23
24
25
    /**
26
     * Constructor uploads
27
     *
28
     * @access public
29
     *
30
     * @param array $rawData Raw data for setup
31
     *
32
     * @result void
33
     */
34
    public function __construct(array $rawData = null)
35
    {
36
        $this->setup($rawData);
0 ignored issues
show
Bug introduced by
It seems like $rawData defined by parameter $rawData on line 34 can also be of type null; however, Micro\Web\Uploader::setup() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
37
    }
38
39
    /**
40
     * Setup uploader from config array
41
     *
42
     * @access public
43
     *
44
     * @param array $rawData Raw data
45
     *
46
     * @return void
47
     */
48
    public function setup(array $rawData = [])
49
    {
50
        if (0 === count($rawData)) {
51
            return;
52
        }
53
54
        if (!empty($rawData['name'])) {
55
            foreach (range(0, count($rawData['name']) - 1) AS $i) {
56
                if (empty($rawData['name'][$i])) {
57
                    continue;
58
                }
59
                $this->files[] = [
60
                    'name' => $rawData['name'][$i],
61
                    'type' => $rawData['type'][$i],
62
                    'error' => $rawData['error'][$i],
63
                    'tmp_name' => $rawData['tmp_name'][$i],
64
                    'size' => $rawData['size'][$i]
65
                ];
66
            }
67
        } else {
68
            $this->files[] = $rawData;
69
        }
70
    }
71
}
72