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

TempFilesystem   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A readFile() 0 3 1
A store() 0 7 1
A clean() 0 4 2
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
}