Test Failed
Pull Request — master (#32)
by Filippo
07:40 queued 04:16
created

TempFilesystem::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Jobtech\LaravelChunky\Support;
4
5
use Illuminate\Support\Facades\Log;
6
7
class TempFilesystem extends Filesystem
8
{
9
    private array $temp_files = [];
10
11
    /**
12
     * @param string $path
13
     * @return resource|null
14
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
15
     */
16
    public function readFile(string $path)
17
    {
18
        return $this->filesystem()->disk($this->disk())->readStream($this->path($path));
19
    }
20
21
    /**
22
     * @param string $path
23
     * @param string|resource $resource
24
     * @param array  $options
25
     *
26
     * @throws \Illuminate\Contracts\Filesystem\FileExistsException
27
     * @return string
28
     */
29
    public function store(string $path, $resource = '', $options = []): string
30
    {
31
        $path = $this->path($path);
32
        $this->filesystem()->disk($this->disk())->writeStream($path, $resource, $options);
33
        $this->temp_files[] = $path;
34
35
        return $path;
36
    }
37
38
    public function clean()
39
    {
40
        foreach($this->temp_files as $file) {
41
            $this->filesystem()->disk($this->disk())->delete($file);
42
        }
43
    }
44
}