Completed
Push — master ( 7f96cd...27908d )
by Freek
09:27
created

FileCannotBeAdded::requestDoesNotHaveFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Spatie\MediaLibrary\Exceptions;
4
5
use Exception;
6
use Illuminate\Database\Eloquent\Model;
7
use Spatie\MediaLibrary\Helpers\File;
8
9
class FileCannotBeAdded extends Exception
10
{
11
    public static function unknownType()
12
    {
13
        return new static('Only strings, FileObjects and UploadedFileObjects can be imported');
14
    }
15
16
    public static function fileIsTooBig(string $path)
17
    {
18
        $fileSize = File::getHumanReadableSize(filesize($path));
19
20
        $maxFileSize = File::getHumanReadableSize(config('laravel-medialibrary.max_file_size'));
21
22
        return new static("File `{$path}` has a size of {$fileSize} which is greater than the maximum allowed {$maxFileSize}");
23
    }
24
25
    public static function fileDoesNotExist(string $path)
26
    {
27
        return new static("File `{$path}` does not exist");
28
    }
29
30
    public static function unreachableUrl(string $url)
31
    {
32
        return new static("Url `{$url}` cannot be reached");
33
    }
34
35
    public static function diskDoesNotExist(string $diskName)
36
    {
37
        return new static("There is no filesystem disk named `{$diskName}` does not exist");
38
    }
39
40
    public static function modelDoesNotExist(Model $model)
41
    {
42
        $modelClass = get_class($model);
43
44
        return new static("Before adding media to it, you should first save the $modelClass-model");
45
    }
46
47
    public static function requestDoesNotHaveFile($key)
48
    {
49
        return new static("The current request does not have a file in a key named `{$key}`");
50
    }
51
}
52