Test Failed
Pull Request — master (#36)
by Filippo
04:47
created

TempFilesystem   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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