Conditions | 3 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
22 | 9 | public static function createFromArray(array $data, Translator $translator = null) |
|
23 | { |
||
24 | 9 | $translator = $translator ?: Translator::locate(); |
|
25 | 9 | $arr = ['name' => null, 'type' => null, 'tmp_name' => null, 'error' => null, 'size' => null]; |
|
26 | |||
27 | 9 | $compare = array_diff_key($arr, $data); |
|
28 | |||
29 | 9 | if (!empty($compare)) { |
|
30 | 5 | $fields = array_keys($compare); |
|
31 | 5 | $msg = sprintf($translator->getMessage('validations.requiredField'), $fields[0]); |
|
32 | 5 | throw new InvalidArgumentException($msg, 400); |
|
33 | } |
||
34 | |||
35 | 4 | $entity = (new Upload()) |
|
36 | 4 | ->setName($data['name']) |
|
37 | 4 | ->setType($data['type']) |
|
38 | 4 | ->setTmpName($data['tmp_name']) |
|
39 | 4 | ->setError($data['error']) |
|
40 | 4 | ->setSize($data['size']); |
|
41 | |||
42 | 4 | return $entity; |
|
43 | } |
||
44 | } |
||
45 |