PendingMediaFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Spatie\MediaLibraryPro\Factories;
4
5
use Spatie\MediaLibraryPro\Dto\PendingMediaItem;
6
7
class PendingMediaFactory
8
{
9
    protected array $temporaryUploadAttributes = [];
10
11
    public function withTemporaryUploadAttributes(array $temporaryUploadAttributes = []): self
12
    {
13
        $this->temporaryUploadAttributes = $temporaryUploadAttributes;
14
15
        return $this;
16
    }
17
18
    public function create(array $attributes = []): PendingMediaItem
19
    {
20
        $temporaryUpload = (new TemporaryUploadFactory)->create($this->temporaryUploadAttributes);
21
22
        return new PendingMediaItem(
23
            $temporaryUpload->getFirstMedia()->uuid,
24
            $attributes['name'] ?? 'name',
25
            $attributes['order'] ?? 0,
26
            $attributes['custom_properties'] ?? [],
27
            $attributes['custom_headers'] ?? [],
28
        );
29
    }
30
}
31