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

MergeManager   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
dl 0
loc 100
rs 10
c 1
b 0
f 0
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 7 2
A getMergeFolder() 0 4 1
A mergeFilesystem() 0 3 1
A store() 0 3 1
A __construct() 0 6 1
A destinationPath() 0 3 1
A defaultMergeStrategy() 0 3 1
A setStrategy() 0 9 3
A getMergeOptions() 0 5 1
A getMergeDisk() 0 4 1
1
<?php
2
3
namespace Jobtech\LaravelChunky;
4
5
use Illuminate\Container\Container;
6
use Jobtech\LaravelChunky\Contracts\MergeManager as MergeManagerContract;
7
use Jobtech\LaravelChunky\Handlers\MergeHandler;
0 ignored issues
show
Bug introduced by
The type Jobtech\LaravelChunky\Handlers\MergeHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Jobtech\LaravelChunky\Strategies\Contracts\MergeStrategy;
9
use Jobtech\LaravelChunky\Support\MergeFilesystem;
10
11
class MergeManager implements MergeManagerContract
12
{
13
    /** @var ?MergeManager */
14
    private static $instance;
15
16
    /** @var \Jobtech\LaravelChunky\ChunkySettings */
17
    private ChunkySettings $settings;
18
19
    /** @var \Jobtech\LaravelChunky\Support\MergeFilesystem */
20
    private $mergeFilesystem;
21
22
    /**
23
     * @var \Jobtech\LaravelChunky\Handlers\MergeHandler|null
24
     */
25
    private ?MergeHandler $handler;
0 ignored issues
show
introduced by
The private property $handler is not used, and could be removed.
Loading history...
26
27
    public function __construct(ChunkySettings $settings)
28
    {
29
        $this->settings = $settings;
30
        $this->mergeFilesystem = MergeFilesystem::instance([
31
            'disk' => $settings->mergeDisk(),
32
            'folder' => $settings->mergeFolder(),
33
        ]);
34
    }
35
36
    private function defaultMergeStrategy()
37
    {
38
        return $this->settings->defaultMergeStrategy();
39
    }
40
41
    public function setStrategy($strategy = null): MergeManager
42
    {
43
        if ($strategy instanceof MergeStrategy) {
44
            $this->strategy = $strategy;
0 ignored issues
show
Bug Best Practice introduced by
The property strategy does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45
        } elseif ($strategy === null) {
46
            $this->defaultMergeStrategy();
47
        }
48
49
        return $this;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function mergeFilesystem(): MergeFilesystem
56
    {
57
        return $this->mergeFilesystem;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getMergeDisk(): ?string
64
    {
65
        return $this->settings
66
            ->mergeDisk();
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getMergeFolder(): string
73
    {
74
        return $this->settings
75
            ->mergeFolder();
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function getMergeOptions(): array
82
    {
83
        return array_merge([
84
            'disk' => $this->getMergeDisk(),
85
        ], $this->settings->additionalMergeOptions());
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function store(string $destination, $origin, $options = [])
92
    {
93
        return $this->mergeFilesystem->store($destination, $origin, $options);
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    public function destinationPath(string $path): string
100
    {
101
        return $this->mergeFilesystem()->destinationPath($path);
102
    }
103
104
    public static function getInstance(): MergeManager
105
    {
106
        if (static::$instance === null) {
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $instance to at least protected.
Loading history...
107
            static::$instance = Container::getInstance()->make(MergeManagerContract::class);
108
        }
109
110
        return static::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::instance could return the type Jobtech\LaravelChunky\Contracts\MergeManager which includes types incompatible with the type-hinted return Jobtech\LaravelChunky\MergeManager. Consider adding an additional type-check to rule them out.
Loading history...
111
    }
112
}
113