Passed
Pull Request — master (#222)
by
unknown
02:51
created

Files   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 22
ccs 8
cts 9
cp 0.8889
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form;
6
7
use ArrayAccess;
8
use Countable;
9
use InvalidArgumentException;
10
use IteratorAggregate;
11
use Psr\Http\Message\UploadedFileInterface;
12
use Yiisoft\Arrays\ArrayAccessTrait;
13
14
final class Files implements Countable, IteratorAggregate, ArrayAccess
15
{
16
    use ArrayAccessTrait;
17
18
    /**
19
     * @var UploadedFileInterface[]
20
     */
21
    public array $data;
22
23 3
    public function __construct(mixed $data)
24
    {
25 3
        if ($data instanceof UploadedFileInterface) {
26 1
            $this->data = [$data];
27 3
        } elseif (!is_array($data)) {
28 2
            throw new InvalidArgumentException('Data should contain array of uploaded files');
29
        } else {
30 3
            foreach ($data as $file) {
31 2
                if (!$file instanceof UploadedFileInterface) {
32
                    throw new InvalidArgumentException('Data should contain UploadedFileInterface objects only');
33
                }
34
            }
35 3
            $this->data = $data;
36
        }
37
    }
38
}
39