x Sorry, these patches are not available anymore due to data migration. Please run a fresh inspection.
Passed
Push — main ( ec0923...4d334c )
by Seth
01:22
created

UploadOption::prepareFromPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace SaasReady\Services\FileManager;
4
5
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Http\UploadedFile;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\UploadedFile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use RuntimeException;
8
use SplFileInfo;
9
10
final class UploadOption
11
{
12
    /**
13
     * The file that will be uploaded to storage disk
14
     */
15
    public SplFileInfo $file;
16
17
    /**
18
     * Desired path to store the file
19
     *
20
     * @example user/$user->id/avatar/
21
     */
22
    public string $storePath = '';
23
24
    /**
25
     * New filename after uploaded
26
     *
27
     * By default, auto generate by Ready
28
     */
29
    public ?string $newFileName = null;
30
31
    /**
32
     * Source model of the File
33
     */
34
    public ?Model $source = null;
35
36
    public static function prepareFromUploadedFile(UploadedFile $uploadedFile): self
37
    {
38
        $option = new self();
39
        $option->file = $uploadedFile->getFileInfo();
40
41
        return $option;
42
    }
43
44
    public static function prepareFromPath(string $filePath): self
45
    {
46
        $option = new self();
47
        $option->file = new SplFileInfo($filePath);
48
49
        if (!$option->file->isReadable()) {
50
            throw new RuntimeException("The file $filePath is not readable. Cannot process further.");
51
        }
52
53
        return $option;
54
    }
55
}
56