Completed
Pull Request — master (#61)
by Michal
02:15
created

FileInputParam   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addFormInput() 0 4 1
A getValue() 0 7 3
A processMultiFileUploads() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tomaj\NetteApi\Params;
6
7
use Nette\Application\UI\Form;
8
use Nette\Forms\Controls\BaseControl;
9
10
class FileInputParam extends InputParam
11
{
12
    protected $type = self::TYPE_FILE;
13
14 3
    protected function addFormInput(Form $form, string $key): BaseControl
15
    {
16 3
        return $form->addUpload($key, $this->getParamLabel());
17
    }
18
19 9
    public function getValue()
20
    {
21 9
        if (isset($_FILES[$this->key])) {
22 6
            return $this->isMulti() ? $this->processMultiFileUploads($_FILES[$this->key]) : $_FILES[$this->key];
23
        }
24 3
        return $this->default;
25
    }
26
27 3
    private function processMultiFileUploads($files)
28
    {
29 3
        $result = [];
30 3
        foreach ($files as $key => $values) {
31 3
            foreach ($values as $index => $value) {
32 3
                $result[$index][$key] = $value;
33
            }
34
        }
35 3
        return $result;
36
    }
37
}
38