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

UploadedFileFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromFiles() 0 14 2
A factoryFilesTree() 0 17 3
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