Test Failed
Push — master ( 87b409...65f6df )
by Filippo
21:44 queued 16:15
created

FlysystemStrategy::instance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jobtech\LaravelChunky\Strategies;
4
5
use Jobtech\LaravelChunky\Exceptions\StrategyException;
6
7
class FlysystemStrategy extends MergeStrategy
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12
    protected function mergeChunks(string $destination, array $chunks): bool
13
    {
14
        if (! $this->chunksManager->chunksFilesystem()->concatenate($destination, $chunks)) {
0 ignored issues
show
Bug introduced by
The method chunksFilesystem() does not exist on null. ( Ignorable by Annotation )

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

14
        if (! $this->chunksManager->/** @scrutinizer ignore-call */ chunksFilesystem()->concatenate($destination, $chunks)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
15
            throw new StrategyException('Unable to concatenate chunks');
16
        }
17
18
        return true;
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function merge(): string
25
    {
26
        // Retrieve chunks
27
        $chunks = $this->chunksManager->temporaryFiles(
28
            $this->chunksFolder()
29
        )->values();
30
        $chunk = $this->chunksManager->chunks(
31
            $this->chunksFolder()
32
        )->first();
33
34
        // Merge chunks
35
        $this->mergeChunks($chunk->getPath(), $chunks->toArray());
36
37
        // Move chunks to destination
38
        $origin = $this->chunksManager->chunk($chunk);
39
        $path = $this->mergeManager->store(
40
            $this->destination,
41
            $origin,
42
            $this->mergeManager->getMergeOptions()
0 ignored issues
show
Bug introduced by
The method getMergeOptions() does not exist on null. ( Ignorable by Annotation )

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

42
            $this->mergeManager->/** @scrutinizer ignore-call */ 
43
                                 getMergeOptions()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        );
44
45
        if (! $path) {
46
            throw new StrategyException('An error occurred while moving merge to destination');
47
        }
48
49
        // Cleanup
50
        $this->chunksManager->deleteChunkFolder($this->folder);
51
52
        return $path;
53
    }
54
55
    public static function instance()
56
    {
57
        return new FlysystemStrategy;
58
    }
59
}
60