Completed
Pull Request — master (#24)
by
unknown
03:52
created

UploadedFileFactory::factoryFilesTree()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 5
dl 0
loc 17
ccs 12
cts 12
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Http\Factory;
3
4
use Wandu\Http\Psr\UploadedFile;
5
6
class UploadedFileFactory
7
{
8
    /**
9
     * @param array $files
10
     * @return \Psr\Http\Message\UploadedFileInterface[]|array
11
     */
12 12
    public function createFromFiles(array $files)
13
    {
14 12
        $uploadedFiles = [];
15 12
        foreach ($files as $name => $file) {
16 3
            $uploadedFiles[$name] = $this->factoryFilesTree(
17 3
                $file['tmp_name'],
18 3
                $file['size'],
19 3
                $file['error'],
20 3
                $file['name'],
21 3
                $file['type']
22
            );
23
        }
24 12
        return $uploadedFiles;
25
    }
26
27
    /**
28
     * @param array|string $fileDatas
29
     * @param array|int $sizeDatas
30
     * @param array|int $errorDatas
31
     * @param array|string $nameDatas
32
     * @param array|string $typeDatas
33
     * @return \Psr\Http\Message\UploadedFileInterface|\Psr\Http\Message\UploadedFileInterface[]|array
34
     */
35 3
    protected function factoryFilesTree($fileDatas, $sizeDatas, $errorDatas, $nameDatas, $typeDatas)
36
    {
37 3
        if (!is_array($errorDatas)) {
38 3
            return new UploadedFile($fileDatas, $sizeDatas, $errorDatas, $nameDatas, $typeDatas);
0 ignored issues
show
Bug introduced by
It seems like $fileDatas defined by parameter $fileDatas on line 35 can also be of type array; however, Wandu\Http\Psr\UploadedFile::__construct() does only seem to accept string|null, 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...
Bug introduced by
It seems like $sizeDatas defined by parameter $sizeDatas on line 35 can also be of type array; however, Wandu\Http\Psr\UploadedFile::__construct() does only seem to accept integer|null, 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...
Bug introduced by
It seems like $nameDatas defined by parameter $nameDatas on line 35 can also be of type array; however, Wandu\Http\Psr\UploadedFile::__construct() does only seem to accept string|null, 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...
Bug introduced by
It seems like $typeDatas defined by parameter $typeDatas on line 35 can also be of type array; however, Wandu\Http\Psr\UploadedFile::__construct() does only seem to accept string|null, 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...
39
        }
40 2
        $filesTree = [];
41 2
        foreach ($errorDatas as $name => $errorData) {
42 2
            $filesTree[$name] = $this->factoryFilesTree(
43 2
                $fileDatas[$name],
44 2
                $sizeDatas[$name],
45 2
                $errorData,
46 2
                $nameDatas[$name],
47 2
                $typeDatas[$name]
48
            );
49
        }
50 2
        return $filesTree;
51
    }
52
}
53