Test Failed
Pull Request — master (#24)
by Filippo
12:43
created

MergeFilesystem   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 15
dl 0
loc 67
rs 10
c 2
b 1
f 0
wmc 12

6 Methods

Rating   Name   Duplication   Size   Complexity  
A destinationPath() 0 7 2
A folder() 0 7 3
A exists() 0 3 1
A disk() 0 7 3
A createTemporaryChunk() 0 3 1
A store() 0 7 2
1
<?php
2
3
namespace Jobtech\LaravelChunky\Support;
4
5
use Illuminate\Support\Str;
6
7
class MergeFilesystem extends FileSystem
8
{
9
    /** {@inheritdoc} */
10
    public function disk($disk = null): ?string
11
    {
12
        if (! empty($disk) && is_string($disk)) {
13
            $this->disk = $disk;
14
        }
15
16
        return  $this->disk;
17
    }
18
19
    /** {@inheritdoc} */
20
    public function folder($folder = null): ?string
21
    {
22
        if (! empty($folder) && is_string($folder)) {
23
            $this->folder = $folder;
24
        }
25
26
        return $this->folder;
27
    }
28
29
    /**
30
     * @param string $path
31
     * @return string
32
     */
33
    public function destinationPath(string $path): string
34
    {
35
        if (Str::startsWith($path, $this->folder())) {
36
            return $path;
37
        }
38
39
        return $this->folder.$path;
40
    }
41
42
    /**
43
     * Write the origin stream into destination.
44
     *
45
     * @param string $destination
46
     * @param resource|null $origin
47
     * @param array $options
48
     *
49
     * @throws \Illuminate\Contracts\Filesystem\FileExistsException
50
     *
51
     * @return string
52
     */
53
    public function store(string $destination, $origin, $options = []): string
54
    {
55
        if ($this->filesystem()->disk($this->disk)->put($destination, $origin, $options)) {
56
            return $destination;
57
        }
58
59
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the type-hinted return string.
Loading history...
60
    }
61
62
    public function createTemporaryChunk($origin)
0 ignored issues
show
Unused Code introduced by
The parameter $origin is not used and could be removed. ( Ignorable by Annotation )

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

62
    public function createTemporaryChunk(/** @scrutinizer ignore-unused */ $origin)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
        $this->filesystem()->disk();
65
    }
66
67
    /**
68
     * @param string $path
69
     * @return bool
70
     */
71
    public function exists(string $path): bool
72
    {
73
        return $this->filesystem()->disk($this->disk)->exists($path);
74
    }
75
}
76