Passed
Push — master ( 86aed3...9c525b )
by Petr
06:19 queued 03:36
created

Json   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 23
c 1
b 0
f 1
dl 0
loc 34
ccs 23
cts 23
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A loadVars() 0 32 5
1
<?php
2
3
namespace kalanis\kw_input\Loaders;
4
5
6
use kalanis\kw_input\Entries;
7
8
9
/**
10
 * Class Json
11
 * @package kalanis\kw_input\Loaders
12
 * Load Json input array into normalized entries
13
 */
14
class Json extends ALoader
15
{
16 7
    public function loadVars(string $source, $array): array
17
    {
18 7
        $fileEntries = new Entries\FileEntry();
19 7
        $entries = new Entries\Entry();
20 7
        $result = [];
21 7
        foreach ($array as $postedKey => $posted) {
22 3
            if (is_array($posted) && isset($posted['FILE'])) {
23 1
                $file = tempnam(sys_get_temp_dir(), 'js_');
24 1
                if (false === $file) {
25
                    // @codeCoverageIgnoreStart
26
                    continue;
27
                }
28
                // @codeCoverageIgnoreEnd
29 1
                $size = file_put_contents($file, $posted['FILE']);
30
31 1
                $entry = clone $fileEntries;
32 1
                $entry->setEntry($source, strval($postedKey));
33 1
                $entry->setFile(
34 1
                    $postedKey . '.json',
35 1
                    $file,
36 1
                    'application/octet-stream',
37 1
                    0,
38 1
                    intval($size)
39 1
                );
40 1
                $result[] = $entry;
41
            } else {
42 3
                $entry = clone $entries;
43 3
                $entry->setEntry($source, strval($postedKey), $posted);
44 3
                $result[] = $entry;
45
            }
46
        }
47 7
        return $result;
48
    }
49
}
50