Passed
Push — master ( b1d4f6...7824cd )
by f
10:25
created

BasicDriver   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 237
Duplicated Lines 0 %

Test Coverage

Coverage 15.15%

Importance

Changes 0
Metric Value
eloc 33
c 0
b 0
f 0
dl 0
loc 237
ccs 5
cts 33
cp 0.1515
rs 10
wmc 13

13 Methods

Rating   Name   Duplication   Size   Complexity  
A canCreateArchive() 0 3 1
A canEncrypt() 0 3 1
A getComment() 0 3 1
A canDeleteFiles() 0 3 1
A deleteFiles() 0 3 1
A addFiles() 0 3 1
A setComment() 0 3 1
A canAddFiles() 0 3 1
A getInstallationInstruction() 0 3 1
A canStream() 0 3 1
A createArchive() 0 9 1
A getDescription() 0 3 1
A wrapStringInStream() 0 6 1
1
<?php
2
namespace wapmorgan\UnifiedArchive\Drivers;
3
4
use wapmorgan\UnifiedArchive\ArchiveEntry;
5
use wapmorgan\UnifiedArchive\ArchiveInformation;
6
use wapmorgan\UnifiedArchive\Exceptions\ArchiveExtractionException;
7
use wapmorgan\UnifiedArchive\Exceptions\ArchiveModificationException;
8
use wapmorgan\UnifiedArchive\Exceptions\NonExistentArchiveFileException;
9
use wapmorgan\UnifiedArchive\Exceptions\UnsupportedOperationException;
10
11
abstract class BasicDriver
12
{
13
    const COMPRESSION_NONE = 0;
14
    const COMPRESSION_WEAK = 1;
15
    const COMPRESSION_AVERAGE = 2;
16
    const COMPRESSION_STRONG = 3;
17
    const COMPRESSION_MAXIMUM = 4;
18
19
    const OPEN = 1;
20
    const OPEN_ENCRYPTED = 2;
21
    const OPEN_VOLUMED = 4;
22
23
    const GET_COMMENT = 64;
24
    const EXTRACT_CONTENT = 128;
25
    const STREAM_CONTENT = 256;
26
27
    const APPEND = 4096;
28
    const DELETE = 8192;
29
    const SET_COMMENT = 16384;
30
31
    const CREATE = 1048576;
32
    const CREATE_ENCRYPTED = 2097152;
33
34
    /**
35
     * @return array
36
     */
37
    abstract public static function getSupportedFormats();
38
39
    /**
40
     * @param $format
41
     * @return array
42
     */
43
    abstract public static function checkFormatSupport($format);
44
45
    /**
46
     * @return string
47
     */
48
    public static function getDescription()
49
    {
50
        return null;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public static function getInstallationInstruction()
57
    {
58
        return null;
59
    }
60
61
    /**
62
     * @param $format
63
     * @return bool
64
     */
65
    public static function canCreateArchive($format)
0 ignored issues
show
Unused Code introduced by
The parameter $format 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

65
    public static function canCreateArchive(/** @scrutinizer ignore-unused */ $format)

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...
66
    {
67
        return false;
68
    }
69
70
    /**
71
     * @param $format
72
     * @return bool
73
     */
74
    public static function canAddFiles($format)
0 ignored issues
show
Unused Code introduced by
The parameter $format 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

74
    public static function canAddFiles(/** @scrutinizer ignore-unused */ $format)

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...
75
    {
76
        return false;
77
    }
78
79
    /**
80
     * @param $format
81
     * @return bool
82
     */
83
    public static function canDeleteFiles($format)
0 ignored issues
show
Unused Code introduced by
The parameter $format 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

83
    public static function canDeleteFiles(/** @scrutinizer ignore-unused */ $format)

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...
84
    {
85
        return false;
86
    }
87
88
    /**
89
     * @param $format
90
     * @return false
91
     */
92
    public static function canEncrypt($format)
0 ignored issues
show
Unused Code introduced by
The parameter $format 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

92
    public static function canEncrypt(/** @scrutinizer ignore-unused */ $format)

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...
93
    {
94
        return false;
95
    }
96
97
    /**
98
     * @param $format
99
     * @return false
100
     */
101
    public static function canStream($format)
0 ignored issues
show
Unused Code introduced by
The parameter $format 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

101
    public static function canStream(/** @scrutinizer ignore-unused */ $format)

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...
102
    {
103
        return false;
104
    }
105
106
    /**
107
     * @param array $files
108
     * @param string $archiveFileName
109
     * @param string $archiveFormat
110
     * @param int $compressionLevel
111
     * @param null $password
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $password is correct as it would always require null to be passed?
Loading history...
112
     * @param $fileProgressCallable
113
     * @return int Number of archived files
114
     * @throws UnsupportedOperationException
115
     */
116
    public static function createArchive(
117
        array $files,
0 ignored issues
show
Unused Code introduced by
The parameter $files 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

117
        /** @scrutinizer ignore-unused */ array $files,

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...
118
        $archiveFileName,
0 ignored issues
show
Unused Code introduced by
The parameter $archiveFileName 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

118
        /** @scrutinizer ignore-unused */ $archiveFileName,

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...
119
        $archiveFormat,
0 ignored issues
show
Unused Code introduced by
The parameter $archiveFormat 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

119
        /** @scrutinizer ignore-unused */ $archiveFormat,

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...
120
        $compressionLevel = self::COMPRESSION_AVERAGE,
0 ignored issues
show
Unused Code introduced by
The parameter $compressionLevel 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

120
        /** @scrutinizer ignore-unused */ $compressionLevel = self::COMPRESSION_AVERAGE,

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...
121
        $password = null,
0 ignored issues
show
Unused Code introduced by
The parameter $password 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

121
        /** @scrutinizer ignore-unused */ $password = null,

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...
122
        $fileProgressCallable = null
0 ignored issues
show
Unused Code introduced by
The parameter $fileProgressCallable 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

122
        /** @scrutinizer ignore-unused */ $fileProgressCallable = null

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...
123
    ) {
124
        throw new UnsupportedOperationException();
125
    }
126
127
    /**
128
     * BasicDriver constructor.
129
     * @param string $archiveFileName
130
     * @param string $format
131
     * @param string|null $password Archive password for opening
132
     */
133
    abstract public function __construct($archiveFileName, $format, $password = null);
134
135
    /**
136
     * Returns summary about an archive.
137
     * Called after
138
     * - constructing
139
     * - addFiles()
140
     * - deleteFiles()
141
     * @return ArchiveInformation
142
     */
143
    abstract public function getArchiveInformation();
144
145
    /**
146
     * @return array
147
     */
148
    abstract public function getFileNames();
149
150
    /**
151
     * @param string $fileName
152
     * @return bool
153
     */
154
    abstract public function isFileExists($fileName);
155
156
    /**
157
     * @param string $fileName
158
     * @return ArchiveEntry|false
159
     */
160
    abstract public function getFileData($fileName);
161
162
    /**
163
     * @param string $fileName
164 5
     * @return string|false
165
     * @throws NonExistentArchiveFileException
166 5
     */
167 5
    abstract public function getFileContent($fileName);
168 5
169 5
    /**
170
     * @param string $fileName
171
     * @return resource
172
     */
173
    abstract public function getFileStream($fileName);
174
175
    /**
176
     * @param $string
177
     * @return resource
178
     */
179
    public static function wrapStringInStream($string)
180
    {
181
        $resource = fopen('php://temp', 'r+');
182
        fwrite($resource, $string);
183
        rewind($resource);
184
        return $resource;
185
    }
186
187
    /**
188
     * @param string $outputFolder
189
     * @param array  $files
190
     * @return int Number of extracted files
191
     * @throws ArchiveExtractionException
192
     */
193
    abstract public function extractFiles($outputFolder, array $files);
194
195
    /**
196
     * @param string $outputFolder
197
     * @return int Number of extracted files
198
     * @throws ArchiveExtractionException
199
     */
200
    abstract public function extractArchive($outputFolder);
201
202
    /**
203
     * @param array $files
204
     * @return false|int Number of deleted files
205
     * @throws UnsupportedOperationException
206
     * @throws ArchiveModificationException
207
     */
208
    public function deleteFiles(array $files)
0 ignored issues
show
Unused Code introduced by
The parameter $files 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

208
    public function deleteFiles(/** @scrutinizer ignore-unused */ array $files)

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...
209
    {
210
        throw new UnsupportedOperationException();
211
    }
212
213
    /**
214
     * @param array $files
215
     * @return int Number of added files
216
     * @throws UnsupportedOperationException
217
     * @throws ArchiveModificationException
218
     */
219
    public function addFiles(array $files)
0 ignored issues
show
Unused Code introduced by
The parameter $files 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

219
    public function addFiles(/** @scrutinizer ignore-unused */ array $files)

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...
220
    {
221
        throw new UnsupportedOperationException();
222
    }
223
224
    /**
225
     * @param string $inArchiveName
226
     * @param string $content
227
     * @return bool
228
     * @throws UnsupportedOperationException
229
     * @throws ArchiveModificationException
230
     */
231
    abstract public function addFileFromString($inArchiveName, $content);
232
233
    /**
234
     * @return string|null
235
     */
236
    public function getComment()
237
    {
238
        return null;
239
    }
240
241
    /**
242
     * @param string|null $comment
243
     * @return null
244
     */
245
    public function setComment($comment)
0 ignored issues
show
Unused Code introduced by
The parameter $comment 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

245
    public function setComment(/** @scrutinizer ignore-unused */ $comment)

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...
246
    {
247
        return null;
248
    }
249
}