Passed
Push — master ( afad4e...ae0184 )
by f
40:32 queued 25:34
created

BasicDriver::createArchiveInString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 2
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 TYPE_EXTENSION = 1;
14
    const TYPE_UTILITIES = 2;
15
    const TYPE_PURE_PHP = 3;
16
17
    static $typeLabels = [
18
        BasicDriver::TYPE_EXTENSION => 'php extension',
19
        BasicDriver::TYPE_UTILITIES => 'utilities + php bridge',
20
        BasicDriver::TYPE_PURE_PHP => 'pure php',
21
    ];
22
23
    const COMPRESSION_NONE = 0;
24
    const COMPRESSION_WEAK = 1;
25
    const COMPRESSION_AVERAGE = 2;
26
    const COMPRESSION_STRONG = 3;
27
    const COMPRESSION_MAXIMUM = 4;
28
29
    const OPEN = 1;
30
    const OPEN_ENCRYPTED = 2;
31
    const OPEN_VOLUMED = 4;
32
33
    const GET_COMMENT = 64;
34
    const EXTRACT_CONTENT = 128;
35
    const STREAM_CONTENT = 256;
36
37
    const APPEND = 4096;
38
    const DELETE = 8192;
39
    const SET_COMMENT = 16384;
40
41
    const CREATE = 1048576;
42
    const CREATE_ENCRYPTED = 2097152;
43
    const CREATE_IN_STRING = 4194304;
44
45
    const TYPE = null;
46
47
    /**
48
     * @var string
49
     */
50
    protected $fileName;
51
52
    /**
53
     * @var string
54
     */
55
    protected $format;
56
57
    /**
58
     * @return string
59
     */
60
    abstract public static function getDescription();
61
62
    /**
63
     * @return bool
64
     */
65
    abstract public static function isInstalled();
66
67
    /**
68
     * @return string
69
     */
70
    abstract public static function getInstallationInstruction();
71
72
    /**
73
     * @return string[]
74
     */
75
    abstract public static function getSupportedFormats();
76
77
    /**
78
     * @param string $format
79
     * @return int[]
80
     */
81
    abstract public static function checkFormatSupport($format);
82
83
    /**
84
     * @param $ability
85
     * @return bool
86
     */
87
    public function checkAbility($ability)
88
    {
89
        return in_array($ability, static::checkFormatSupport($this->format), true);
90
    }
91
92
    /**
93
     * @param array $files
94
     * @param string $archiveFileName
95
     * @param string $archiveFormat
96
     * @param int $compressionLevel
97
     * @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...
98
     * @param $fileProgressCallable
99
     * @return int Number of archived files
100
     * @throws UnsupportedOperationException
101
     */
102
    public static function createArchive(
103
        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

103
        /** @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...
104
        $archiveFileName,
105
        $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

105
        /** @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...
106
        $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

106
        /** @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...
107
        $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

107
        /** @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...
108
        $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

108
        /** @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...
109
    ) {
110
        throw new UnsupportedOperationException();
111
    }
112
113
    /**
114
     * @param array $files
115
     * @param string $archiveFormat
116
     * @param int $compressionLevel
117
     * @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...
118
     * @param $fileProgressCallable
119
     * @return int Number of archived files
120
     * @throws UnsupportedOperationException
121
     */
122
    public static function createArchiveInString(
123
        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

123
        /** @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...
124
        $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

124
        /** @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...
125
        $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

125
        /** @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...
126
        $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

126
        /** @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...
127
        $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

127
        /** @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...
128
    ) {
129
        throw new UnsupportedOperationException();
130
    }
131
132
    /**
133
     * BasicDriver constructor.
134
     * @param string $format
135
     * @param string $archiveFileName
136
     * @param string|null $password Archive password for opening
137
     */
138
    public function __construct($archiveFileName, $format, $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

138
    public function __construct($archiveFileName, $format, /** @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...
139
    {
140
        $this->fileName = $archiveFileName;
141
        $this->format = $format;
142
    }
143
144
    /**
145
     * Returns summary about an archive.
146
     * Called after
147
     * - constructing
148
     * - addFiles()
149
     * - deleteFiles()
150
     * @return ArchiveInformation
151
     */
152
    abstract public function getArchiveInformation();
153
154
    /**
155
     * @return array
156
     */
157
    abstract public function getFileNames();
158
159
    /**
160
     * @param string $fileName
161
     * @return bool
162
     */
163
    abstract public function isFileExists($fileName);
164 5
165
    /**
166 5
     * @param string $fileName
167 5
     * @return ArchiveEntry|false
168 5
     */
169 5
    abstract public function getFileData($fileName);
170
171
    /**
172
     * @param string $fileName
173
     * @return string|false
174
     * @throws NonExistentArchiveFileException
175
     */
176
    abstract public function getFileContent($fileName);
177
178
    /**
179
     * @param string $fileName
180
     * @return resource
181
     */
182
    abstract public function getFileStream($fileName);
183
184
    /**
185
     * @param $string
186
     * @return resource
187
     */
188
    public static function wrapStringInStream($string)
189
    {
190
        $resource = fopen('php://temp', 'r+');
191
        fwrite($resource, $string);
192
        rewind($resource);
193
        return $resource;
194
    }
195
196
    /**
197
     * @param string $outputFolder
198
     * @param array  $files
199
     * @return int Number of extracted files
200
     * @throws ArchiveExtractionException
201
     */
202
    abstract public function extractFiles($outputFolder, array $files);
203
204
    /**
205
     * @param string $outputFolder
206
     * @return int Number of extracted files
207
     * @throws ArchiveExtractionException
208
     */
209
    abstract public function extractArchive($outputFolder);
210
211
    /**
212
     * @param array $files
213
     * @return false|int Number of deleted files
214
     * @throws UnsupportedOperationException
215
     * @throws ArchiveModificationException
216
     */
217
    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

217
    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...
218
    {
219
        throw new UnsupportedOperationException();
220
    }
221
222
    /**
223
     * @param array $files
224
     * @return int Number of added files
225
     * @throws UnsupportedOperationException
226
     * @throws ArchiveModificationException
227
     */
228
    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

228
    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...
229
    {
230
        throw new UnsupportedOperationException();
231
    }
232
233
    /**
234
     * @param string $inArchiveName
235
     * @param string $content
236
     * @return bool
237
     * @throws UnsupportedOperationException
238
     * @throws ArchiveModificationException
239
     */
240
    public function addFileFromString($inArchiveName, $content)
0 ignored issues
show
Unused Code introduced by
The parameter $inArchiveName 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

240
    public function addFileFromString(/** @scrutinizer ignore-unused */ $inArchiveName, $content)

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...
Unused Code introduced by
The parameter $content 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

240
    public function addFileFromString($inArchiveName, /** @scrutinizer ignore-unused */ $content)

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...
241
    {
242
        throw new UnsupportedOperationException();
243
    }
244
245
    /**
246
     * @return string|null
247
     * @throws UnsupportedOperationException
248
     */
249
    public function getComment()
250
    {
251
        throw new UnsupportedOperationException();
252
    }
253
254
    /**
255
     * @param string|null $comment
256
     * @return null
257
     * @throws UnsupportedOperationException
258
     */
259
    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

259
    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...
260
    {
261
        throw new UnsupportedOperationException();
262
    }
263
}
264