Passed
Push — main ( 44f9b3...d7b1c0 )
by Yaroslav
02:39
created

HasChunkFolder::getChunksFolder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace NovaChunkedVideo;
5
6
use Laravel\Nova\Http\Requests\NovaRequest;
7
8
trait HasChunkFolder
9
{
10
11
    /**
12
     * Temporary chunk folder
13
     *
14
     * @var string
15
     */
16
    protected string $chunksFolder;
17
18
    /**
19
     * The callback used to store file.
20
     *
21
     * @var callable
22
     */
23
    public ?\Closure $storeFileCallback = null;
24
25
    /**
26
     * Set chunk folder
27
     *
28
     * @param string $chunksFolder
29
     *
30
     * @return $this
31
     */
32 1
    public function chunksFolder(string $chunksFolder)
33
    {
34 1
        $this->chunksFolder = $chunksFolder;
35
36 1
        return $this;
37
    }
38
39
    /**
40
     * Get chunk folder
41
     *
42
     * @return string
43
     */
44 3
    public function getChunksFolder(): string
45
    {
46 3
        return $this->chunksFolder;
47
    }
48
49
    /**
50
     * Specify the callback that should be used to save file.
51
     *
52
     * @param callable $storeFileCallback
53
     *
54
     * @return $this
55
     */
56 13
    public function store(callable $storeFileCallback)
57
    {
58 13
        $this->storeFileCallback = $storeFileCallback;
59
60 13
        return $this;
61
    }
62
63
    /**
64
     * Store file
65
     *
66
     * @param NovaRequest $request
67
     * @param $filePath
68
     *
69
     * @return string|null
70
     */
71 2
    public function storeFile(NovaRequest $request, $filePath): ?string
72
    {
73 2
        return call_user_func($this->storeFileCallback, $filePath, $this->getStorageDisk(), $this->resource, $this->attribute, $request);
0 ignored issues
show
Bug introduced by
It seems like getStorageDisk() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        return call_user_func($this->storeFileCallback, $filePath, $this->/** @scrutinizer ignore-call */ getStorageDisk(), $this->resource, $this->attribute, $request);
Loading history...
Bug introduced by
It seems like $this->storeFileCallback can also be of type null; however, parameter $callback of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

73
        return call_user_func(/** @scrutinizer ignore-type */ $this->storeFileCallback, $filePath, $this->getStorageDisk(), $this->resource, $this->attribute, $request);
Loading history...
74
    }
75
}
76