TemporaryUploadFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A new() 0 3 1
A createMultiple() 0 4 1
A create() 0 9 1
A useFakeImageDimensions() 0 7 1
1
<?php
2
3
namespace Spatie\MediaLibraryPro\Factories;
4
5
use Illuminate\Http\UploadedFile;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Str;
8
use Spatie\MediaLibraryPro\Models\TemporaryUpload;
9
10
class TemporaryUploadFactory
11
{
12
    private int $fakeImageWidth = 10;
13
    private int $fakeImageHeight = 10;
14
15
    public static function new(): self
16
    {
17
        return new static;
18
    }
19
20
    public function useFakeImageDimensions(int $fakeImageWidth, int $fakeImageHeight): self
21
    {
22
        $this->fakeImageWidth = $fakeImageWidth;
23
24
        $this->fakeImageHeight = $fakeImageHeight;
25
26
        return $this;
27
    }
28
29
    public function create(array $attributes = []): TemporaryUpload
30
    {
31
        $fakeUpload = UploadedFile::fake()->image('test.jpg', $this->fakeImageWidth, $this->fakeImageHeight);
32
33
        return TemporaryUpload::createForFile(
34
            $fakeUpload,
35
            session()->getId(),
36
            $attributes['uuid'] ?? Str::uuid(),
37
            $attributes['name'] ?? 'name',
38
        );
39
    }
40
41
    public function createMultiple(int $count, array $attributes = []): array
42
    {
43
        return Collection::times($count)
44
            ->map(fn () => $this->create($attributes))->toArray();
45
    }
46
}
47