Passed
Push — master ( 3f67b7...07fe76 )
by f
02:48
created

BasicDriver::wrapStringInStream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace wapmorgan\UnifiedArchive\Drivers;
3
4
use wapmorgan\UnifiedArchive\ArchiveEntry;
5
use wapmorgan\UnifiedArchive\ArchiveInformation;
6
use wapmorgan\UnifiedArchive\Exceptions\ArchiveCreationException;
7
use wapmorgan\UnifiedArchive\Exceptions\ArchiveExtractionException;
8
use wapmorgan\UnifiedArchive\Exceptions\ArchiveModificationException;
9
use wapmorgan\UnifiedArchive\Exceptions\UnsupportedArchiveException;
10
use wapmorgan\UnifiedArchive\Exceptions\UnsupportedOperationException;
11
use wapmorgan\UnifiedArchive\PclzipZipInterface;
12
13
abstract class BasicDriver
14
{
15
    const COMPRESSION_NONE = 0;
16
    const COMPRESSION_WEAK = 1;
17
    const COMPRESSION_AVERAGE = 2;
18
    const COMPRESSION_STRONG = 3;
19
    const COMPRESSION_MAXIMUM = 4;
20
21
    /**
22
     * @return mixed
23
     * @throws UnsupportedOperationException
24
     */
25
    public static function getSupportedFormats()
26
    {
27
        throw new UnsupportedOperationException();
28
    }
29
30
    /**
31
     * @param $format
32
     * @throws UnsupportedOperationException
33
     */
34
    public static function checkFormatSupport($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

34
    public static function checkFormatSupport(/** @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...
35
    {
36
        throw new UnsupportedOperationException();
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public static function getDescription()
43
    {
44
        return null;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public static function getInstallationInstruction()
51
    {
52
        return null;
53
    }
54
55
    /**
56
     * @param $format
57
     * @return bool
58
     */
59
    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

59
    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...
60
    {
61
        return false;
62
    }
63
64
    /**
65
     * @param $format
66
     * @return bool
67
     */
68
    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

68
    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...
69
    {
70
        return false;
71
    }
72
73
    /**
74
     * @param $format
75
     * @return bool
76
     */
77
    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

77
    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...
78
    {
79
        return false;
80
    }
81
82
    /**
83
     * @param $format
84
     * @return false
85
     */
86
    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

86
    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...
87
    {
88
        return false;
89
    }
90
91
    /**
92
     * @param $format
93
     * @return false
94
     */
95
    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

95
    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...
96
    {
97
        return false;
98
    }
99
100
    /**
101
     * @param array $files
102
     * @param string $archiveFileName
103
     * @param int $compressionLevel
104
     * @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...
105
     * @return int Number of archived files
106
     * @throws UnsupportedOperationException
107
     */
108
    public static function createArchive(array $files, $archiveFileName, $compressionLevel = self::COMPRESSION_AVERAGE, $password = null)
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

108
    public static function createArchive(/** @scrutinizer ignore-unused */ array $files, $archiveFileName, $compressionLevel = self::COMPRESSION_AVERAGE, $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...
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

108
    public static function createArchive(array $files, $archiveFileName, $compressionLevel = self::COMPRESSION_AVERAGE, /** @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...
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

108
    public static function createArchive(array $files, /** @scrutinizer ignore-unused */ $archiveFileName, $compressionLevel = self::COMPRESSION_AVERAGE, $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...
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

108
    public static function createArchive(array $files, $archiveFileName, /** @scrutinizer ignore-unused */ $compressionLevel = self::COMPRESSION_AVERAGE, $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...
109
    {
110
        throw new UnsupportedOperationException();
111
    }
112
113
    /**
114
     * BasicDriver constructor.
115
     * @param string $archiveFileName
116
     * @param string $format
117
     * @param string|null $password Archive password for opening
118
     */
119
    abstract public function __construct($archiveFileName, $format, $password = null);
120
121
    /**
122
     * Returns summary about an archive.
123
     * Called after
124
     * - constructing
125
     * - addFiles()
126
     * - deleteFiles()
127
     * @return ArchiveInformation
128
     */
129
    abstract public function getArchiveInformation();
130
131
    /**
132
     * @return array
133
     */
134
    abstract public function getFileNames();
135
136
    /**
137
     * @param string $fileName
138
     * @return bool
139
     */
140
    abstract public function isFileExists($fileName);
141
142
    /**
143
     * @param string $fileName
144
     * @return ArchiveEntry|false
145
     */
146
    abstract public function getFileData($fileName);
147
148
    /**
149
     * @param string $fileName
150
     * @return string|false
151
     */
152
    abstract public function getFileContent($fileName);
153
154
    /**
155
     * @param string $fileName
156
     * @return resource
157
     */
158
    abstract public function getFileStream($fileName);
159
160
    /**
161
     * @param $string
162
     * @return resource
163
     */
164 6
    public static function wrapStringInStream($string)
165
    {
166 6
        $resource = fopen('php://temp', 'r+');
167 6
        fwrite($resource, $string);
168 6
        rewind($resource);
169 6
        return $resource;
170
    }
171
172
    /**
173
     * @param string $outputFolder
174
     * @param array  $files
175
     * @return int Number of extracted files
176
     * @throws ArchiveExtractionException
177
     */
178
    abstract public function extractFiles($outputFolder, array $files);
179
180
    /**
181
     * @param string $outputFolder
182
     * @return int Number of extracted files
183
     * @throws ArchiveExtractionException
184
     */
185
    abstract public function extractArchive($outputFolder);
186
187
    /**
188
     * @param array $files
189
     * @return false|int Number of deleted files
190
     * @throws UnsupportedOperationException
191
     * @throws ArchiveModificationException
192
     */
193
    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

193
    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...
194
    {
195
        throw new UnsupportedOperationException();
196
    }
197
198
    /**
199
     * @param array $files
200
     * @return int Number of added files
201
     * @throws UnsupportedOperationException
202
     * @throws ArchiveModificationException
203
     */
204
    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

204
    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...
205
    {
206
        throw new UnsupportedOperationException();
207
    }
208
209
    /**
210
     * @param string $inArchiveName
211
     * @param string $content
212
     * @return bool
213
     * @throws UnsupportedOperationException
214
     * @throws ArchiveModificationException
215
     */
216
    abstract public function addFileFromString($inArchiveName, $content);
217
218
    /**
219
     * @return string|null
220
     */
221
    public function getComment()
222
    {
223
        return null;
224
    }
225
226
    /**
227
     * @param string|null $comment
228
     * @return null
229
     */
230
    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

230
    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...
231
    {
232
        return null;
233
    }
234
}