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

ChunkySettings::defaultMergeStrategy()   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;
4
5
use Illuminate\Contracts\Config\Repository;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Str;
8
9
class ChunkySettings
10
{
11
    /** @var int */
12
    const INDEX_ZERO = 0;
13
14
    /** @var int */
15
    const INDEX_ONE = 1;
16
17
    /**
18
     * @var array
19
     */
20
    private $config;
21
22
    public function __construct(Repository $config)
23
    {
24
        $this->config = $config->get('chunky');
25
    }
26
27
    /**
28
     * Retrieve the chunky configurations.
29
     *
30
     * @return array
31
     */
32
    public function config(): array
33
    {
34
        return $this->config;
35
    }
36
37
    /**
38
     * Retrieve the default chunks disk.
39
     *
40
     * @return string|null
41
     */
42
    public function chunksDisk(): ?string
43
    {
44
        return Arr::get($this->config, 'disks.chunks.disk');
45
    }
46
47
    /**
48
     * Retrieve the chunks destination folder.
49
     *
50
     * @return string
51
     */
52
    public function chunksFolder(): string
53
    {
54
        $folder = Arr::get($this->config, 'disks.chunks.folder');
55
56
        if ($folder === null) {
57
            return '';
58
        } elseif (! Str::endsWith($folder, '/')) {
59
            $folder .= DIRECTORY_SEPARATOR;
60
        }
61
62
        return $folder;
63
    }
64
65
    /**
66
     * Retrieve the default merge file disk.
67
     *
68
     * @return string|null
69
     */
70
    public function mergeDisk(): ?string
71
    {
72
        return Arr::get($this->config, 'disks.merge.disk');
73
    }
74
75
    /**
76
     * Retrieve the merge file destination folder.
77
     *
78
     * @return string
79
     */
80
    public function mergeFolder(): string
81
    {
82
        $folder = Arr::get($this->config, 'disks.merge.folder');
83
84
        if ($folder === null) {
85
            return '';
86
        } elseif (! Str::endsWith($folder, '/')) {
87
            $folder .= DIRECTORY_SEPARATOR;
88
        }
89
90
        return $folder;
91
    }
92
93
    /**
94
     * Retrieve the default index value for chunks.
95
     *
96
     * @return int
97
     */
98
    public function defaultIndex(): int
99
    {
100
        return Arr::get($this->config, 'index', self::INDEX_ZERO)
101
            ?: self::INDEX_ZERO;
102
    }
103
104
    /**
105
     * Retrieve the additional options for chunk store.
106
     *
107
     * @return array
108
     */
109
    public function additionalChunksOptions(): array
110
    {
111
        return Arr::get($this->config, 'options.chunks', []);
112
    }
113
114
    /**
115
     * Retrieve the additional options for merge store.
116
     *
117
     * @return array
118
     */
119
    public function additionalMergeOptions(): array
120
    {
121
        return Arr::get($this->config, 'options.merge', []);
122
    }
123
124
    /**
125
     * Retrieve the auto merge option.
126
     *
127
     * @return bool
128
     */
129
    public function autoMerge(): bool
130
    {
131
        return Arr::get($this->config, 'auto_merge', false);
132
    }
133
134
    /**
135
     * Retrieve the default merge strategy.
136
     *
137
     * @return string
138
     */
139
    public function defaultMergeStrategy(): string
140
    {
141
        return Arr::get($this->config, 'strategies.default');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor..., 'strategies.default') could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
142
    }
143
144
    /**
145
     * Retrieve the queue connection for the merge job.
146
     *
147
     * @return string
148
     */
149
    public function connection()
150
    {
151
        return Arr::get($this->config, 'strategies.connection');
152
    }
153
154
    /**
155
     * Retrieve the queue for the merge job.
156
     *
157
     * @return array|\ArrayAccess|mixed
158
     */
159
    public function queue()
160
    {
161
        return Arr::get($this->config, 'strategies.queue');
162
    }
163
}
164