TemporaryUploadFactory::useFakeImageDimensions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
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