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

MergeStrategy::chunksManager()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jobtech\LaravelChunky\Strategies;
4
5
use Illuminate\Support\Traits\ForwardsCalls;
6
use Jobtech\LaravelChunky\Contracts\ChunksManager;
7
use Jobtech\LaravelChunky\Contracts\MergeManager;
8
use Jobtech\LaravelChunky\Exceptions\StrategyException;
9
use Jobtech\LaravelChunky\Strategies\Contracts\MergeStrategy as MergeStrategyContract;
10
11
abstract class MergeStrategy implements MergeStrategyContract
12
{
13
    use ForwardsCalls;
14
15
    /**
16
     * @var string
17
     */
18
    protected string $folder;
19
20
    /**
21
     * @var string
22
     */
23
    protected string $destination;
24
25
    /**
26
     * @var \Jobtech\LaravelChunky\Contracts\ChunksManager|null
27
     */
28
    protected ?ChunksManager $chunksManager;
29
30
    /**
31
     * @var \Jobtech\LaravelChunky\Contracts\MergeManager|null
32
     */
33
    protected ?MergeManager $mergeManager;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function chunksManager($manager = null): ChunksManager
39
    {
40
        if ($manager instanceof ChunksManager) {
41
            $this->chunksManager = $manager;
42
        } elseif ($this->chunksManager === null) {
43
            throw new StrategyException('Chunks manager cannot be empty');
44
        }
45
46
        return $this->chunksManager;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function mergeManager($manager = null): MergeManager
53
    {
54
        if ($manager instanceof MergeManager) {
55
            $this->mergeManager = $manager;
56
        } elseif ($this->mergeManager === null) {
57
            throw new StrategyException('Merge manager cannot be empty');
58
        }
59
60
        return $this->mergeManager;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function destination($destination = null): string
67
    {
68
        if (is_string($destination) && ! empty($destination)) {
69
            $this->destination = $this->mergeManager->destinationPath($destination);
0 ignored issues
show
Bug introduced by
The method destinationPath() 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

69
            /** @scrutinizer ignore-call */ 
70
            $this->destination = $this->mergeManager->destinationPath($destination);

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...
70
        }
71
72
        return $this->destination;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function chunksFolder($folder = null): string
79
    {
80
        if (is_string($folder) && $this->chunksManager->validFolder($folder)) {
0 ignored issues
show
Bug introduced by
The method validFolder() 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

80
        if (is_string($folder) && $this->chunksManager->/** @scrutinizer ignore-call */ validFolder($folder)) {

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...
81
            $this->folder = $folder;
82
        } elseif (empty($this->folder) || ! $this->chunksManager->validFolder($this->folder)) {
83
            throw new StrategyException('Chunks folder cannot be empty');
84
        }
85
86
        return $this->folder;
87
    }
88
}
89