MediaLibraryRequestItem::fromArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 9.9666
1
<?php
2
3
namespace Spatie\MediaLibraryPro\Dto;
4
5
use Illuminate\Support\Str;
6
7
class MediaLibraryRequestItem
8
{
9
    public static function fromArray(array $properties): self
10
    {
11
        $properties = collect($properties)
12
            ->keyBy(fn ($value, $key) => Str::snake($key));
13
14
        return new static(
15
            $properties['uuid'],
16
            $properties['name'] ?? '',
17
            $properties['order'] ?? 0,
18
            $properties['custom_properties'] ?? [],
19
            $properties['custom_headers'] ?? [],
20
            $properties['file_name'] ?? null,
21
        );
22
    }
23
24
    protected function __construct(
25
        public string $uuid,
26
        public string $name,
27
        public int $order,
28
        public array $customProperties,
29
        public array $customHeaders,
30
        public ?string $fileName = null,
31
    ) {
32
    }
33
}
34